@@ -189,7 +189,7 @@ function lookupPublicResource(resource) {
189
189
// Used by C++ to call all init() callbacks. Because some state can be setup
190
190
// from C++ there's no need to perform all the same operations as in
191
191
// emitInitScript.
192
- function emitInitNative ( asyncId , type , triggerAsyncId , resource ) {
192
+ function emitInitNative ( asyncId , type , triggerAsyncId , resource , isPromiseHook ) {
193
193
active_hooks . call_depth += 1 ;
194
194
resource = lookupPublicResource ( resource ) ;
195
195
// Use a single try/catch for all hooks to avoid setting up one per iteration.
@@ -199,6 +199,10 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) {
199
199
// eslint-disable-next-line no-var
200
200
for ( var i = 0 ; i < active_hooks . array . length ; i ++ ) {
201
201
if ( typeof active_hooks . array [ i ] [ init_symbol ] === 'function' ) {
202
+ if ( isPromiseHook &&
203
+ active_hooks . array [ i ] [ kNoPromiseHook ] ) {
204
+ continue ;
205
+ }
202
206
active_hooks . array [ i ] [ init_symbol ] (
203
207
asyncId , type , triggerAsyncId ,
204
208
resource ,
@@ -222,7 +226,7 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) {
222
226
223
227
// Called from native. The asyncId stack handling is taken care of there
224
228
// before this is called.
225
- function emitHook ( symbol , asyncId ) {
229
+ function emitHook ( symbol , asyncId , isPromiseHook ) {
226
230
active_hooks . call_depth += 1 ;
227
231
// Use a single try/catch for all hook to avoid setting up one per
228
232
// iteration.
@@ -232,6 +236,10 @@ function emitHook(symbol, asyncId) {
232
236
// eslint-disable-next-line no-var
233
237
for ( var i = 0 ; i < active_hooks . array . length ; i ++ ) {
234
238
if ( typeof active_hooks . array [ i ] [ symbol ] === 'function' ) {
239
+ if ( isPromiseHook &&
240
+ active_hooks . array [ i ] [ kNoPromiseHook ] ) {
241
+ continue ;
242
+ }
235
243
active_hooks . array [ i ] [ symbol ] ( asyncId ) ;
236
244
}
237
245
}
@@ -321,7 +329,7 @@ function promiseInitHook(promise, parent) {
321
329
trackPromise ( promise , parent ) ;
322
330
const asyncId = promise [ async_id_symbol ] ;
323
331
const triggerAsyncId = promise [ trigger_async_id_symbol ] ;
324
- emitInitScript ( asyncId , 'PROMISE' , triggerAsyncId , promise ) ;
332
+ emitInitScript ( asyncId , 'PROMISE' , triggerAsyncId , promise , true ) ;
325
333
}
326
334
327
335
function promiseInitHookWithDestroyTracking ( promise , parent ) {
@@ -339,14 +347,14 @@ function promiseBeforeHook(promise) {
339
347
trackPromise ( promise ) ;
340
348
const asyncId = promise [ async_id_symbol ] ;
341
349
const triggerId = promise [ trigger_async_id_symbol ] ;
342
- emitBeforeScript ( asyncId , triggerId , promise ) ;
350
+ emitBeforeScript ( asyncId , triggerId , promise , true ) ;
343
351
}
344
352
345
353
function promiseAfterHook ( promise ) {
346
354
trackPromise ( promise ) ;
347
355
const asyncId = promise [ async_id_symbol ] ;
348
356
if ( hasHooks ( kAfter ) ) {
349
- emitAfterNative ( asyncId ) ;
357
+ emitAfterNative ( asyncId , true ) ;
350
358
}
351
359
if ( asyncId === executionAsyncId ( ) ) {
352
360
// This condition might not be true if async_hooks was enabled during
@@ -361,7 +369,7 @@ function promiseAfterHook(promise) {
361
369
function promiseResolveHook ( promise ) {
362
370
trackPromise ( promise ) ;
363
371
const asyncId = promise [ async_id_symbol ] ;
364
- emitPromiseResolveNative ( asyncId ) ;
372
+ emitPromiseResolveNative ( asyncId , true ) ;
365
373
}
366
374
367
375
let wantPromiseHook = false ;
@@ -492,7 +500,7 @@ function promiseResolveHooksExist() {
492
500
}
493
501
494
502
495
- function emitInitScript ( asyncId , type , triggerAsyncId , resource ) {
503
+ function emitInitScript ( asyncId , type , triggerAsyncId , resource , isPromiseHook = false ) {
496
504
// Short circuit all checks for the common case. Which is that no hooks have
497
505
// been set. Do this to remove performance impact for embedders (and core).
498
506
if ( ! hasHooks ( kInit ) )
@@ -502,15 +510,15 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
502
510
triggerAsyncId = getDefaultTriggerAsyncId ( ) ;
503
511
}
504
512
505
- emitInitNative ( asyncId , type , triggerAsyncId , resource ) ;
513
+ emitInitNative ( asyncId , type , triggerAsyncId , resource , isPromiseHook ) ;
506
514
}
507
515
508
516
509
- function emitBeforeScript ( asyncId , triggerAsyncId , resource ) {
517
+ function emitBeforeScript ( asyncId , triggerAsyncId , resource , isPromiseHook = false ) {
510
518
pushAsyncContext ( asyncId , triggerAsyncId , resource ) ;
511
519
512
520
if ( hasHooks ( kBefore ) )
513
- emitBeforeNative ( asyncId ) ;
521
+ emitBeforeNative ( asyncId , isPromiseHook ) ;
514
522
}
515
523
516
524
0 commit comments