@@ -316,27 +316,31 @@ function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) {
316316 }
317317}
318318
319+ function hasHooks ( key ) {
320+ return async_hook_fields [ key ] > 0 ;
321+ }
322+
319323function enabledHooksExist ( ) {
320- return async_hook_fields [ kCheck ] > 0 ;
324+ return hasHooks ( kCheck ) ;
321325}
322326
323327function initHooksExist ( ) {
324- return async_hook_fields [ kInit ] > 0 ;
328+ return hasHooks ( kInit ) ;
325329}
326330
327331function afterHooksExist ( ) {
328- return async_hook_fields [ kAfter ] > 0 ;
332+ return hasHooks ( kAfter ) ;
329333}
330334
331335function destroyHooksExist ( ) {
332- return async_hook_fields [ kDestroy ] > 0 ;
336+ return hasHooks ( kDestroy ) ;
333337}
334338
335339
336340function emitInitScript ( asyncId , type , triggerAsyncId , resource ) {
337341 // Short circuit all checks for the common case. Which is that no hooks have
338342 // been set. Do this to remove performance impact for embedders (and core).
339- if ( async_hook_fields [ kInit ] === 0 )
343+ if ( ! hasHooks ( kInit ) )
340344 return ;
341345
342346 if ( triggerAsyncId === null ) {
@@ -350,13 +354,13 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
350354function emitBeforeScript ( asyncId , triggerAsyncId , resource ) {
351355 pushAsyncContext ( asyncId , triggerAsyncId , resource ) ;
352356
353- if ( async_hook_fields [ kBefore ] > 0 )
357+ if ( hasHooks ( kBefore ) )
354358 emitBeforeNative ( asyncId ) ;
355359}
356360
357361
358362function emitAfterScript ( asyncId ) {
359- if ( async_hook_fields [ kAfter ] > 0 )
363+ if ( hasHooks ( kAfter ) )
360364 emitAfterNative ( asyncId ) ;
361365
362366 popAsyncContext ( asyncId ) ;
@@ -365,7 +369,7 @@ function emitAfterScript(asyncId) {
365369
366370function emitDestroyScript ( asyncId ) {
367371 // 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 )
369373 return ;
370374 async_wrap . queueDestroyAsyncId ( asyncId ) ;
371375}
@@ -382,7 +386,7 @@ function clearAsyncIdStack() {
382386
383387
384388function hasAsyncIdStack ( ) {
385- return async_hook_fields [ kStackLength ] > 0 ;
389+ return hasHooks ( kStackLength ) ;
386390}
387391
388392
0 commit comments