Skip to content

Commit 7c9ee3f

Browse files
committed
refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment()
1 parent 9604107 commit 7c9ee3f

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

shell/browser/electron_browser_main_parts.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
237237
node_bindings_->Initialize(js_env_->isolate()->GetCurrentContext());
238238
// Create the global environment.
239239
node_env_ = node_bindings_->CreateEnvironment(
240-
js_env_->isolate()->GetCurrentContext(), js_env_->platform(),
241-
js_env_->max_young_generation_size_in_bytes());
240+
js_env_->isolate(), js_env_->isolate()->GetCurrentContext(),
241+
js_env_->platform(), js_env_->max_young_generation_size_in_bytes());
242242

243243
node_env_->set_trace_sync_io(node_env_->options()->trace_sync_io);
244244

shell/common/node_bindings.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ void NodeBindings::Initialize(v8::Local<v8::Context> context) {
641641
}
642642

643643
std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
644+
v8::Isolate* isolate,
644645
v8::Local<v8::Context> context,
645646
node::MultiIsolatePlatform* platform,
646647
size_t max_young_generation_size,
@@ -664,7 +665,6 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
664665
break;
665666
}
666667

667-
v8::Isolate* isolate = v8::Isolate::GetCurrent();
668668
gin_helper::Dictionary global(isolate, context->Global());
669669

670670
if (browser_env_ == BrowserEnvironment::kBrowser) {
@@ -832,13 +832,14 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
832832
}
833833

834834
std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
835+
v8::Isolate* const isolate,
835836
v8::Local<v8::Context> context,
836837
node::MultiIsolatePlatform* platform,
837838
size_t max_young_generation_size,
838839
std::optional<base::RepeatingCallback<void()>> on_app_code_ready) {
839-
return CreateEnvironment(context, platform, max_young_generation_size,
840-
ElectronCommandLine::AsUtf8(), {},
841-
on_app_code_ready);
840+
return CreateEnvironment(
841+
isolate, context, platform, max_young_generation_size,
842+
ElectronCommandLine::AsUtf8(), {}, on_app_code_ready);
842843
}
843844

844845
void NodeBindings::LoadEnvironment(node::Environment* env) {

shell/common/node_bindings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class NodeBindings {
131131

132132
// Create the environment and load node.js.
133133
std::shared_ptr<node::Environment> CreateEnvironment(
134+
v8::Isolate* isolate,
134135
v8::Local<v8::Context> context,
135136
node::MultiIsolatePlatform* platform,
136137
size_t max_young_generation_size,
@@ -140,6 +141,7 @@ class NodeBindings {
140141
std::nullopt);
141142

142143
std::shared_ptr<node::Environment> CreateEnvironment(
144+
v8::Isolate* isolate,
143145
v8::Local<v8::Context> context,
144146
node::MultiIsolatePlatform* platform,
145147
size_t max_young_generation_size = 0,

shell/renderer/electron_renderer_client.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ void ElectronRendererClient::DidCreateScriptContext(
125125
render_frame->GetWebFrame()->GetDocumentLoader()->SetDefersLoading(
126126
blink::LoaderFreezeMode::kStrict);
127127

128+
v8::Isolate* const isolate = renderer_context->GetIsolate();
128129
std::shared_ptr<node::Environment> env = node_bindings_->CreateEnvironment(
129-
renderer_context, nullptr, 0,
130+
isolate, renderer_context, nullptr, 0,
130131
base::BindRepeating(&ElectronRendererClient::UndeferLoad,
131132
base::Unretained(this), render_frame));
132133

133134
// We need to use the Blink implementation of fetch in the renderer process
134135
// Node.js deletes the global fetch function when their fetch implementation
135136
// is disabled, so we need to save and re-add it after the Node.js environment
136137
// is loaded. See corresponding change in node/init.ts.
137-
v8::Isolate* isolate = env->isolate();
138138
v8::Local<v8::Object> global = renderer_context->Global();
139139

140140
std::vector<std::string> keys = {"fetch", "Response", "FormData",

shell/renderer/web_worker_observer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ WebWorkerObserver::~WebWorkerObserver() = default;
4949
void WebWorkerObserver::WorkerScriptReadyForEvaluation(
5050
v8::Local<v8::Context> worker_context) {
5151
v8::Context::Scope context_scope(worker_context);
52-
auto* isolate = worker_context->GetIsolate();
52+
v8::Isolate* const isolate = worker_context->GetIsolate();
5353
v8::MicrotasksScope microtasks_scope(
5454
worker_context, v8::MicrotasksScope::kDoNotRunMicrotasks);
5555

@@ -66,7 +66,7 @@ void WebWorkerObserver::WorkerScriptReadyForEvaluation(
6666
v8::Maybe<bool> initialized = node::InitializeContext(worker_context);
6767
CHECK(!initialized.IsNothing() && initialized.FromJust());
6868
std::shared_ptr<node::Environment> env =
69-
node_bindings_->CreateEnvironment(worker_context, nullptr);
69+
node_bindings_->CreateEnvironment(isolate, worker_context, nullptr);
7070

7171
// We need to use the Blink implementation of fetch in web workers
7272
// Node.js deletes the global fetch function when their fetch implementation

shell/services/node/node_service.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ void NodeService::Initialize(
136136

137137
// Create the global environment.
138138
node_env_ = node_bindings_->CreateEnvironment(
139-
js_env_->isolate()->GetCurrentContext(), js_env_->platform(),
140-
js_env_->max_young_generation_size_in_bytes(), params->args,
141-
params->exec_args);
139+
js_env_->isolate(), js_env_->isolate()->GetCurrentContext(),
140+
js_env_->platform(), js_env_->max_young_generation_size_in_bytes(),
141+
params->args, params->exec_args);
142142

143143
// Override the default handler set by NodeBindings.
144144
node_env_->isolate()->SetFatalErrorHandler(V8FatalErrorCallback);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy