refactor: avoid deprecated v8::Context::GetIsolate()
calls (pt 2) (#47896)
* refactor: add a v8::Isolate* arg to Constructible::GetConstructor() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add a v8::Isolate* arg to NodeBindings::Initialize() This is needed for the GetConstructor() call Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: avoid v8::Context::GetIsolate() call in GetIpcObject() by taking it as an arg Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: avoid v8::Context::GetIsolate() call in ipc_native::EmitIPCEvent() by taking it as an arg Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
edccb0a7ea
commit
e1e12318e2
18 changed files with 42 additions and 36 deletions
|
@ -327,7 +327,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
gin_helper::Dictionary dict{isolate, exports};
|
gin_helper::Dictionary dict{isolate, exports};
|
||||||
dict.Set("Menu", Menu::GetConstructor(context));
|
dict.Set("Menu", Menu::GetConstructor(isolate, context));
|
||||||
#if BUILDFLAG(IS_MAC)
|
#if BUILDFLAG(IS_MAC)
|
||||||
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
|
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);
|
||||||
dict.SetMethod("sendActionToFirstResponder",
|
dict.SetMethod("sendActionToFirstResponder",
|
||||||
|
|
|
@ -253,7 +253,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
gin_helper::Dictionary dict{isolate, exports};
|
gin_helper::Dictionary dict{isolate, exports};
|
||||||
dict.Set("Notification", Notification::GetConstructor(context));
|
dict.Set("Notification", Notification::GetConstructor(isolate, context));
|
||||||
dict.SetMethod("isSupported", &Notification::IsSupported);
|
dict.SetMethod("isSupported", &Notification::IsSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -362,7 +362,8 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
gin_helper::Dictionary dict{isolate, exports};
|
gin_helper::Dictionary dict{isolate, exports};
|
||||||
dict.Set("Protocol", electron::api::Protocol::GetConstructor(context));
|
dict.Set("Protocol",
|
||||||
|
electron::api::Protocol::GetConstructor(isolate, context));
|
||||||
dict.SetMethod("registerSchemesAsPrivileged", &RegisterSchemesAsPrivileged);
|
dict.SetMethod("registerSchemesAsPrivileged", &RegisterSchemesAsPrivileged);
|
||||||
dict.SetMethod("getStandardSchemes", &electron::api::GetStandardSchemes);
|
dict.SetMethod("getStandardSchemes", &electron::api::GetStandardSchemes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,7 +356,8 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
gin_helper::Dictionary dict{isolate, exports};
|
gin_helper::Dictionary dict{isolate, exports};
|
||||||
dict.Set("ServiceWorkerMain", ServiceWorkerMain::GetConstructor(context));
|
dict.Set("ServiceWorkerMain",
|
||||||
|
ServiceWorkerMain::GetConstructor(isolate, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -1869,7 +1869,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
gin_helper::Dictionary dict(isolate, exports);
|
gin_helper::Dictionary dict(isolate, exports);
|
||||||
dict.Set("Session", Session::GetConstructor(context));
|
dict.Set("Session", Session::GetConstructor(isolate, context));
|
||||||
dict.SetMethod("fromPartition", &FromPartition);
|
dict.SetMethod("fromPartition", &FromPartition);
|
||||||
dict.SetMethod("fromPath", &FromPath);
|
dict.SetMethod("fromPath", &FromPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,7 +447,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
gin::Dictionary dict{isolate, exports};
|
gin::Dictionary dict{isolate, exports};
|
||||||
dict.Set("Tray", Tray::GetConstructor(context));
|
dict.Set("Tray", Tray::GetConstructor(isolate, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -4662,7 +4662,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
gin_helper::Dictionary dict{isolate, exports};
|
gin_helper::Dictionary dict{isolate, exports};
|
||||||
dict.Set("WebContents", WebContents::GetConstructor(context));
|
dict.Set("WebContents", WebContents::GetConstructor(isolate, context));
|
||||||
dict.SetMethod("fromId", &WebContentsFromID);
|
dict.SetMethod("fromId", &WebContentsFromID);
|
||||||
dict.SetMethod("fromFrame", &WebContentsFromFrame);
|
dict.SetMethod("fromFrame", &WebContentsFromFrame);
|
||||||
dict.SetMethod("fromDevToolsTargetId", &WebContentsFromDevToolsTargetID);
|
dict.SetMethod("fromDevToolsTargetId", &WebContentsFromDevToolsTargetID);
|
||||||
|
|
|
@ -675,7 +675,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
gin_helper::Dictionary dict{isolate, exports};
|
gin_helper::Dictionary dict{isolate, exports};
|
||||||
dict.Set("WebFrameMain", WebFrameMain::GetConstructor(context));
|
dict.Set("WebFrameMain", WebFrameMain::GetConstructor(isolate, context));
|
||||||
dict.SetMethod("fromId", &FromID);
|
dict.SetMethod("fromId", &FromID);
|
||||||
dict.SetMethod("_fromIdIfExists", &FromIdIfExists);
|
dict.SetMethod("_fromIdIfExists", &FromIdIfExists);
|
||||||
dict.SetMethod("_fromFtnIdIfExists", &FromFtnIdIfExists);
|
dict.SetMethod("_fromFtnIdIfExists", &FromFtnIdIfExists);
|
||||||
|
|
|
@ -232,13 +232,14 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
|
||||||
// avoid conflicts we only initialize our V8 environment after that.
|
// avoid conflicts we only initialize our V8 environment after that.
|
||||||
js_env_ = std::make_unique<JavascriptEnvironment>(node_bindings_->uv_loop());
|
js_env_ = std::make_unique<JavascriptEnvironment>(node_bindings_->uv_loop());
|
||||||
|
|
||||||
v8::HandleScope scope(js_env_->isolate());
|
v8::Isolate* const isolate = js_env_->isolate();
|
||||||
|
v8::HandleScope scope(isolate);
|
||||||
|
|
||||||
node_bindings_->Initialize(js_env_->isolate()->GetCurrentContext());
|
node_bindings_->Initialize(isolate, isolate->GetCurrentContext());
|
||||||
// Create the global environment.
|
// Create the global environment.
|
||||||
node_env_ = node_bindings_->CreateEnvironment(
|
node_env_ = node_bindings_->CreateEnvironment(
|
||||||
js_env_->isolate(), js_env_->isolate()->GetCurrentContext(),
|
isolate, isolate->GetCurrentContext(), js_env_->platform(),
|
||||||
js_env_->platform(), js_env_->max_young_generation_size_in_bytes());
|
js_env_->max_young_generation_size_in_bytes());
|
||||||
|
|
||||||
node_env_->set_trace_sync_io(node_env_->options()->trace_sync_io);
|
node_env_->set_trace_sync_io(node_env_->options()->trace_sync_io);
|
||||||
|
|
||||||
|
@ -246,7 +247,7 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
|
||||||
node_env_->options()->unhandled_rejections = "warn-with-error-code";
|
node_env_->options()->unhandled_rejections = "warn-with-error-code";
|
||||||
|
|
||||||
// Add Electron extended APIs.
|
// Add Electron extended APIs.
|
||||||
electron_bindings_->BindTo(js_env_->isolate(), node_env_->process_object());
|
electron_bindings_->BindTo(isolate, node_env_->process_object());
|
||||||
|
|
||||||
// Create explicit microtasks runner.
|
// Create explicit microtasks runner.
|
||||||
js_env_->CreateMicrotasksRunner();
|
js_env_->CreateMicrotasksRunner();
|
||||||
|
|
|
@ -40,8 +40,8 @@ template <typename T>
|
||||||
class Constructible {
|
class Constructible {
|
||||||
public:
|
public:
|
||||||
static v8::Local<v8::Function> GetConstructor(
|
static v8::Local<v8::Function> GetConstructor(
|
||||||
|
v8::Isolate* const isolate,
|
||||||
v8::Local<v8::Context> context) {
|
v8::Local<v8::Context> context) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
|
||||||
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
|
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
|
||||||
auto* wrapper_info = &T::kWrapperInfo;
|
auto* wrapper_info = &T::kWrapperInfo;
|
||||||
v8::Local<v8::FunctionTemplate> constructor =
|
v8::Local<v8::FunctionTemplate> constructor =
|
||||||
|
|
|
@ -576,7 +576,8 @@ std::vector<std::string> NodeBindings::ParseNodeCliFlags() {
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeBindings::Initialize(v8::Local<v8::Context> context) {
|
void NodeBindings::Initialize(v8::Isolate* const isolate,
|
||||||
|
v8::Local<v8::Context> context) {
|
||||||
TRACE_EVENT0("electron", "NodeBindings::Initialize");
|
TRACE_EVENT0("electron", "NodeBindings::Initialize");
|
||||||
// Open node's error reporting system for browser process.
|
// Open node's error reporting system for browser process.
|
||||||
|
|
||||||
|
@ -635,7 +636,7 @@ void NodeBindings::Initialize(v8::Local<v8::Context> context) {
|
||||||
SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX);
|
SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gin_helper::internal::Event::GetConstructor(context);
|
gin_helper::internal::Event::GetConstructor(isolate, context);
|
||||||
|
|
||||||
g_is_initialized = true;
|
g_is_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ class NodeBindings {
|
||||||
virtual ~NodeBindings();
|
virtual ~NodeBindings();
|
||||||
|
|
||||||
// Setup V8, libuv.
|
// Setup V8, libuv.
|
||||||
void Initialize(v8::Local<v8::Context> context);
|
void Initialize(v8::Isolate* isolate, v8::Local<v8::Context> context);
|
||||||
|
|
||||||
std::vector<std::string> ParseNodeCliFlags();
|
std::vector<std::string> ParseNodeCliFlags();
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ void ElectronApiServiceImpl::Message(bool internal,
|
||||||
|
|
||||||
v8::Local<v8::Value> args = gin::ConvertToV8(isolate, arguments);
|
v8::Local<v8::Value> args = gin::ConvertToV8(isolate, arguments);
|
||||||
|
|
||||||
ipc_native::EmitIPCEvent(context, internal, channel, {}, args);
|
ipc_native::EmitIPCEvent(isolate, context, internal, channel, {}, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronApiServiceImpl::ReceivePostMessage(
|
void ElectronApiServiceImpl::ReceivePostMessage(
|
||||||
|
@ -125,7 +125,7 @@ void ElectronApiServiceImpl::ReceivePostMessage(
|
||||||
|
|
||||||
std::vector<v8::Local<v8::Value>> args = {message_value};
|
std::vector<v8::Local<v8::Value>> args = {message_value};
|
||||||
|
|
||||||
ipc_native::EmitIPCEvent(context, false, channel, ports,
|
ipc_native::EmitIPCEvent(isolate, context, false, channel, ports,
|
||||||
gin::ConvertToV8(isolate, args));
|
gin::ConvertToV8(isolate, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@ namespace {
|
||||||
constexpr std::string_view kIpcKey = "ipcNative";
|
constexpr std::string_view kIpcKey = "ipcNative";
|
||||||
|
|
||||||
// Gets the private object under kIpcKey
|
// Gets the private object under kIpcKey
|
||||||
v8::Local<v8::Object> GetIpcObject(const v8::Local<v8::Context>& context) {
|
v8::Local<v8::Object> GetIpcObject(v8::Isolate* const isolate,
|
||||||
auto* isolate = context->GetIsolate();
|
const v8::Local<v8::Context>& context) {
|
||||||
auto binding_key = gin::StringToV8(isolate, kIpcKey);
|
auto binding_key = gin::StringToV8(isolate, kIpcKey);
|
||||||
auto private_binding_key = v8::Private::ForApi(isolate, binding_key);
|
auto private_binding_key = v8::Private::ForApi(isolate, binding_key);
|
||||||
auto global_object = context->Global();
|
auto global_object = context->Global();
|
||||||
|
@ -33,13 +33,13 @@ v8::Local<v8::Object> GetIpcObject(const v8::Local<v8::Context>& context) {
|
||||||
return value->ToObject(context).ToLocalChecked();
|
return value->ToObject(context).ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InvokeIpcCallback(const v8::Local<v8::Context>& context,
|
void InvokeIpcCallback(v8::Isolate* const isolate,
|
||||||
|
const v8::Local<v8::Context>& context,
|
||||||
const std::string& callback_name,
|
const std::string& callback_name,
|
||||||
std::vector<v8::Local<v8::Value>> args) {
|
std::vector<v8::Local<v8::Value>> args) {
|
||||||
TRACE_EVENT0("devtools.timeline", "FunctionCall");
|
TRACE_EVENT0("devtools.timeline", "FunctionCall");
|
||||||
auto* isolate = context->GetIsolate();
|
|
||||||
|
|
||||||
auto ipcNative = GetIpcObject(context);
|
auto ipcNative = GetIpcObject(isolate, context);
|
||||||
if (ipcNative.IsEmpty())
|
if (ipcNative.IsEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -62,13 +62,12 @@ void InvokeIpcCallback(const v8::Local<v8::Context>& context,
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void EmitIPCEvent(const v8::Local<v8::Context>& context,
|
void EmitIPCEvent(v8::Isolate* const isolate,
|
||||||
|
const v8::Local<v8::Context>& context,
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
std::vector<v8::Local<v8::Value>> ports,
|
std::vector<v8::Local<v8::Value>> ports,
|
||||||
v8::Local<v8::Value> args) {
|
v8::Local<v8::Value> args) {
|
||||||
auto* isolate = context->GetIsolate();
|
|
||||||
|
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
v8::Context::Scope context_scope(context);
|
v8::Context::Scope context_scope(context);
|
||||||
v8::MicrotasksScope script_scope(isolate, context->GetMicrotaskQueue(),
|
v8::MicrotasksScope script_scope(isolate, context->GetMicrotaskQueue(),
|
||||||
|
@ -78,7 +77,7 @@ void EmitIPCEvent(const v8::Local<v8::Context>& context,
|
||||||
gin::ConvertToV8(isolate, internal), gin::ConvertToV8(isolate, channel),
|
gin::ConvertToV8(isolate, internal), gin::ConvertToV8(isolate, channel),
|
||||||
gin::ConvertToV8(isolate, ports), args};
|
gin::ConvertToV8(isolate, ports), args};
|
||||||
|
|
||||||
InvokeIpcCallback(context, "onMessage", argv);
|
InvokeIpcCallback(isolate, context, "onMessage", argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace electron::ipc_native
|
} // namespace electron::ipc_native
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
namespace electron::ipc_native {
|
namespace electron::ipc_native {
|
||||||
|
|
||||||
void EmitIPCEvent(const v8::Local<v8::Context>& context,
|
void EmitIPCEvent(v8::Isolate* isolate,
|
||||||
|
const v8::Local<v8::Context>& context,
|
||||||
bool internal,
|
bool internal,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
std::vector<v8::Local<v8::Value>> ports,
|
std::vector<v8::Local<v8::Value>> ports,
|
||||||
|
|
|
@ -105,7 +105,7 @@ void ElectronRendererClient::DidCreateScriptContext(
|
||||||
|
|
||||||
if (!node_integration_initialized_) {
|
if (!node_integration_initialized_) {
|
||||||
node_integration_initialized_ = true;
|
node_integration_initialized_ = true;
|
||||||
node_bindings_->Initialize(renderer_context);
|
node_bindings_->Initialize(isolate, renderer_context);
|
||||||
node_bindings_->PrepareEmbedThread();
|
node_bindings_->PrepareEmbedThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,8 @@ void ServiceWorkerData::Message(bool internal,
|
||||||
|
|
||||||
v8::Local<v8::Value> args = gin::ConvertToV8(isolate, arguments);
|
v8::Local<v8::Value> args = gin::ConvertToV8(isolate, arguments);
|
||||||
|
|
||||||
ipc_native::EmitIPCEvent(preload_context, internal, channel, {}, args);
|
ipc_native::EmitIPCEvent(isolate, preload_context, internal, channel, {},
|
||||||
|
args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceWorkerData::ReceivePostMessage(const std::string& channel,
|
void ServiceWorkerData::ReceivePostMessage(const std::string& channel,
|
||||||
|
|
|
@ -122,9 +122,10 @@ void NodeService::Initialize(
|
||||||
|
|
||||||
js_env_ = std::make_unique<JavascriptEnvironment>(node_bindings_->uv_loop());
|
js_env_ = std::make_unique<JavascriptEnvironment>(node_bindings_->uv_loop());
|
||||||
|
|
||||||
v8::HandleScope scope(js_env_->isolate());
|
v8::Isolate* const isolate = js_env_->isolate();
|
||||||
|
v8::HandleScope scope{isolate};
|
||||||
|
|
||||||
node_bindings_->Initialize(js_env_->isolate()->GetCurrentContext());
|
node_bindings_->Initialize(isolate, isolate->GetCurrentContext());
|
||||||
|
|
||||||
// Append program path for process.argv0
|
// Append program path for process.argv0
|
||||||
auto program = base::CommandLine::ForCurrentProcess()->GetProgram();
|
auto program = base::CommandLine::ForCurrentProcess()->GetProgram();
|
||||||
|
@ -136,9 +137,9 @@ void NodeService::Initialize(
|
||||||
|
|
||||||
// Create the global environment.
|
// Create the global environment.
|
||||||
node_env_ = node_bindings_->CreateEnvironment(
|
node_env_ = node_bindings_->CreateEnvironment(
|
||||||
js_env_->isolate(), js_env_->isolate()->GetCurrentContext(),
|
isolate, isolate->GetCurrentContext(), js_env_->platform(),
|
||||||
js_env_->platform(), js_env_->max_young_generation_size_in_bytes(),
|
js_env_->max_young_generation_size_in_bytes(), params->args,
|
||||||
params->args, params->exec_args);
|
params->exec_args);
|
||||||
|
|
||||||
// Override the default handler set by NodeBindings.
|
// Override the default handler set by NodeBindings.
|
||||||
node_env_->isolate()->SetFatalErrorHandler(V8FatalErrorCallback);
|
node_env_->isolate()->SetFatalErrorHandler(V8FatalErrorCallback);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue