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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ckerr
Copy link
Member

@ckerr ckerr commented Jul 15, 2025

Description of Change

Part 1 of a very short series to remove calls to v8::Context::GetIsolate() which is being deprecated.

Even though the individual changes are pretty straightforward, the overall diff is pretty heavy due to the number of places where we are using that method. So I'm breaking into a couple of smaller PRs to make review easier.

This PR:

  1. Stops using GetIsolate() in NodeBindings::CreateEnvironment() by adding a v8::Isolate* arg to that method.
  2. Stops using GetIsolate() in the Node.js module Initialize() methods by using v8::Isolate::GetCurrent() instead.

Checklist

Release Notes

Notes: none.

@ckerr ckerr added semver/patch backwards-compatible bug fixes target/38-x-y PR should also be added to the "38-x-y" branch. labels Jul 15, 2025
@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jul 15, 2025
@@ -1856,8 +1856,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For browser layer usages it would be better to replace with JavascriptEnvironment::GetIsolate

@@ -125,16 +125,16 @@ void ElectronRendererClient::DidCreateScriptContext(
render_frame->GetWebFrame()->GetDocumentLoader()->SetDefersLoading(
blink::LoaderFreezeMode::kStrict);

v8::Isolate* const isolate = renderer_context->GetIsolate();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not call v8::Isolate::GetCurrent() here already ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepak1556 see #24179 - we shouldn't be trying to use v8::Isolate::GetCurrent() if we have other options imho

Copy link
Member

@deepak1556 deepak1556 Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow, isn't getting isolate from context is being deprecated ? Whats' the alternative here, this is the renderer layer fwiw

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://chromium-review.googlesource.com/c/chromium/src/+/6718066 v8::Isolate::GetCurrent is what is being preferred for third_party/blink irrespective of the source context.

@@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes target/38-x-y PR should also be added to the "38-x-y" branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
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