File tree Expand file tree Collapse file tree 4 files changed +28
-0
lines changed
test/addons/async-hooks-id Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,12 @@ async_id AsyncHooksGetExecutionAsyncId(Isolate* isolate) {
196196 return env->execution_async_id ();
197197}
198198
199+ async_id AsyncHooksGetExecutionAsyncId (Local<Context> context) {
200+ Environment* env = Environment::GetCurrent (context);
201+ if (env == nullptr ) return -1 ;
202+ return env->execution_async_id ();
203+ }
204+
199205async_id AsyncHooksGetTriggerAsyncId (Isolate* isolate) {
200206 Environment* env = Environment::GetCurrent (isolate);
201207 if (env == nullptr ) return -1 ;
Original file line number Diff line number Diff line change @@ -1387,6 +1387,12 @@ NODE_EXTERN void RequestInterrupt(Environment* env,
13871387 * I/O from native code. */
13881388NODE_EXTERN async_id AsyncHooksGetExecutionAsyncId (v8::Isolate* isolate);
13891389
1390+ /* Returns the id of the current execution context. If the return value is
1391+ * zero then no execution has been set. This will happen if the user handles
1392+ * I/O from native code. */
1393+ NODE_EXTERN async_id
1394+ AsyncHooksGetExecutionAsyncId (v8::Local<v8::Context> context);
1395+
13901396/* Return same value as async_hooks.triggerAsyncId(); */
13911397NODE_EXTERN async_id AsyncHooksGetTriggerAsyncId (v8::Isolate* isolate);
13921398
Original file line number Diff line number Diff line change @@ -12,13 +12,21 @@ void GetExecutionAsyncId(const FunctionCallbackInfo<Value>& args) {
1212 node::AsyncHooksGetExecutionAsyncId (args.GetIsolate ()));
1313}
1414
15+ void GetExecutionAsyncIdWithContext (const FunctionCallbackInfo<Value>& args) {
16+ args.GetReturnValue ().Set (node::AsyncHooksGetExecutionAsyncId (
17+ args.GetIsolate ()->GetCurrentContext ()));
18+ }
19+
1520void GetTriggerAsyncId (const FunctionCallbackInfo<Value>& args) {
1621 args.GetReturnValue ().Set (
1722 node::AsyncHooksGetTriggerAsyncId (args.GetIsolate ()));
1823}
1924
2025void Initialize (Local<Object> exports) {
2126 NODE_SET_METHOD (exports, " getExecutionAsyncId" , GetExecutionAsyncId);
27+ NODE_SET_METHOD (exports,
28+ " getExecutionAsyncIdWithContext" ,
29+ GetExecutionAsyncIdWithContext);
2230 NODE_SET_METHOD (exports, " getTriggerAsyncId" , GetTriggerAsyncId);
2331}
2432
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ assert.strictEqual(
99 binding . getExecutionAsyncId ( ) ,
1010 async_hooks . executionAsyncId ( ) ,
1111) ;
12+ assert . strictEqual (
13+ binding . getExecutionAsyncIdWithContext ( ) ,
14+ async_hooks . executionAsyncId ( ) ,
15+ ) ;
1216assert . strictEqual (
1317 binding . getTriggerAsyncId ( ) ,
1418 async_hooks . triggerAsyncId ( ) ,
@@ -19,6 +23,10 @@ process.nextTick(common.mustCall(() => {
1923 binding . getExecutionAsyncId ( ) ,
2024 async_hooks . executionAsyncId ( ) ,
2125 ) ;
26+ assert . strictEqual (
27+ binding . getExecutionAsyncIdWithContext ( ) ,
28+ async_hooks . executionAsyncId ( ) ,
29+ ) ;
2230 assert . strictEqual (
2331 binding . getTriggerAsyncId ( ) ,
2432 async_hooks . triggerAsyncId ( ) ,
You can’t perform that action at this time.
0 commit comments