From 809cf595ebce1b9dbb07ba055fbf44957de1e617 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 16 Apr 2019 13:18:45 +0200 Subject: [PATCH] src: add `Environment` overload of `EmitAsyncDestroy` This can be necessary for being able to call the function when no JS Context is on the stack, e.g. during GC. Refs: https://github.com/nodejs/node/issues/27218 PR-URL: https://github.com/nodejs/node/pull/27255 Fixes: https://github.com/nodejs/node/issues/27218 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Michael Dawson --- src/api/hooks.cc | 7 +++++-- src/node.h | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/api/hooks.cc b/src/api/hooks.cc index 3b1ee90a99ae1d..cec58cee00847c 100644 --- a/src/api/hooks.cc +++ b/src/api/hooks.cc @@ -130,8 +130,11 @@ async_context EmitAsyncInit(Isolate* isolate, } void EmitAsyncDestroy(Isolate* isolate, async_context asyncContext) { - AsyncWrap::EmitDestroy( - Environment::GetCurrent(isolate), asyncContext.async_id); + EmitAsyncDestroy(Environment::GetCurrent(isolate), asyncContext); +} + +void EmitAsyncDestroy(Environment* env, async_context asyncContext) { + AsyncWrap::EmitDestroy(env, asyncContext.async_id); } } // namespace node diff --git a/src/node.h b/src/node.h index cbf9b938f1ed9e..fadfd8b7866b49 100644 --- a/src/node.h +++ b/src/node.h @@ -685,9 +685,16 @@ NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate, v8::Local name, async_id trigger_async_id = -1); -/* Emit the destroy() callback. */ +/* Emit the destroy() callback. The overload taking an `Environment*` argument + * should be used when the Isolate’s current Context is not associated with + * a Node.js Environment, or when there is no current Context, for example + * when calling this function during garbage collection. In that case, the + * `Environment*` value should have been acquired previously, e.g. through + * `GetCurrentEnvironment()`. */ NODE_EXTERN void EmitAsyncDestroy(v8::Isolate* isolate, async_context asyncContext); +NODE_EXTERN void EmitAsyncDestroy(Environment* env, + async_context asyncContext); class InternalCallbackScope;