@@ -316,27 +316,31 @@ function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) {
316
316
}
317
317
}
318
318
319
+ function hasHooks ( key ) {
320
+ return async_hook_fields [ key ] > 0 ;
321
+ }
322
+
319
323
function enabledHooksExist ( ) {
320
- return async_hook_fields [ kCheck ] > 0 ;
324
+ return hasHooks ( kCheck ) ;
321
325
}
322
326
323
327
function initHooksExist ( ) {
324
- return async_hook_fields [ kInit ] > 0 ;
328
+ return hasHooks ( kInit ) ;
325
329
}
326
330
327
331
function afterHooksExist ( ) {
328
- return async_hook_fields [ kAfter ] > 0 ;
332
+ return hasHooks ( kAfter ) ;
329
333
}
330
334
331
335
function destroyHooksExist ( ) {
332
- return async_hook_fields [ kDestroy ] > 0 ;
336
+ return hasHooks ( kDestroy ) ;
333
337
}
334
338
335
339
336
340
function emitInitScript ( asyncId , type , triggerAsyncId , resource ) {
337
341
// Short circuit all checks for the common case. Which is that no hooks have
338
342
// been set. Do this to remove performance impact for embedders (and core).
339
- if ( async_hook_fields [ kInit ] === 0 )
343
+ if ( ! hasHooks ( kInit ) )
340
344
return ;
341
345
342
346
if ( triggerAsyncId === null ) {
@@ -350,13 +354,13 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
350
354
function emitBeforeScript ( asyncId , triggerAsyncId , resource ) {
351
355
pushAsyncContext ( asyncId , triggerAsyncId , resource ) ;
352
356
353
- if ( async_hook_fields [ kBefore ] > 0 )
357
+ if ( hasHooks ( kBefore ) )
354
358
emitBeforeNative ( asyncId ) ;
355
359
}
356
360
357
361
358
362
function emitAfterScript ( asyncId ) {
359
- if ( async_hook_fields [ kAfter ] > 0 )
363
+ if ( hasHooks ( kAfter ) )
360
364
emitAfterNative ( asyncId ) ;
361
365
362
366
popAsyncContext ( asyncId ) ;
@@ -365,7 +369,7 @@ function emitAfterScript(asyncId) {
365
369
366
370
function emitDestroyScript ( asyncId ) {
367
371
// Return early if there are no destroy callbacks, or invalid asyncId.
368
- if ( async_hook_fields [ kDestroy ] === 0 || asyncId <= 0 )
372
+ if ( ! hasHooks ( kDestroy ) || asyncId <= 0 )
369
373
return ;
370
374
async_wrap . queueDestroyAsyncId ( asyncId ) ;
371
375
}
@@ -382,7 +386,7 @@ function clearAsyncIdStack() {
382
386
383
387
384
388
function hasAsyncIdStack ( ) {
385
- return async_hook_fields [ kStackLength ] > 0 ;
389
+ return hasHooks ( kStackLength ) ;
386
390
}
387
391
388
392
0 commit comments