diff --git a/shell/browser/api/electron_api_auto_updater.cc b/shell/browser/api/electron_api_auto_updater.cc index 2d870bba83bd..2a1feaa9d837 100644 --- a/shell/browser/api/electron_api_auto_updater.cc +++ b/shell/browser/api/electron_api_auto_updater.cc @@ -47,8 +47,8 @@ void AutoUpdater::OnError(const std::string& message) { }; gin_helper::MicrotasksScope microtasks_scope{ - isolate, wrapper->GetCreationContextChecked()->GetMicrotaskQueue(), - true, v8::MicrotasksScope::kRunMicrotasks}; + wrapper->GetCreationContextChecked(), true, + v8::MicrotasksScope::kRunMicrotasks}; node::MakeCallback(isolate, wrapper, "emit", args.size(), args.data(), {0, 0}); diff --git a/shell/common/api/electron_bindings.cc b/shell/common/api/electron_bindings.cc index 1bd968e16aa7..a2bc082ed0e0 100644 --- a/shell/common/api/electron_bindings.cc +++ b/shell/common/api/electron_bindings.cc @@ -240,8 +240,7 @@ void ElectronBindings::DidReceiveMemoryDump( v8::Local local_context = v8::Local::New(isolate, context); gin_helper::MicrotasksScope microtasks_scope{ - isolate, local_context->GetMicrotaskQueue(), true, - v8::MicrotasksScope::kRunMicrotasks}; + local_context, true, v8::MicrotasksScope::kRunMicrotasks}; v8::Context::Scope context_scope(local_context); if (!success) { diff --git a/shell/common/gin_helper/callback.h b/shell/common/gin_helper/callback.h index 7be65ec6d4e3..40babf18db7b 100644 --- a/shell/common/gin_helper/callback.h +++ b/shell/common/gin_helper/callback.h @@ -51,8 +51,7 @@ struct V8FunctionInvoker(ArgTypes...)> { v8::Local holder = function.NewHandle(isolate); v8::Local context = holder->GetCreationContextChecked(); gin_helper::MicrotasksScope microtasks_scope{ - isolate, context->GetMicrotaskQueue(), true, - v8::MicrotasksScope::kRunMicrotasks}; + context, true, v8::MicrotasksScope::kRunMicrotasks}; v8::Context::Scope context_scope(context); std::array, sizeof...(raw)> args{ gin::ConvertToV8(isolate, std::forward(raw))...}; @@ -77,8 +76,7 @@ struct V8FunctionInvoker { v8::Local holder = function.NewHandle(isolate); v8::Local context = holder->GetCreationContextChecked(); gin_helper::MicrotasksScope microtasks_scope{ - isolate, context->GetMicrotaskQueue(), true, - v8::MicrotasksScope::kRunMicrotasks}; + context, true, v8::MicrotasksScope::kRunMicrotasks}; v8::Context::Scope context_scope(context); std::array, sizeof...(raw)> args{ gin::ConvertToV8(isolate, std::forward(raw))...}; @@ -102,8 +100,7 @@ struct V8FunctionInvoker { v8::Local holder = function.NewHandle(isolate); v8::Local context = holder->GetCreationContextChecked(); gin_helper::MicrotasksScope microtasks_scope{ - isolate, context->GetMicrotaskQueue(), true, - v8::MicrotasksScope::kRunMicrotasks}; + context, true, v8::MicrotasksScope::kRunMicrotasks}; v8::Context::Scope context_scope(context); std::array, sizeof...(raw)> args{ gin::ConvertToV8(isolate, std::forward(raw))...}; diff --git a/shell/common/gin_helper/event_emitter_caller.cc b/shell/common/gin_helper/event_emitter_caller.cc index 2f4c50056ed1..360c84bebffc 100644 --- a/shell/common/gin_helper/event_emitter_caller.cc +++ b/shell/common/gin_helper/event_emitter_caller.cc @@ -25,7 +25,7 @@ v8::Local CallMethodWithArgs( // Perform microtask checkpoint after running JavaScript. gin_helper::MicrotasksScope microtasks_scope{ - isolate, obj->GetCreationContextChecked()->GetMicrotaskQueue(), true, + obj->GetCreationContextChecked(), true, v8::MicrotasksScope::kRunMicrotasks}; // node::MakeCallback will also run pending tasks in Node.js. diff --git a/shell/common/gin_helper/function_template.h b/shell/common/gin_helper/function_template.h index 0737c8b47448..5633184bec60 100644 --- a/shell/common/gin_helper/function_template.h +++ b/shell/common/gin_helper/function_template.h @@ -268,8 +268,7 @@ class Invoker, ArgTypes...> void DispatchToCallback( base::RepeatingCallback callback) { gin_helper::MicrotasksScope microtasks_scope{ - args_->isolate(), - args_->GetHolderCreationContext()->GetMicrotaskQueue(), true, + args_->GetHolderCreationContext(), true, v8::MicrotasksScope::kRunMicrotasks}; args_->Return( callback.Run(std::move(ArgumentHolder::value)...)); @@ -280,8 +279,7 @@ class Invoker, ArgTypes...> // that have the void return type. void DispatchToCallback(base::RepeatingCallback callback) { gin_helper::MicrotasksScope microtasks_scope{ - args_->isolate(), - args_->GetHolderCreationContext()->GetMicrotaskQueue(), true, + args_->GetHolderCreationContext(), true, v8::MicrotasksScope::kRunMicrotasks}; callback.Run(std::move(ArgumentHolder::value)...); } diff --git a/shell/common/gin_helper/microtasks_scope.cc b/shell/common/gin_helper/microtasks_scope.cc index 763d1893d852..9daff7872a81 100644 --- a/shell/common/gin_helper/microtasks_scope.cc +++ b/shell/common/gin_helper/microtasks_scope.cc @@ -5,13 +5,15 @@ #include "shell/common/gin_helper/microtasks_scope.h" #include "shell/common/process_util.h" +#include "v8/include/v8-context.h" namespace gin_helper { -MicrotasksScope::MicrotasksScope(v8::Isolate* isolate, - v8::MicrotaskQueue* microtask_queue, +MicrotasksScope::MicrotasksScope(v8::Local context, bool ignore_browser_checkpoint, v8::MicrotasksScope::Type scope_type) { + auto* isolate = context->GetIsolate(); + auto* microtask_queue = context->GetMicrotaskQueue(); if (electron::IsBrowserProcess()) { if (!ignore_browser_checkpoint) v8::MicrotasksScope::PerformCheckpoint(isolate); diff --git a/shell/common/gin_helper/microtasks_scope.h b/shell/common/gin_helper/microtasks_scope.h index 55772dea44b7..55487a649879 100644 --- a/shell/common/gin_helper/microtasks_scope.h +++ b/shell/common/gin_helper/microtasks_scope.h @@ -16,8 +16,7 @@ namespace gin_helper { // In the render process creates a v8::MicrotasksScope. class MicrotasksScope { public: - MicrotasksScope(v8::Isolate* isolate, - v8::MicrotaskQueue* microtask_queue, + MicrotasksScope(v8::Local context, bool ignore_browser_checkpoint, v8::MicrotasksScope::Type scope_type); ~MicrotasksScope(); diff --git a/shell/common/gin_helper/promise.cc b/shell/common/gin_helper/promise.cc index 17da3f4bb3e1..531dede1fa6a 100644 --- a/shell/common/gin_helper/promise.cc +++ b/shell/common/gin_helper/promise.cc @@ -17,8 +17,7 @@ namespace gin_helper { PromiseBase::SettleScope::SettleScope(const PromiseBase& base) : handle_scope_{base.isolate()}, context_{base.GetContext()}, - microtasks_scope_{base.isolate(), context_->GetMicrotaskQueue(), false, - v8::MicrotasksScope::kRunMicrotasks}, + microtasks_scope_{context_, false, v8::MicrotasksScope::kRunMicrotasks}, context_scope_{context_} {} PromiseBase::SettleScope::~SettleScope() = default; diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index bde4c3ca5d1d..8c682aba1c1e 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -288,8 +288,7 @@ void ErrorMessageListener(v8::Local message, node::Environment* env = node::Environment::GetCurrent(isolate); if (env) { gin_helper::MicrotasksScope microtasks_scope( - isolate, env->context()->GetMicrotaskQueue(), false, - v8::MicrotasksScope::kDoNotRunMicrotasks); + env->context(), false, v8::MicrotasksScope::kDoNotRunMicrotasks); // Emit the after() hooks now that the exception has been handled. // Analogous to node/lib/internal/process/execution.js#L176-L180 if (env->async_hooks()->fields()[node::AsyncHooks::kAfter]) { diff --git a/shell/common/v8_util.cc b/shell/common/v8_util.cc index 463ef545ed7d..85ed35cf1ae1 100644 --- a/shell/common/v8_util.cc +++ b/shell/common/v8_util.cc @@ -36,7 +36,7 @@ class V8Serializer : public v8::ValueSerializer::Delegate { bool Serialize(v8::Local value, blink::CloneableMessage* out) { gin_helper::MicrotasksScope microtasks_scope{ - isolate_, isolate_->GetCurrentContext()->GetMicrotaskQueue(), false, + isolate_->GetCurrentContext(), false, v8::MicrotasksScope::kDoNotRunMicrotasks}; WriteBlinkEnvelope(19); diff --git a/shell/renderer/api/electron_api_spell_check_client.cc b/shell/renderer/api/electron_api_spell_check_client.cc index 95e05ecccb52..6626d8b2ce49 100644 --- a/shell/renderer/api/electron_api_spell_check_client.cc +++ b/shell/renderer/api/electron_api_spell_check_client.cc @@ -217,8 +217,7 @@ void SpellCheckClient::SpellCheckWords(const SpellCheckScope& scope, auto context = isolate_->GetCurrentContext(); gin_helper::MicrotasksScope microtasks_scope{ - isolate_, context->GetMicrotaskQueue(), false, - v8::MicrotasksScope::kDoNotRunMicrotasks}; + context, false, v8::MicrotasksScope::kDoNotRunMicrotasks}; v8::Local templ = gin_helper::CreateFunctionTemplate( isolate_, base::BindRepeating(&SpellCheckClient::OnSpellCheckDone, diff --git a/shell/renderer/electron_render_frame_observer.cc b/shell/renderer/electron_render_frame_observer.cc index 23b2b6698f19..bf0045ae2d9e 100644 --- a/shell/renderer/electron_render_frame_observer.cc +++ b/shell/renderer/electron_render_frame_observer.cc @@ -81,8 +81,7 @@ void ElectronRenderFrameObserver::DidClearWindowObject() { v8::HandleScope handle_scope{isolate}; v8::Local context = web_frame->MainWorldScriptContext(); v8::MicrotasksScope microtasks_scope( - isolate, context->GetMicrotaskQueue(), - v8::MicrotasksScope::kDoNotRunMicrotasks); + context, v8::MicrotasksScope::kDoNotRunMicrotasks); v8::Context::Scope context_scope(context); // DidClearWindowObject only emits for the main world. DidInstallConditionalFeatures(context, MAIN_WORLD_ID); @@ -123,10 +122,8 @@ void ElectronRenderFrameObserver::DidInstallConditionalFeatures( } has_delayed_node_initialization_ = false; - auto* isolate = context->GetIsolate(); v8::MicrotasksScope microtasks_scope( - isolate, context->GetMicrotaskQueue(), - v8::MicrotasksScope::kDoNotRunMicrotasks); + context, v8::MicrotasksScope::kDoNotRunMicrotasks); if (ShouldNotifyClient(world_id)) renderer_client_->DidCreateScriptContext(context, render_frame_); diff --git a/shell/renderer/electron_sandboxed_renderer_client.cc b/shell/renderer/electron_sandboxed_renderer_client.cc index 398e86141751..48aa42f6cd74 100644 --- a/shell/renderer/electron_sandboxed_renderer_client.cc +++ b/shell/renderer/electron_sandboxed_renderer_client.cc @@ -149,8 +149,7 @@ void ElectronSandboxedRendererClient::WillReleaseScriptContext( auto* isolate = context->GetIsolate(); gin_helper::MicrotasksScope microtasks_scope{ - isolate, context->GetMicrotaskQueue(), false, - v8::MicrotasksScope::kDoNotRunMicrotasks}; + context, false, v8::MicrotasksScope::kDoNotRunMicrotasks}; v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(context); InvokeEmitProcessEvent(context, "exit"); @@ -168,8 +167,7 @@ void ElectronSandboxedRendererClient::EmitProcessEvent( v8::Local context = GetContext(frame, isolate); gin_helper::MicrotasksScope microtasks_scope{ - isolate, context->GetMicrotaskQueue(), false, - v8::MicrotasksScope::kDoNotRunMicrotasks}; + context, false, v8::MicrotasksScope::kDoNotRunMicrotasks}; v8::Context::Scope context_scope(context); InvokeEmitProcessEvent(context, event_name); diff --git a/shell/renderer/web_worker_observer.cc b/shell/renderer/web_worker_observer.cc index 295ec163a2e6..3520c6db0015 100644 --- a/shell/renderer/web_worker_observer.cc +++ b/shell/renderer/web_worker_observer.cc @@ -49,8 +49,7 @@ void WebWorkerObserver::WorkerScriptReadyForEvaluation( v8::Context::Scope context_scope(worker_context); auto* isolate = worker_context->GetIsolate(); v8::MicrotasksScope microtasks_scope( - isolate, worker_context->GetMicrotaskQueue(), - v8::MicrotasksScope::kDoNotRunMicrotasks); + worker_context, v8::MicrotasksScope::kDoNotRunMicrotasks); // Start the embed thread. node_bindings_->PrepareEmbedThread();