@@ -299,27 +299,31 @@ function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) {
299299 }
300300}
301301
302+ function hasHooks ( key ) {
303+ return async_hook_fields [ key ] > 0 ;
304+ }
305+
302306function enabledHooksExist ( ) {
303- return async_hook_fields [ kCheck ] > 0 ;
307+ return hasHooks ( kCheck ) ;
304308}
305309
306310function initHooksExist ( ) {
307- return async_hook_fields [ kInit ] > 0 ;
311+ return hasHooks ( kInit ) ;
308312}
309313
310314function afterHooksExist ( ) {
311- return async_hook_fields [ kAfter ] > 0 ;
315+ return hasHooks ( kAfter ) ;
312316}
313317
314318function destroyHooksExist ( ) {
315- return async_hook_fields [ kDestroy ] > 0 ;
319+ return hasHooks ( kDestroy ) ;
316320}
317321
318322
319323function emitInitScript ( asyncId , type , triggerAsyncId , resource ) {
320324 // Short circuit all checks for the common case. Which is that no hooks have
321325 // been set. Do this to remove performance impact for embedders (and core).
322- if ( async_hook_fields [ kInit ] === 0 )
326+ if ( ! hasHooks ( kInit ) )
323327 return ;
324328
325329 if ( triggerAsyncId === null ) {
@@ -333,13 +337,13 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
333337function emitBeforeScript ( asyncId , triggerAsyncId ) {
334338 pushAsyncIds ( asyncId , triggerAsyncId ) ;
335339
336- if ( async_hook_fields [ kBefore ] > 0 )
340+ if ( hasHooks ( kBefore ) )
337341 emitBeforeNative ( asyncId ) ;
338342}
339343
340344
341345function emitAfterScript ( asyncId ) {
342- if ( async_hook_fields [ kAfter ] > 0 )
346+ if ( hasHooks ( kAfter ) )
343347 emitAfterNative ( asyncId ) ;
344348
345349 popAsyncIds ( asyncId ) ;
@@ -348,7 +352,7 @@ function emitAfterScript(asyncId) {
348352
349353function emitDestroyScript ( asyncId ) {
350354 // Return early if there are no destroy callbacks, or invalid asyncId.
351- if ( async_hook_fields [ kDestroy ] === 0 || asyncId <= 0 )
355+ if ( ! hasHooks ( kDestroy ) || asyncId <= 0 )
352356 return ;
353357 async_wrap . queueDestroyAsyncId ( asyncId ) ;
354358}
@@ -364,7 +368,7 @@ function clearAsyncIdStack() {
364368
365369
366370function hasAsyncIdStack ( ) {
367- return async_hook_fields [ kStackLength ] > 0 ;
371+ return hasHooks ( kStackLength ) ;
368372}
369373
370374
0 commit comments