Skip to content

Commit 624ba4f

Browse files
zcbenzcodebytere
authored andcommitted
chore: remove native_mate (Part 5) (electron#20264)
* deprecate native_mate/native_mate/object_template_builder.h * add gin_helper/object_template_builder.h * add patch to avoid ambiguous error * remove usage of object_template_builder_deprecated.h in a few files * add note we should remove gin_helper/object_template_builder.h in future
1 parent 63f08fc commit 624ba4f

39 files changed

+474
-121
lines changed

filenames.gni

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ filenames = {
476476
"shell/common/gin_converters/gurl_converter.h",
477477
"shell/common/gin_converters/image_converter.cc",
478478
"shell/common/gin_converters/image_converter.h",
479+
"shell/common/gin_converters/native_mate_handle_converter.h",
479480
"shell/common/gin_converters/message_box_converter.cc",
480481
"shell/common/gin_converters/message_box_converter.h",
481482
"shell/common/gin_converters/native_window_converter.h",
@@ -494,6 +495,8 @@ filenames = {
494495
"shell/common/gin_helper/event_emitter_caller.h",
495496
"shell/common/gin_helper/function_template.cc",
496497
"shell/common/gin_helper/function_template.h",
498+
"shell/common/gin_helper/object_template_builder.cc",
499+
"shell/common/gin_helper/object_template_builder.h",
497500
"shell/common/heap_snapshot.cc",
498501
"shell/common/heap_snapshot.h",
499502
"shell/common/key_weak_map.h",

native_mate/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source_set("native_mate") {
2323
"native_mate/function_template.h",
2424
"native_mate/handle.h",
2525
"native_mate/object_template_builder.cc",
26-
"native_mate/object_template_builder.h",
26+
"native_mate/object_template_builder_deprecated.h",
2727
"native_mate/persistent_dictionary.cc",
2828
"native_mate/persistent_dictionary.h",
2929
"native_mate/scoped_persistent.h",

native_mate/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void Initialize(v8::Handle<v8::Object> exports) {
4545
types. You can define your own by specializing `Converter`.
4646
* `function_template.h` - Create JavaScript functions that dispatch to any C++
4747
function, member function pointer, or `base::Callback`.
48-
* `object_template_builder.h` - A handy utility for creation of `v8::ObjectTemplate`.
48+
* `object_template_builder_deprecated.h` - A handy utility for creation of `v8::ObjectTemplate`.
4949
* `wrappable.h` - Base class for C++ classes that want to be owned by the V8 GC.
5050
Wrappable objects are automatically deleted when GC discovers that nothing in
5151
the V8 heap refers to them. This is also an easy way to expose C++ objects to

native_mate/native_mate/dictionary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_
77

88
#include "native_mate/converter.h"
9-
#include "native_mate/object_template_builder.h"
9+
#include "native_mate/object_template_builder_deprecated.h"
1010

1111
namespace mate {
1212

native_mate/native_mate/object_template_builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE.chromium file.
44

5-
#include "native_mate/object_template_builder.h"
5+
#include "native_mate/object_template_builder_deprecated.h"
66

77
namespace mate {
88

native_mate/native_mate/object_template_builder.h renamed to native_mate/native_mate/object_template_builder_deprecated.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE.chromium file.
44

5-
#ifndef NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
6-
#define NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
5+
#ifndef NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_
6+
#define NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_
77

88
#include "base/bind.h"
99
#include "base/callback.h"
@@ -117,4 +117,4 @@ class ObjectTemplateBuilder {
117117

118118
} // namespace mate
119119

120-
#endif // NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_H_
120+
#endif // NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_

native_mate/native_mate/wrappable.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "base/logging.h"
88
#include "native_mate/dictionary.h"
9-
#include "native_mate/object_template_builder.h"
9+
#include "native_mate/object_template_builder_deprecated.h"
1010

1111
namespace mate {
1212

patches/chromium/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ web_contents.patch
1717
webview_cross_drag.patch
1818
disable_user_gesture_requirement_for_beforeunload_dialogs.patch
1919
gin_enable_disable_v8_platform.patch
20+
gin_with_namespace.patch
2021
blink-worker-enable-csp-in-file-scheme.patch
2122
disable-redraw-lock.patch
2223
v8_context_snapshot_generator.patch
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Cheng Zhao <[email protected]>
3+
Date: Thu, 20 Sep 2018 17:47:44 -0700
4+
Subject: gin_with_namespace.patch
5+
6+
When using gin with native_mate together we may have C++ confused with
7+
finding the correct ConvertFromV8. We add gin:: namespace explicitly in
8+
those calls to work around the ambiguous compilation error.
9+
10+
Note that this is only a work around to make it easier to remove
11+
native_mate, and we should remove this patch once native_mate is erased
12+
from Electron.
13+
14+
diff --git a/gin/arguments.h b/gin/arguments.h
15+
index eaded13e2991..03e1495566d1 100644
16+
--- a/gin/arguments.h
17+
+++ b/gin/arguments.h
18+
@@ -28,14 +28,14 @@ class GIN_EXPORT Arguments {
19+
v8::Local<v8::Object> holder = is_for_property_
20+
? info_for_property_->Holder()
21+
: info_for_function_->Holder();
22+
- return ConvertFromV8(isolate_, holder, out);
23+
+ return gin::ConvertFromV8(isolate_, holder, out);
24+
}
25+
26+
template<typename T>
27+
bool GetData(T* out) {
28+
v8::Local<v8::Value> data = is_for_property_ ? info_for_property_->Data()
29+
: info_for_function_->Data();
30+
- return ConvertFromV8(isolate_, data, out);
31+
+ return gin::ConvertFromV8(isolate_, data, out);
32+
}
33+
34+
template<typename T>
35+
@@ -45,7 +45,7 @@ class GIN_EXPORT Arguments {
36+
return false;
37+
}
38+
v8::Local<v8::Value> val = (*info_for_function_)[next_++];
39+
- return ConvertFromV8(isolate_, val, out);
40+
+ return gin::ConvertFromV8(isolate_, val, out);
41+
}
42+
43+
template<typename T>
44+
@@ -58,7 +58,7 @@ class GIN_EXPORT Arguments {
45+
out->resize(remaining);
46+
for (int i = 0; i < remaining; ++i) {
47+
v8::Local<v8::Value> val = (*info_for_function_)[next_++];
48+
- if (!ConvertFromV8(isolate_, val, &out->at(i)))
49+
+ if (!gin::ConvertFromV8(isolate_, val, &out->at(i)))
50+
return false;
51+
}
52+
return true;
53+
@@ -80,7 +80,7 @@ class GIN_EXPORT Arguments {
54+
template<typename T>
55+
void Return(T val) {
56+
v8::Local<v8::Value> v8_value;
57+
- if (!TryConvertToV8(isolate_, val, &v8_value))
58+
+ if (!gin::TryConvertToV8(isolate_, val, &v8_value))
59+
return;
60+
(is_for_property_ ? info_for_property_->GetReturnValue()
61+
: info_for_function_->GetReturnValue())
62+
diff --git a/gin/converter.h b/gin/converter.h
63+
index 27b4d0acd016..b19209a8534a 100644
64+
--- a/gin/converter.h
65+
+++ b/gin/converter.h
66+
@@ -250,7 +250,7 @@ std::enable_if_t<ToV8ReturnsMaybe<T>::value, bool> TryConvertToV8(
67+
v8::Isolate* isolate,
68+
const T& input,
69+
v8::Local<v8::Value>* output) {
70+
- return ConvertToV8(isolate, input).ToLocal(output);
71+
+ return gin::ConvertToV8(isolate, input).ToLocal(output);
72+
}
73+
74+
template <typename T>
75+
@@ -258,7 +258,7 @@ std::enable_if_t<!ToV8ReturnsMaybe<T>::value, bool> TryConvertToV8(
76+
v8::Isolate* isolate,
77+
const T& input,
78+
v8::Local<v8::Value>* output) {
79+
- *output = ConvertToV8(isolate, input);
80+
+ *output = gin::ConvertToV8(isolate, input);
81+
return true;
82+
}
83+

shell/browser/api/atom_api_app.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "content/public/common/content_switches.h"
3131
#include "gin/arguments.h"
3232
#include "media/audio/audio_manager.h"
33-
#include "native_mate/object_template_builder.h"
33+
#include "native_mate/object_template_builder_deprecated.h"
3434
#include "net/ssl/client_cert_identity.h"
3535
#include "net/ssl/ssl_cert_request_info.h"
3636
#include "services/service_manager/sandbox/switches.h"

0 commit comments

Comments
 (0)