diff options
author | rickyes <mail@zhoumq.cn> | 2020-04-04 14:40:36 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-04-07 21:27:45 +0300 |
commit | 1c816f0c591cd0242930e8605c5473416cc94241 (patch) | |
tree | ce54853fcb625d1d10e71b14a7f587acc036bf18 /lib/internal/async_hooks.js | |
parent | 6ed912dd0319475d2c4ebd9991af52420de17fe8 (diff) |
async_hooks: use hasHooks function internally
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib/internal/async_hooks.js')
-rw-r--r-- | lib/internal/async_hooks.js | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index f7a7f7aad66..8439260f1af 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -316,27 +316,31 @@ function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) { } } +function hasHooks(key) { + return async_hook_fields[key] > 0; +} + function enabledHooksExist() { - return async_hook_fields[kCheck] > 0; + return hasHooks(kCheck); } function initHooksExist() { - return async_hook_fields[kInit] > 0; + return hasHooks(kInit); } function afterHooksExist() { - return async_hook_fields[kAfter] > 0; + return hasHooks(kAfter); } function destroyHooksExist() { - return async_hook_fields[kDestroy] > 0; + return hasHooks(kDestroy); } function emitInitScript(asyncId, type, triggerAsyncId, resource) { // Short circuit all checks for the common case. Which is that no hooks have // been set. Do this to remove performance impact for embedders (and core). - if (async_hook_fields[kInit] === 0) + if (!hasHooks(kInit)) return; if (triggerAsyncId === null) { @@ -350,13 +354,13 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) { function emitBeforeScript(asyncId, triggerAsyncId, resource) { pushAsyncContext(asyncId, triggerAsyncId, resource); - if (async_hook_fields[kBefore] > 0) + if (hasHooks(kBefore)) emitBeforeNative(asyncId); } function emitAfterScript(asyncId) { - if (async_hook_fields[kAfter] > 0) + if (hasHooks(kAfter)) emitAfterNative(asyncId); popAsyncContext(asyncId); @@ -365,7 +369,7 @@ function emitAfterScript(asyncId) { function emitDestroyScript(asyncId) { // Return early if there are no destroy callbacks, or invalid asyncId. - if (async_hook_fields[kDestroy] === 0 || asyncId <= 0) + if (!hasHooks(kDestroy) || asyncId <= 0) return; async_wrap.queueDestroyAsyncId(asyncId); } @@ -382,7 +386,7 @@ function clearAsyncIdStack() { function hasAsyncIdStack() { - return async_hook_fields[kStackLength] > 0; + return hasHooks(kStackLength); } |