Skip to content

Commit 3645898

Browse files
committed
fix(napi): enter the env's context around async-work completion
CompleteAsyncWork called into the module with only the loop entry's Locker + Isolate::Scope + HandleScope, leaving the current context empty — addon complete callbacks (and the exception reporter on the napi_throw_error failure path) observed no entered context. Open a HandleScope + Context::Scope first, mirroring NapiEnv::CallFinalizer and the TSFN dispatch path. Same fix as NativeScript/android#2004. Fixes #441
1 parent 9fb910c commit 3645898

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎NativeScript/napi/NodeApiEmbed.mm‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ void CompleteAsyncWork(napi_async_work work, napi_status status) {
525525
}
526526

527527
void* data = work->data;
528+
// Node runs `complete` with the env's context entered; the loop entry only
529+
// supplies Locker + Isolate::Scope + HandleScope.
530+
v8::HandleScope handle_scope(env->isolate);
531+
v8::Context::Scope context_scope(env->context());
528532
env->CallIntoModule(
529533
[&](napi_env moduleEnv) { complete(moduleEnv, status, data); },
530534
[](napi_env moduleEnv, v8::Local<v8::Value> exception) {

0 commit comments

Comments
 (0)