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

* refactor: avoid redundant GetIsolate() calls in NodeBindings::CreateEnvironment()

Xref: 6563615

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use v8::Isolate::GetCurrent() in Initialize() methods

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fixup! refactor: use v8::Isolate::GetCurrent() in Initialize() methods

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: add v8::Isolate* arg to RendererClientBase::DidCreateScriptContext()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fixup! refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* fixup! fixup! refactor: use v8::Isolate::GetCurrent() in Initialize() methods

refactor: prefer JavascriptEnvironment::GetIsolate() in the browser layer

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:
trop[bot] 2025-07-21 13:12:24 -04:00 committed by GitHub
parent 673ec5d39e
commit d426b92326
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 136 additions and 110 deletions

View file

@ -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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("app", electron::api::App::Create(isolate));
}

View file

@ -152,8 +152,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("autoUpdater", AutoUpdater::Create(isolate));
}

View file

@ -1302,7 +1302,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
BaseWindow::SetConstructor(isolate, base::BindRepeating(&BaseWindow::New));
gin_helper::Dictionary constructor(isolate,

View file

@ -341,8 +341,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("BrowserWindow",
gin_helper::CreateConstructor<BrowserWindow>(
isolate, base::BindRepeating(&BrowserWindow::New)));

View file

@ -13,6 +13,7 @@
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/trace_config.h"
#include "content/public/browser/tracing_controller.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_converters/value_converter.h"
@ -171,7 +172,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("getCategories", &GetCategories);
dict.SetMethod("startRecording", &StartTracing);
dict.SetMethod("stopRecording", &StopRecording);

View file

@ -21,6 +21,7 @@
#include "electron/mas.h"
#include "gin/arguments.h"
#include "gin/data_object_builder.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/electron_paths.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
@ -261,7 +262,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
dict.SetMethod("start", &electron::api::crash_reporter::Start);
#if IS_MAS_BUILD()
dict.SetMethod("addExtraParameter", &electron::api::crash_reporter::NoOp);

View file

@ -539,7 +539,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("createDesktopCapturer",
&electron::api::DesktopCapturer::Create);
dict.SetMethod(

View file

@ -5,6 +5,7 @@
#include <utility>
#include <vector>
#include "shell/browser/javascript_environment.h"
#include "shell/browser/ui/certificate_trust.h"
#include "shell/browser/ui/file_dialog.h"
#include "shell/browser/ui/message_box.h"
@ -89,8 +90,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("showMessageBoxSync", &ShowMessageBoxSync);
dict.SetMethod("showMessageBox", &ShowMessageBox);
dict.SetMethod("_closeMessageBox", &electron::CloseMessageBox);

View file

@ -7,6 +7,7 @@
#include "base/functional/bind.h"
#include "base/no_destructor.h"
#include "gin/dictionary.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/node_includes.h"
#include "v8/include/v8.h"
@ -27,9 +28,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::Dictionary dict(isolate, exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin::Dictionary dict{isolate, exports};
dict.Set("setEventEmitterPrototype",
base::BindRepeating(&SetEventEmitterPrototype));
}

View file

@ -247,8 +247,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::Dictionary dict(isolate, exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin::Dictionary dict{isolate, exports};
dict.Set("globalShortcut", electron::api::GlobalShortcut::Create(isolate));
}

View file

@ -216,8 +216,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
#if BUILDFLAG(IS_MAC)
v8::Isolate* isolate = context->GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("inAppPurchase", InAppPurchase::Create(isolate));
#endif
}

View file

@ -325,9 +325,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("Menu", Menu::GetConstructor(context));
#if BUILDFLAG(IS_MAC)
dict.SetMethod("setApplicationMenu", &Menu::SetApplicationMenu);

View file

@ -137,8 +137,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::Dictionary dict(isolate, exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin::Dictionary dict{isolate, exports};
dict.Set("nativeTheme", NativeTheme::Create(isolate));
}

View file

@ -251,8 +251,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("Notification", Notification::GetConstructor(context));
dict.SetMethod("isSupported", &Notification::IsSupported);
}

View file

