Skip to content

Commit 2c5b014

Browse files
rickyestargos
authored andcommittedApr 22, 2020
async_hooks: use hasHooks function internally
PR-URL: #32656 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2cf7381 commit 2c5b014

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
@@ -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+
302306
function enabledHooksExist() {
303-
return async_hook_fields[kCheck] > 0;
307+
return hasHooks(kCheck);
304308
}
305309

306310
function initHooksExist() {
307-
return async_hook_fields[kInit] > 0;
311+
return hasHooks(kInit);
308312
}
309313

310314
function afterHooksExist() {
311-
return async_hook_fields[kAfter] > 0;
315+
return hasHooks(kAfter);
312316
}
313317

314318
function destroyHooksExist() {
315-
return async_hook_fields[kDestroy] > 0;
319+
return hasHooks(kDestroy);
316320
}
317321

318322

319323
function 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) {
333337
function 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

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

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

366370
function hasAsyncIdStack() {
367-
return async_hook_fields[kStackLength] > 0;
371+
return hasHooks(kStackLength);
368372
}
369373

370374

0 commit comments

Comments
 (0)
Please sign in to comment.