summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-04-16 13:18:45 +0200
committerMichaël Zasso <targos@protonmail.com>2019-04-27 11:36:03 +0200
commit809cf595ebce1b9dbb07ba055fbf44957de1e617 (patch)
treea99c19a80f2fae241c7be8ac076cc974f7a7b48c
parent7bc47cba2e69a5c5b97a096306d41150665428e5 (diff)
downloadnode-new-809cf595ebce1b9dbb07ba055fbf44957de1e617.tar.gz
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 <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
-rw-r--r--src/api/hooks.cc7
-rw-r--r--src/node.h9
2 files changed, 13 insertions, 3 deletions
diff --git a/src/api/hooks.cc b/src/api/hooks.cc
index 3b1ee90a99..cec58cee00 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 cbf9b938f1..fadfd8b786 100644
--- a/src/node.h
+++ b/src/node.h
@@ -685,9 +685,16 @@ NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate,
v8::Local<v8::String> 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;