refactor: avoid deprecated v8::Context::GetIsolate() calls pt 3 context get isolate pt 3 (#47910)
* refactor: add a v8::Isolate* arg to RendererClientBase::IsWebViewFrame() Needed for creating gin dictionaries refactor: add a v8::Isolate* arg to ShouldLoadPreload() Needed for calling IsWebViewFrame() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add a v8::Isolate* arg to electron::util::CompileAndCall() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add a v8::Isolate* arg to OnCreatePreloadableV8Context() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add a v8::Isolate* arg to InvokeEmitProcessEvent() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add a v8::Isolate* arg to ServiceWorkerData's constructor Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add a v8::Isolate* arg to RendererClientBase::SetupMainWorldOverrides() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add a v8::Isolate* arg to RendererClientBase::WilLReleaseScriptContext() Co-authored-by: Charles Kerr <charles@charleskerr.com> * docs: update docs to avoid v8::Context::GetIsolate() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: add a v8::Isolate* arg to ElectronSandboxedRendererClient::InitializeBindings() Co-authored-by: Charles Kerr <charles@charleskerr.com> * refactor: avoid v8::Context::GetIsolate() call in PromiseBase::SettleScope::~SettleScope() 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:
parent
9b1dfe90f4
commit
f2d14ca29d
17 changed files with 73 additions and 55 deletions
|
@ -36,9 +36,9 @@ constinit thread_local ServiceWorkerData* service_worker_data = nullptr;
|
|||
|
||||
constexpr std::string_view kEmitProcessEventKey = "emit-process-event";
|
||||
|
||||
void InvokeEmitProcessEvent(v8::Local<v8::Context> context,
|
||||
void InvokeEmitProcessEvent(v8::Isolate* const isolate,
|
||||
v8::Local<v8::Context> context,
|
||||
const std::string& event_name) {
|
||||
auto* isolate = context->GetIsolate();
|
||||
// set by sandboxed_renderer/init.js
|
||||
auto binding_key = gin::ConvertToV8(isolate, kEmitProcessEventKey)
|
||||
->ToString(context)
|
||||
|
@ -69,9 +69,9 @@ ElectronSandboxedRendererClient::~ElectronSandboxedRendererClient() = default;
|
|||
|
||||
void ElectronSandboxedRendererClient::InitializeBindings(
|
||||
v8::Local<v8::Object> binding,
|
||||
v8::Isolate* const isolate,
|
||||
v8::Local<v8::Context> context,
|
||||
content::RenderFrame* render_frame) {
|
||||
auto* isolate = context->GetIsolate();
|
||||
gin_helper::Dictionary b(isolate, binding);
|
||||
b.SetMethod("get", preload_utils::GetBinding);
|
||||
b.SetMethod("createPreloadScript", preload_utils::CreatePreloadScript);
|
||||
|
@ -114,7 +114,7 @@ void ElectronSandboxedRendererClient::DidCreateScriptContext(
|
|||
// Only allow preload for the main frame or
|
||||
// For devtools we still want to run the preload_bundle script
|
||||
// Or when nodeSupport is explicitly enabled in sub frames
|
||||
if (!ShouldLoadPreload(context, render_frame))
|
||||
if (!ShouldLoadPreload(isolate, context, render_frame))
|
||||
return;
|
||||
|
||||
injected_frames_.insert(render_frame);
|
||||
|
@ -122,7 +122,7 @@ void ElectronSandboxedRendererClient::DidCreateScriptContext(
|
|||
// Wrap the bundle into a function that receives the binding object as
|
||||
// argument.
|
||||
auto binding = v8::Object::New(isolate);
|
||||
InitializeBindings(binding, context, render_frame);
|
||||
InitializeBindings(binding, isolate, context, render_frame);
|
||||
|
||||
v8::LocalVector<v8::String> sandbox_preload_bundle_params(
|
||||
isolate, {node::FIXED_ONE_BYTE_STRING(isolate, "binding")});
|
||||
|
@ -130,26 +130,26 @@ void ElectronSandboxedRendererClient::DidCreateScriptContext(
|
|||
v8::LocalVector<v8::Value> sandbox_preload_bundle_args(isolate, {binding});
|
||||
|
||||
util::CompileAndCall(
|
||||
isolate->GetCurrentContext(), "electron/js2c/sandbox_bundle",
|
||||
isolate, isolate->GetCurrentContext(), "electron/js2c/sandbox_bundle",
|
||||
&sandbox_preload_bundle_params, &sandbox_preload_bundle_args);
|
||||
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Context::Scope context_scope(context);
|
||||
InvokeEmitProcessEvent(context, "loaded");
|
||||
v8::HandleScope handle_scope{isolate};
|
||||
v8::Context::Scope context_scope{context};
|
||||
InvokeEmitProcessEvent(isolate, context, "loaded");
|
||||
}
|
||||
|
||||
void ElectronSandboxedRendererClient::WillReleaseScriptContext(
|
||||
v8::Isolate* const isolate,
|
||||
v8::Local<v8::Context> context,
|
||||
content::RenderFrame* render_frame) {
|
||||
if (injected_frames_.erase(render_frame) == 0)
|
||||
return;
|
||||
|
||||
auto* isolate = context->GetIsolate();
|
||||
v8::MicrotasksScope microtasks_scope(
|
||||
context, v8::MicrotasksScope::kDoNotRunMicrotasks);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Context::Scope context_scope(context);
|
||||
InvokeEmitProcessEvent(context, "exit");
|
||||
v8::HandleScope handle_scope{isolate};
|
||||
v8::Context::Scope context_scope{context};
|
||||
InvokeEmitProcessEvent(isolate, context, "exit");
|
||||
}
|
||||
|
||||
void ElectronSandboxedRendererClient::EmitProcessEvent(
|
||||
|
@ -163,11 +163,11 @@ void ElectronSandboxedRendererClient::EmitProcessEvent(
|
|||
v8::HandleScope handle_scope{isolate};
|
||||
|
||||
v8::Local<v8::Context> context = GetContext(frame, isolate);
|
||||
v8::MicrotasksScope microtasks_scope(
|
||||
context, v8::MicrotasksScope::kDoNotRunMicrotasks);
|
||||
v8::Context::Scope context_scope(context);
|
||||
v8::MicrotasksScope microtasks_scope{
|
||||
context, v8::MicrotasksScope::kDoNotRunMicrotasks};
|
||||
v8::Context::Scope context_scope{context};
|
||||
|
||||
InvokeEmitProcessEvent(context, event_name);
|
||||
InvokeEmitProcessEvent(isolate, context, event_name);
|
||||
}
|
||||
|
||||
void ElectronSandboxedRendererClient::WillEvaluateServiceWorkerOnWorkerThread(
|
||||
|
@ -183,12 +183,14 @@ void ElectronSandboxedRendererClient::WillEvaluateServiceWorkerOnWorkerThread(
|
|||
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (command_line->HasSwitch(switches::kServiceWorkerPreload)) {
|
||||
v8::Isolate* const v8_isolate = v8_context->GetIsolate();
|
||||
|
||||
if (!service_worker_data) {
|
||||
service_worker_data = new ServiceWorkerData(
|
||||
context_proxy, service_worker_version_id, v8_context);
|
||||
service_worker_data = new ServiceWorkerData{
|
||||
context_proxy, service_worker_version_id, v8_isolate, v8_context};
|
||||
}
|
||||
|
||||
preload_realm::OnCreatePreloadableV8Context(v8_context,
|
||||
preload_realm::OnCreatePreloadableV8Context(v8_isolate, v8_context,
|
||||
service_worker_data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue