Skip to content

refactor: avoid deprecated v8::Context::GetIsolate() calls (pt 1) #47760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 21, 2025
Prev Previous commit
Next Next commit
refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment()
  • Loading branch information
ckerr committed Jul 18, 2025
commit 8a4f912ee0ae0dfb6bad194f1372c0a85f2e1d9e
4 changes: 2 additions & 2 deletions shell/browser/electron_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
node_bindings_->Initialize(js_env_->isolate()->GetCurrentContext());
// Create the global environment.
node_env_ = node_bindings_->CreateEnvironment(
js_env_->isolate()->GetCurrentContext(), js_env_->platform(),
js_env_->max_young_generation_size_in_bytes());
js_env_->isolate(), js_env_->isolate()->GetCurrentContext(),
js_env_->platform(), js_env_->max_young_generation_size_in_bytes());

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

Expand Down
9 changes: 5 additions & 4 deletions shell/common/node_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ void NodeBindings::Initialize(v8::Local<v8::Context> context) {
}

std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
v8::Isolate* isolate,
v8::Local<v8::Context> context,
node::MultiIsolatePlatform* platform,
size_t max_young_generation_size,
Expand All @@ -664,7 +665,6 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
break;
}

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

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

std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
v8::Isolate* const isolate,
v8::Local<v8::Context> context,
node::MultiIsolatePlatform* platform,
size_t max_young_generation_size,
std::optional<base::RepeatingCallback<void()>> on_app_code_ready) {
return CreateEnvironment(context, platform, max_young_generation_size,
ElectronCommandLine::AsUtf8(), {},
on_app_code_ready);
return CreateEnvironment(
isolate, context, platform, max_young_generation_size,
ElectronCommandLine::AsUtf8(), {}, on_app_code_ready);
}

void NodeBindings::LoadEnvironment(node::Environment* env) {
Expand Down
2 changes: 2 additions & 0 deletions shell/common/node_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class NodeBindings {

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

std::shared_ptr<node::Environment> CreateEnvironment(
v8::Isolate* isolate,
v8::Local<v8::Context> context,
node::MultiIsolatePlatform* platform,
size_t max_young_generation_size = 0,
Expand Down
4 changes: 2 additions & 2 deletions shell/renderer/electron_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ void ElectronRendererClient::DidCreateScriptContext(
render_frame->GetWebFrame()->GetDocumentLoader()->SetDefersLoading(
blink::LoaderFreezeMode::kStrict);

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

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

std::vector<std::string> keys = {"fetch", "Response", "FormData",
Expand Down
4 changes: 2 additions & 2 deletions shell/renderer/web_worker_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ WebWorkerObserver::~WebWorkerObserver() = default;
void WebWorkerObserver::WorkerScriptReadyForEvaluation(
v8::Local<v8::Context> worker_context) {
v8::Context::Scope context_scope(worker_context);
auto* isolate = worker_context->GetIsolate();
v8::Isolate* const isolate = worker_context->GetIsolate();
v8::MicrotasksScope microtasks_scope(
worker_context, v8::MicrotasksScope::kDoNotRunMicrotasks);

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

// We need to use the Blink implementation of fetch in web workers
// Node.js deletes the global fetch function when their fetch implementation
Expand Down
6 changes: 3 additions & 3 deletions shell/services/node/node_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ void NodeService::Initialize(

// Create the global environment.
node_env_ = node_bindings_->CreateEnvironment(
js_env_->isolate()->GetCurrentContext(), js_env_->platform(),
js_env_->max_young_generation_size_in_bytes(), params->args,
params->exec_args);
js_env_->isolate(), js_env_->isolate()->GetCurrentContext(),
js_env_->platform(), js_env_->max_young_generation_size_in_bytes(),
params->args, params->exec_args);

// Override the default handler set by NodeBindings.
node_env_->isolate()->SetFatalErrorHandler(V8FatalErrorCallback);
Expand Down
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