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) {
196
196
return env->execution_async_id ();
197
197
}
198
198
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
+
199
205
async_id AsyncHooksGetTriggerAsyncId (Isolate* isolate) {
200
206
Environment* env = Environment::GetCurrent (isolate);
201
207
if (env == nullptr ) return -1 ;
Original file line number Diff line number Diff line change @@ -1404,6 +1404,12 @@ NODE_EXTERN void RequestInterrupt(Environment* env,
1404
1404
* I/O from native code. */
1405
1405
NODE_EXTERN async_id AsyncHooksGetExecutionAsyncId (v8::Isolate* isolate);
1406
1406
1407
+ /* Returns the id of the current execution context. If the return value is
1408
+ * zero then no execution has been set. This will happen if the user handles
1409
+ * I/O from native code. */
1410
+ NODE_EXTERN async_id
1411
+ AsyncHooksGetExecutionAsyncId (v8::Local<v8::Context> context);
1412
+
1407
1413
/* Return same value as async_hooks.triggerAsyncId(); */
1408
1414
NODE_EXTERN async_id AsyncHooksGetTriggerAsyncId (v8::Isolate* isolate);
1409
1415
Original file line number Diff line number Diff line change @@ -12,13 +12,21 @@ void GetExecutionAsyncId(const FunctionCallbackInfo<Value>& args) {
12
12
node::AsyncHooksGetExecutionAsyncId (args.GetIsolate ()));
13
13
}
14
14
15
+ void GetExecutionAsyncIdWithContext (const FunctionCallbackInfo<Value>& args) {
16
+ args.GetReturnValue ().Set (node::AsyncHooksGetExecutionAsyncId (
17
+ args.GetIsolate ()->GetCurrentContext ()));
18
+ }
19
+
15
20
void GetTriggerAsyncId (const FunctionCallbackInfo<Value>& args) {
16
21
args.GetReturnValue ().Set (
17
22
node::AsyncHooksGetTriggerAsyncId (args.GetIsolate ()));
18
23
}
19
24
20
25
void Initialize (Local<Object> exports) {
21
26
NODE_SET_METHOD (exports, " getExecutionAsyncId" , GetExecutionAsyncId);
27
+ NODE_SET_METHOD (exports,
28
+ " getExecutionAsyncIdWithContext" ,
29
+ GetExecutionAsyncIdWithContext);
22
30
NODE_SET_METHOD (exports, " getTriggerAsyncId" , GetTriggerAsyncId);
23
31
}
24
32
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ assert.strictEqual(
9
9
binding . getExecutionAsyncId ( ) ,
10
10
async_hooks . executionAsyncId ( ) ,
11
11
) ;
12
+ assert . strictEqual (
13
+ binding . getExecutionAsyncIdWithContext ( ) ,
14
+ async_hooks . executionAsyncId ( ) ,
15
+ ) ;
12
16
assert . strictEqual (
13
17
binding . getTriggerAsyncId ( ) ,
14
18
async_hooks . triggerAsyncId ( ) ,
@@ -19,6 +23,10 @@ process.nextTick(common.mustCall(() => {
19
23
binding . getExecutionAsyncId ( ) ,
20
24
async_hooks . executionAsyncId ( ) ,
21
25
) ;
26
+ assert . strictEqual (
27
+ binding . getExecutionAsyncIdWithContext ( ) ,
28
+ async_hooks . executionAsyncId ( ) ,
29
+ ) ;
22
30
assert . strictEqual (
23
31
binding . getTriggerAsyncId ( ) ,
24
32
async_hooks . triggerAsyncId ( ) ,
You can’t perform that action at this time.
0 commit comments