mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
refactor: avoid deprecated v8::Context::GetIsolate() calls (pt 1) (#47760)
* refactor: avoid redundant GetIsolate() calls in NodeBindings::CreateEnvironment() Xref: https://chromium-review.googlesource.com/c/v8/v8/+/6563615 * refactor: use v8::Isolate::GetCurrent() in Initialize() methods * refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment() * fixup! refactor: use v8::Isolate::GetCurrent() in Initialize() methods * refactor: add v8::Isolate* arg to RendererClientBase::DidCreateScriptContext() * fixup! refactor: add v8::Isolate* arg to NodeBindings::CreateEnvironment() * fixup! fixup! refactor: use v8::Isolate::GetCurrent() in Initialize() methods refactor: prefer JavascriptEnvironment::GetIsolate() in the browser layer
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user