Skip to content

Commit 3241546

Browse files
committed
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: #27218 PR-URL: #27255 Fixes: #27218 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 51079db commit 3241546

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/api/hooks.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ async_context EmitAsyncInit(Isolate* isolate,
130130
}
131131

132132
void EmitAsyncDestroy(Isolate* isolate, async_context asyncContext) {
133-
AsyncWrap::EmitDestroy(
134-
Environment::GetCurrent(isolate), asyncContext.async_id);
133+
EmitAsyncDestroy(Environment::GetCurrent(isolate), asyncContext);
134+
}
135+
136+
void EmitAsyncDestroy(Environment* env, async_context asyncContext) {
137+
AsyncWrap::EmitDestroy(env, asyncContext.async_id);
135138
}
136139

137140
} // namespace node

src/node.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,16 @@ NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate,
685685
v8::Local<v8::String> name,
686686
async_id trigger_async_id = -1);
687687

688-
/* Emit the destroy() callback. */
688+
/* Emit the destroy() callback. The overload taking an `Environment*` argument
689+
* should be used when the Isolate’s current Context is not associated with
690+
* a Node.js Environment, or when there is no current Context, for example
691+
* when calling this function during garbage collection. In that case, the
692+
* `Environment*` value should have been acquired previously, e.g. through
693+
* `GetCurrentEnvironment()`. */
689694
NODE_EXTERN void EmitAsyncDestroy(v8::Isolate* isolate,
690695
async_context asyncContext);
696+
NODE_EXTERN void EmitAsyncDestroy(Environment* env,
697+
async_context asyncContext);
691698

692699
class InternalCallbackScope;
693700

0 commit comments

Comments
 (0)