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(napi): Don't run microtasks in napi_resolve_deferred #25246

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions cli/napi/js_native_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3307,19 +3307,30 @@ fn napi_resolve_deferred(
check_arg!(env, result);
check_arg!(env, deferred);

// Make sure microtasks don't run and call back into JS
env
.scope()
.set_microtasks_policy(v8::MicrotasksPolicy::Explicit);

littledivy marked this conversation as resolved.
Show resolved Hide resolved
let deferred_ptr =
unsafe { NonNull::new_unchecked(deferred as *mut v8::PromiseResolver) };
let global = unsafe { v8::Global::from_raw(env.isolate(), deferred_ptr) };
let resolver = v8::Local::new(&mut env.scope(), global);

if !resolver
let success = resolver
.resolve(&mut env.scope(), result.unwrap())
.unwrap_or(false)
{
return napi_generic_failure;
}
.unwrap_or(false);

napi_ok
// Restore policy
env
.scope()
.set_microtasks_policy(v8::MicrotasksPolicy::Auto);

if success {
napi_ok
} else {
napi_generic_failure
}
}

#[napi_sym]
Expand Down