Browse Source

refactor: extract the move-only ConvertToV8() into a new header

Charles Kerr 1 month ago
parent
commit
c0f65489c4
3 changed files with 25 additions and 7 deletions
  1. 1 0
      filenames.gni
  2. 23 0
      shell/common/gin_adapters.h
  3. 1 7
      shell/common/gin_converters/std_converter.h

+ 1 - 0
filenames.gni

@@ -586,6 +586,7 @@ filenames = {
     "shell/common/electron_command_line.h",
     "shell/common/electron_constants.h",
     "shell/common/electron_paths.h",
+    "shell/common/gin_adapters.h",
     "shell/common/gin_converters/accelerator_converter.cc",
     "shell/common/gin_converters/accelerator_converter.h",
     "shell/common/gin_converters/base_converter.h",

+ 23 - 0
shell/common/gin_adapters.h

@@ -0,0 +1,23 @@
+// Copyright (c) 2025 Microsoft, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ELECTRON_SHELL_COMMON_GIN_ADAPTERS_H_
+#define ELECTRON_SHELL_COMMON_GIN_ADAPTERS_H_
+
+#include <utility>
+
+#include "gin/converter.h"
+
+namespace gin {
+
+// Make it possible to convert move-only types.
+template <typename T>
+v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate, T&& input) {
+  return Converter<typename std::remove_reference<T>::type>::ToV8(
+      isolate, std::forward<T>(input));
+}
+
+}  // namespace gin
+
+#endif  // ELECTRON_SHELL_COMMON_GIN_ADAPTERS_H_

+ 1 - 7
shell/common/gin_converters/std_converter.h

@@ -13,6 +13,7 @@
 #include <utility>
 
 #include "gin/converter.h"
+#include "shell/common/gin_adapters.h"
 
 #include "base/strings/string_util.h"
 #if BUILDFLAG(IS_WIN)
@@ -21,13 +22,6 @@
 
 namespace gin {
 
-// Make it possible to convert move-only types.
-template <typename T>
-v8::Local<v8::Value> ConvertToV8(v8::Isolate* isolate, T&& input) {
-  return Converter<typename std::remove_reference<T>::type>::ToV8(
-      isolate, std::forward<T>(input));
-}
-
 #if !BUILDFLAG(IS_LINUX)
 template <>
 struct Converter<unsigned long> {  // NOLINT(runtime/int)