@ -197,8 +197,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("createPowerMonitor",
base::BindRepeating(&PowerMonitor::Create));
dict.SetMethod("getSystemIdleState",

View file

@ -14,6 +14,7 @@
#include "gin/object_template_builder.h"
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/node_includes.h"
namespace gin {
@ -139,8 +140,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::Dictionary dict(isolate, exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin::Dictionary dict{isolate, exports};
dict.Set("powerSaveBlocker",
electron::api::PowerSaveBlocker::Create(isolate));
}

View file

@ -5,6 +5,7 @@
#include "chrome/browser/browser_process.h"
#include "gin/converter.h"
#include "printing/buildflags/buildflags.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
#include "shell/common/thread_restrictions.h"
@ -78,8 +79,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
#if BUILDFLAG(ENABLE_PRINTING)
dict.SetMethod("getPrinterListAsync",
base::BindRepeating(&GetPrinterListAsync));

View file

@ -14,6 +14,7 @@
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "shell/browser/browser.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/protocol_registry.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/net_converter.h"
@ -359,8 +360,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("Protocol", electron::api::Protocol::GetConstructor(context));
dict.SetMethod("registerSchemesAsPrivileged", &RegisterSchemesAsPrivileged);
dict.SetMethod("getStandardSchemes", &electron::api::GetStandardSchemes);

View file

@ -61,7 +61,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin::Dictionary dict(isolate, exports);
dict.Set("pushNotifications",
electron::api::PushNotifications::Create(isolate));

View file

@ -7,6 +7,7 @@
#include "components/os_crypt/sync/os_crypt.h"
#include "shell/browser/browser.h"
#include "shell/browser/browser_process_impl.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/gin_converters/base_converter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_helper/dictionary.h"
@ -131,7 +132,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
dict.SetMethod("decryptString", &DecryptString);
dict.SetMethod("encryptString", &EncryptString);

View file

@ -223,7 +223,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
dict.SetMethod("createScreen", base::BindRepeating(&Screen::Create));
}

View file

@ -354,8 +354,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("ServiceWorkerMain", ServiceWorkerMain::GetConstructor(context));
}

View file

@ -1864,7 +1864,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("Session", Session::GetConstructor(context));
dict.SetMethod("fromPartition", &FromPartition);

View file

@ -115,7 +115,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("systemPreferences", SystemPreferences::Create(isolate));
}

View file

@ -445,9 +445,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::Dictionary dict(isolate, exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin::Dictionary dict{isolate, exports};
dict.Set("Tray", Tray::GetConstructor(context));
}

View file

@ -530,8 +530,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("_fork", &electron::api::UtilityProcessWrapper::Create);
}

View file

@ -470,9 +470,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("View", View::GetConstructor(isolate));
}

View file

@ -4653,8 +4653,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("WebContents", WebContents::GetConstructor(context));
dict.SetMethod("fromId", &WebContentsFromID);
dict.SetMethod("fromFrame", &WebContentsFromFrame);

View file

@ -228,8 +228,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("WebContentsView", WebContentsView::GetConstructor(isolate));
}

View file

@ -674,8 +674,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("WebFrameMain", WebFrameMain::GetConstructor(context));
dict.SetMethod("fromId", &FromID);
dict.SetMethod("_fromIdIfExists", &FromIdIfExists);

View file

@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "content/public/browser/browser_context.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/web_contents_preferences.h"
#include "shell/browser/web_contents_zoom_controller.h"
#include "shell/browser/web_view_manager.h"
@ -40,7 +41,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("addGuest", &AddGuest);
dict.SetMethod("removeGuest", &RemoveGuest);
}

View file

@ -316,8 +316,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("createPair", &CreatePair);
}

View file

@ -4,6 +4,7 @@
#include "shell/browser/api/views/electron_api_image_view.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
@ -49,8 +50,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 = electron::JavascriptEnvironment::GetIsolate();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("ImageView", gin_helper::CreateConstructor<ImageView>(
isolate, base::BindRepeating(&ImageView::New)));
}

View file

@ -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);

View file

@ -27,7 +27,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
#if BUILDFLAG(IS_LINUX)
dict.SetMethod("getCrashdumpSignalFD", &GetCrashdumpSignalFD);
dict.SetMethod("getCrashpadHandlerPID", &GetCrashpadHandlerPID);

View file

@ -213,7 +213,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
auto* isolate = exports->GetIsolate();
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
auto cons = Archive::CreateFunctionTemplate(isolate)
->GetFunction(context)

View file

@ -294,7 +294,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("availableFormats",
&electron::api::Clipboard::AvailableFormats);
dict.SetMethod("has", &electron::api::Clipboard::Has);

View file

@ -64,7 +64,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("hasSwitch", &HasSwitch);
dict.SetMethod("getSwitchValue", &GetSwitchValue);
dict.SetMethod("appendSwitch", &AppendSwitch);

View file

