async_hooks: rename internal emit functions
There are two categories of emit functions in async_hooks, those used by c++ (native) and those used by JavaScript (script). Previously these were named N for native and S for script. Finally, there was an odd case where emitInitN was called just init. This makes it more explicit by using the names emitInitNative and emitInitScript. The other emit functions are also renamed. PR-URL: https://github.com/nodejs/node/pull/14152 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
f94fd0c0f3
commit
628485ea01
@ -57,7 +57,7 @@ const emitDestroyNative = emitHookFactory(destroy_symbol, 'emitDestroyNative');
|
|||||||
// process. They use the same functions as the JS embedder API. These callbacks
|
// process. They use the same functions as the JS embedder API. These callbacks
|
||||||
// are setup immediately to prevent async_wrap.setupHooks() from being hijacked
|
// are setup immediately to prevent async_wrap.setupHooks() from being hijacked
|
||||||
// and the cost of doing so is negligible.
|
// and the cost of doing so is negligible.
|
||||||
async_wrap.setupHooks({ init,
|
async_wrap.setupHooks({ init: emitInitNative,
|
||||||
before: emitBeforeNative,
|
before: emitBeforeNative,
|
||||||
after: emitAfterNative,
|
after: emitAfterNative,
|
||||||
destroy: emitDestroyNative });
|
destroy: emitDestroyNative });
|
||||||
@ -228,21 +228,21 @@ class AsyncResource {
|
|||||||
if (async_hook_fields[kInit] === 0)
|
if (async_hook_fields[kInit] === 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
init(this[async_id_symbol], type, triggerAsyncId, this);
|
emitInitNative(this[async_id_symbol], type, triggerAsyncId, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
emitBefore() {
|
emitBefore() {
|
||||||
emitBeforeS(this[async_id_symbol], this[trigger_id_symbol]);
|
emitBeforeScript(this[async_id_symbol], this[trigger_id_symbol]);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
emitAfter() {
|
emitAfter() {
|
||||||
emitAfterS(this[async_id_symbol]);
|
emitAfterScript(this[async_id_symbol]);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
emitDestroy() {
|
emitDestroy() {
|
||||||
emitDestroyS(this[async_id_symbol]);
|
emitDestroyScript(this[async_id_symbol]);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ function setInitTriggerId(triggerAsyncId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function emitInitS(asyncId, type, triggerAsyncId, resource) {
|
function emitInitScript(asyncId, type, triggerAsyncId, resource) {
|
||||||
// Short circuit all checks for the common case. Which is that no hooks have
|
// 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).
|
// been set. Do this to remove performance impact for embedders (and core).
|
||||||
// Even though it bypasses all the argument checks. The performance savings
|
// Even though it bypasses all the argument checks. The performance savings
|
||||||
@ -334,7 +334,7 @@ function emitInitS(asyncId, type, triggerAsyncId, resource) {
|
|||||||
if (!Number.isSafeInteger(triggerAsyncId) || triggerAsyncId < 0)
|
if (!Number.isSafeInteger(triggerAsyncId) || triggerAsyncId < 0)
|
||||||
throw new RangeError('triggerAsyncId must be an unsigned integer');
|
throw new RangeError('triggerAsyncId must be an unsigned integer');
|
||||||
|
|
||||||
init(asyncId, type, triggerAsyncId, resource);
|
emitInitNative(asyncId, type, triggerAsyncId, resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitHookFactory(symbol, name) {
|
function emitHookFactory(symbol, name) {
|
||||||
@ -370,9 +370,7 @@ function emitHookFactory(symbol, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Usage: emitBeforeS(asyncId[, triggerAsyncId]). If triggerAsyncId is omitted
|
function emitBeforeScript(asyncId, triggerAsyncId) {
|
||||||
// then asyncId will be used instead.
|
|
||||||
function emitBeforeS(asyncId, triggerAsyncId) {
|
|
||||||
// CHECK(Number.isSafeInteger(asyncId) && asyncId > 0)
|
// CHECK(Number.isSafeInteger(asyncId) && asyncId > 0)
|
||||||
// CHECK(Number.isSafeInteger(triggerAsyncId) && triggerAsyncId > 0)
|
// CHECK(Number.isSafeInteger(triggerAsyncId) && triggerAsyncId > 0)
|
||||||
|
|
||||||
@ -392,7 +390,7 @@ function emitBeforeS(asyncId, triggerAsyncId) {
|
|||||||
// TODO(trevnorris): Calling emitBefore/emitAfter from native can't adjust the
|
// TODO(trevnorris): Calling emitBefore/emitAfter from native can't adjust the
|
||||||
// kIdStackIndex. But what happens if the user doesn't have both before and
|
// kIdStackIndex. But what happens if the user doesn't have both before and
|
||||||
// after callbacks.
|
// after callbacks.
|
||||||
function emitAfterS(asyncId) {
|
function emitAfterScript(asyncId) {
|
||||||
if (async_hook_fields[kAfter] > 0)
|
if (async_hook_fields[kAfter] > 0)
|
||||||
emitAfterNative(asyncId);
|
emitAfterNative(asyncId);
|
||||||
|
|
||||||
@ -400,7 +398,7 @@ function emitAfterS(asyncId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function emitDestroyS(asyncId) {
|
function emitDestroyScript(asyncId) {
|
||||||
// Return early if there are no destroy callbacks, or on attempt to emit
|
// Return early if there are no destroy callbacks, or on attempt to emit
|
||||||
// destroy on the void.
|
// destroy on the void.
|
||||||
if (async_hook_fields[kDestroy] === 0 || asyncId === 0)
|
if (async_hook_fields[kDestroy] === 0 || asyncId === 0)
|
||||||
@ -422,7 +420,7 @@ function emitDestroyS(asyncId) {
|
|||||||
// change in the future depending on whether it can be determined if there's a
|
// change in the future depending on whether it can be determined if there's a
|
||||||
// slim chance of the application remaining stable after handling one of these
|
// slim chance of the application remaining stable after handling one of these
|
||||||
// exceptions.
|
// exceptions.
|
||||||
function init(asyncId, type, triggerAsyncId, resource) {
|
function emitInitNative(asyncId, type, triggerAsyncId, resource) {
|
||||||
processing_hook += 1;
|
processing_hook += 1;
|
||||||
// Use a single try/catch for all hook to avoid setting up one per iteration.
|
// Use a single try/catch for all hook to avoid setting up one per iteration.
|
||||||
try {
|
try {
|
||||||
@ -467,10 +465,10 @@ module.exports = {
|
|||||||
newUid,
|
newUid,
|
||||||
initTriggerId,
|
initTriggerId,
|
||||||
setInitTriggerId,
|
setInitTriggerId,
|
||||||
emitInit: emitInitS,
|
emitInit: emitInitScript,
|
||||||
emitBefore: emitBeforeS,
|
emitBefore: emitBeforeScript,
|
||||||
emitAfter: emitAfterS,
|
emitAfter: emitAfterScript,
|
||||||
emitDestroy: emitDestroyS,
|
emitDestroy: emitDestroyScript,
|
||||||
};
|
};
|
||||||
|
|
||||||
// currentId was renamed to executionAsyncId. This was in 8.2.0 during the
|
// currentId was renamed to executionAsyncId. This was in 8.2.0 during the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user