Skip to content

Commit

Permalink
src: add Environment overload of EmitAsyncDestroy
Browse files Browse the repository at this point in the history
This can be necessary for being able to call the function when no
JS Context is on the stack, e.g. during GC.

Refs: nodejs#27218
  • Loading branch information
addaleax committed Apr 16, 2019
1 parent f85ef97 commit 7947f48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/api/hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 7947f48

Please sign in to comment.