@ -29,7 +29,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("getVar", &GetVar);
dict.SetMethod("hasVar", &HasVar);
dict.SetMethod("setVar", &SetVar);

View file

@ -619,8 +619,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();
gin_helper::Dictionary dict{isolate, exports};
auto native_image = gin_helper::Dictionary::CreateEmpty(isolate);
dict.Set("nativeImage", native_image);

View file

@ -80,9 +80,9 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict(isolate, exports);
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("isOnline", &IsOnline);
dict.SetMethod("isValidHeaderName", &IsValidHeaderName);
dict.SetMethod("isValidHeaderValue", &IsValidHeaderValue);

View file

@ -173,7 +173,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder);
dict.SetMethod("openPath", &OpenPath);
dict.SetMethod("openExternal", &OpenExternal);

View file

@ -45,7 +45,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("log", &Log);
dict.SetMethod("getLoggingDestination", &GetLoggingDestination);
}

View file

@ -99,7 +99,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("getHiddenValue", &GetHiddenValue);
dict.SetMethod("setHiddenValue", &SetHiddenValue);
dict.SetMethod("getObjectHash", &GetObjectHash);

View file

@ -41,7 +41,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("isBuiltinSpellCheckerEnabled", &IsBuiltinSpellCheckerEnabled);
dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled);
dict.SetMethod("isFakeLocationProviderEnabled",

View file

@ -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,
@ -664,7 +665,6 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
break;
}
v8::Isolate* isolate = context->GetIsolate();
gin_helper::Dictionary global(isolate, context->Global());
if (browser_env_ == BrowserEnvironment::kBrowser) {
@ -766,7 +766,7 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
// could be either kExplicit or kScoped depending on whether we're executing
// from within a Node.js or a Blink entrypoint. Instead, the policy is
// toggled to kExplicit when entering Node.js through UvRunOnce.
is.policy = context->GetIsolate()->GetMicrotasksPolicy();
is.policy = isolate->GetMicrotasksPolicy();
// We do not want to use Node.js' message listener as it interferes with
// Blink's.
@ -775,8 +775,8 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
// Isolate message listeners are additive (you can add multiple), so instead
// we add an extra one here to ensure that the async hook stack is properly
// cleared when errors are thrown.
context->GetIsolate()->AddMessageListenerWithErrorLevel(
ErrorMessageListener, v8::Isolate::kMessageError);
isolate->AddMessageListenerWithErrorLevel(ErrorMessageListener,
v8::Isolate::kMessageError);
// We do not want to use the promise rejection callback that Node.js uses,
// because it does not send PromiseRejectionEvents to the global script
@ -792,15 +792,14 @@ std::shared_ptr<node::Environment> NodeBindings::CreateEnvironment(
node::IsolateSettingsFlags::SHOULD_NOT_SET_PREPARE_STACK_TRACE_CALLBACK;
}
node::SetIsolateUpForNode(context->GetIsolate(), is);
context->GetIsolate()->SetHostImportModuleDynamicallyCallback(
HostImportModuleDynamically);
context->GetIsolate()->SetHostImportModuleWithPhaseDynamicallyCallback(
node::SetIsolateUpForNode(isolate, is);
isolate->SetHostImportModuleDynamicallyCallback(HostImportModuleDynamically);
isolate->SetHostImportModuleWithPhaseDynamicallyCallback(
HostImportModuleWithPhaseDynamically);
context->GetIsolate()->SetHostInitializeImportMetaObjectCallback(
isolate->SetHostInitializeImportMetaObjectCallback(
HostInitializeImportMetaObject);
gin_helper::Dictionary process(context->GetIsolate(), env->process_object());
gin_helper::Dictionary process(isolate, env->process_object());
process.SetReadOnly("type", process_type);
if (browser_env_ == BrowserEnvironment::kBrowser ||
@ -833,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) {

View file

@ -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,
@ -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,

View file

@ -1106,8 +1106,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();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("executeInWorld", &electron::api::ExecuteInWorld);
dict.SetMethod("exposeAPIInWorld", &electron::api::ExposeAPIInWorld);
dict.SetMethod("_overrideGlobalValueFromIsolatedWorld",

View file

@ -29,7 +29,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
#if IS_MAS_BUILD()
dict.SetMethod("addExtraParameter", &SetCrashKeyStub);
dict.SetMethod("removeExtraParameter", &ClearCrashKeyStub);

View file

@ -267,7 +267,8 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
gin_helper::Dictionary dict(context->GetIsolate(), exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("createForRenderFrame", &IPCRenderFrame::Create);
dict.SetMethod("createForServiceWorker", &IPCServiceWorker::Create);
}

View file

@ -963,8 +963,8 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
using namespace electron::api; // NOLINT(build/namespaces)
v8::Isolate* isolate = context->GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
v8::Isolate* const isolate = v8::Isolate::GetCurrent();
gin_helper::Dictionary dict{isolate, exports};
dict.Set("mainFrame", WebFrameRenderer::Create(
isolate, electron::GetRenderFrame(exports)));
}

View file

@ -30,8 +30,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();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("getPathForFile", &electron::api::web_utils::GetPathForFile);
}

View file

@ -123,7 +123,8 @@ void ElectronRenderFrameObserver::DidInstallConditionalFeatures(
context, v8::MicrotasksScope::kDoNotRunMicrotasks);
if (ShouldNotifyClient(world_id))
renderer_client_->DidCreateScriptContext(context, render_frame_);
renderer_client_->DidCreateScriptContext(v8::Isolate::GetCurrent(), context,
render_frame_);
auto prefs = render_frame_->GetBlinkPreferences();
bool use_context_isolation = prefs.context_isolation;

View file

@ -90,6 +90,7 @@ void ElectronRendererClient::UndeferLoad(content::RenderFrame* render_frame) {
}
void ElectronRendererClient::DidCreateScriptContext(
v8::Isolate* const isolate,
v8::Local<v8::Context> renderer_context,
content::RenderFrame* render_frame) {
// TODO(zcbenz): Do not create Node environment if node integration is not
@ -126,7 +127,7 @@ void ElectronRendererClient::DidCreateScriptContext(
blink::LoaderFreezeMode::kStrict);
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));
@ -134,7 +135,6 @@ void ElectronRendererClient::DidCreateScriptContext(
// 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",

View file

@ -29,7 +29,8 @@ class ElectronRendererClient : public RendererClientBase {
ElectronRendererClient& operator=(const ElectronRendererClient&) = delete;
// electron::RendererClientBase:
void DidCreateScriptContext(v8::Local<v8::Context> context,
void DidCreateScriptContext(v8::Isolate* isolate,
v8::Local<v8::Context> context,
content::RenderFrame* render_frame) override;
void WillReleaseScriptContext(v8::Local<v8::Context> context,
content::RenderFrame* render_frame) override;

View file

@ -108,6 +108,7 @@ void ElectronSandboxedRendererClient::RunScriptsAtDocumentEnd(
}
void ElectronSandboxedRendererClient::DidCreateScriptContext(
v8::Isolate* const isolate,
v8::Local<v8::Context> context,
content::RenderFrame* render_frame) {
// Only allow preload for the main frame or
@ -120,7 +121,6 @@ void ElectronSandboxedRendererClient::DidCreateScriptContext(
// Wrap the bundle into a function that receives the binding object as
// argument.
auto* isolate = context->GetIsolate();
auto binding = v8::Object::New(isolate);
InitializeBindings(binding, context, render_frame);

View file

@ -34,7 +34,8 @@ class ElectronSandboxedRendererClient : public RendererClientBase {
v8::Local<v8::Context> context,
content::RenderFrame* render_frame);
// electron::RendererClientBase:
void DidCreateScriptContext(v8::Local<v8::Context> context,
void DidCreateScriptContext(v8::Isolate* isolate,
v8::Local<v8::Context> context,
content::RenderFrame* render_frame) override;
void WillReleaseScriptContext(v8::Local<v8::Context> context,
content::RenderFrame* render_frame) override;

View file

@ -56,7 +56,8 @@ class RendererClientBase : public content::ContentRendererClient
mojo::ScopedMessagePipeHandle interface_pipe) override;
#endif
virtual void DidCreateScriptContext(v8::Local<v8::Context> context,
virtual void DidCreateScriptContext(v8::Isolate* isolate,
v8::Local<v8::Context> context,
content::RenderFrame* render_frame) = 0;
virtual void WillReleaseScriptContext(v8::Local<v8::Context> context,
content::RenderFrame* render_frame) = 0;

View file

@ -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 = v8::Isolate::GetCurrent();
v8::MicrotasksScope microtasks_scope(
worker_context, v8::MicrotasksScope::kDoNotRunMicrotasks);
@ -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

View file

@ -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);

View file

@ -131,8 +131,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();
gin_helper::Dictionary dict{isolate, exports};
dict.SetMethod("createParentPort", &electron::ParentPort::Create);
}