From 6395898a7925cb288b5746042ad85f7cc37d6f2c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 22 Feb 2023 10:03:46 +0100 Subject: [PATCH] refactor: use associated `v8::Context` for event setup (#37355) refactor: use associated v8::Context for event setup --- shell/browser/electron_browser_main_parts.cc | 2 +- shell/common/node_bindings.cc | 5 ++--- shell/common/node_bindings.h | 2 +- shell/renderer/electron_renderer_client.cc | 2 +- shell/services/node/node_service.cc | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/shell/browser/electron_browser_main_parts.cc b/shell/browser/electron_browser_main_parts.cc index dafe1a932c11..96cebf055340 100644 --- a/shell/browser/electron_browser_main_parts.cc +++ b/shell/browser/electron_browser_main_parts.cc @@ -270,7 +270,7 @@ void ElectronBrowserMainParts::PostEarlyInitialization() { v8::HandleScope scope(js_env_->isolate()); - node_bindings_->Initialize(); + node_bindings_->Initialize(js_env_->isolate()->GetCurrentContext()); // Create the global environment. node::Environment* env = node_bindings_->CreateEnvironment( js_env_->isolate()->GetCurrentContext(), js_env_->platform()); diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 922840dc0de4..28447a277512 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -415,7 +415,7 @@ void NodeBindings::SetNodeCliFlags() { } } -void NodeBindings::Initialize() { +void NodeBindings::Initialize(v8::Local context) { TRACE_EVENT0("electron", "NodeBindings::Initialize"); // Open node's error reporting system for browser process. @@ -463,8 +463,7 @@ void NodeBindings::Initialize() { SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX); #endif - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - gin_helper::internal::Event::GetConstructor(isolate->GetCurrentContext()); + gin_helper::internal::Event::GetConstructor(context); g_is_initialized = true; } diff --git a/shell/common/node_bindings.h b/shell/common/node_bindings.h index 1f559f6e39fd..5476434f96c7 100644 --- a/shell/common/node_bindings.h +++ b/shell/common/node_bindings.h @@ -85,7 +85,7 @@ class NodeBindings { virtual ~NodeBindings(); // Setup V8, libuv. - void Initialize(); + void Initialize(v8::Local context); void SetNodeCliFlags(); diff --git a/shell/renderer/electron_renderer_client.cc b/shell/renderer/electron_renderer_client.cc index bb1fd5f748c8..bbdea3035c6c 100644 --- a/shell/renderer/electron_renderer_client.cc +++ b/shell/renderer/electron_renderer_client.cc @@ -76,7 +76,7 @@ void ElectronRendererClient::DidCreateScriptContext( if (!node_integration_initialized_) { node_integration_initialized_ = true; - node_bindings_->Initialize(); + node_bindings_->Initialize(renderer_context); node_bindings_->PrepareEmbedThread(); } diff --git a/shell/services/node/node_service.cc b/shell/services/node/node_service.cc index 7ce0fcb552d1..58a1a9a2e027 100644 --- a/shell/services/node/node_service.cc +++ b/shell/services/node/node_service.cc @@ -47,7 +47,7 @@ void NodeService::Initialize(node::mojom::NodeServiceParamsPtr params) { v8::HandleScope scope(js_env_->isolate()); - node_bindings_->Initialize(); + node_bindings_->Initialize(js_env_->isolate()->GetCurrentContext()); // Append program path for process.argv0 auto program = base::CommandLine::ForCurrentProcess()->GetProgram();