Skip to content

Commit a25ceef

Browse files
rickyestargos
authored andcommitted
async_hooks: use hasHooks function internally
PR-URL: #32656 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6d47958 commit a25ceef

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/internal/async_hooks.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -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+
319323
function enabledHooksExist() {
320-
return async_hook_fields[kCheck] > 0;
324+
return hasHooks(kCheck);
321325
}
322326

323327
function initHooksExist() {
324-
return async_hook_fields[kInit] > 0;
328+
return hasHooks(kInit);
325329
}
326330

327331
function afterHooksExist() {
328-
return async_hook_fields[kAfter] > 0;
332+
return hasHooks(kAfter);
329333
}
330334

331335
function destroyHooksExist() {
332-
return async_hook_fields[kDestroy] > 0;
336+
return hasHooks(kDestroy);
333337
}
334338

335339

336340
function 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) {
350354
function 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

358362
function 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

366370
function 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

384388
function hasAsyncIdStack() {
385-
return async_hook_fields[kStackLength] > 0;
389+
return hasHooks(kStackLength);
386390
}
387391

388392

0 commit comments

Comments
 (0)