Skip to content
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

fix: allow Node.js to manage microtasks queue #28974

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions shell/common/node_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,13 @@ void NodeBindings::UvRunOnce() {
// Enter node context while dealing with uv events.
v8::Context::Scope context_scope(env->context());

// Perform microtask checkpoint after running JavaScript.
gin_helper::MicrotasksScope microtasks_scope(env->isolate());
// Node.js expects `kExplicit` microtasks policy and will run microtasks
// checkpoints after every call into JavaScript. Since we use a different
// policy in the renderer - switch to `kExplicit` and then drop back to the
// previous policy value.
auto old_policy = env->isolate()->GetMicrotasksPolicy();
DCHECK_EQ(v8::MicrotasksScope::GetCurrentDepth(env->isolate()), 0);
env->isolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit);

if (browser_env_ != BrowserEnvironment::BROWSER)
TRACE_EVENT_BEGIN0("devtools.timeline", "FunctionCall");
Expand All @@ -592,6 +597,8 @@ void NodeBindings::UvRunOnce() {
if (browser_env_ != BrowserEnvironment::BROWSER)
TRACE_EVENT_END0("devtools.timeline", "FunctionCall");

env->isolate()->SetMicrotasksPolicy(old_policy);

if (r == 0)
base::RunLoop().QuitWhenIdle(); // Quit from uv.

Expand Down