File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -533,6 +533,7 @@ napi_status napi_add_async_cleanup_hook(
533
533
auto handle = node::AddEnvironmentCleanupHook (env->isolate , fun, arg);
534
534
if (remove_handle != nullptr ) {
535
535
*remove_handle = new napi_async_cleanup_hook_handle__ { std::move (handle) };
536
+ env->Ref ();
536
537
}
537
538
538
539
return napi_clear_last_error (env);
@@ -547,6 +548,11 @@ napi_status napi_remove_async_cleanup_hook(
547
548
node::RemoveEnvironmentCleanupHook (std::move (remove_handle->handle ));
548
549
delete remove_handle;
549
550
551
+ // Release the `env` handle asynchronously since it would be surprising if
552
+ // a call to a N-API function would destroy `env` synchronously.
553
+ static_cast <node_napi_env>(env)->node_env ()
554
+ ->SetImmediate ([env](node::Environment*) { env->Unref (); });
555
+
550
556
return napi_clear_last_error (env);
551
557
}
552
558
You can’t perform that action at this time.
0 commit comments