Skip to content

Commit 628485e

Browse files
committed
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: #14152 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent f94fd0c commit 628485e

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

lib/async_hooks.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const emitDestroyNative = emitHookFactory(destroy_symbol, 'emitDestroyNative');
5757
// process. They use the same functions as the JS embedder API. These callbacks
5858
// are setup immediately to prevent async_wrap.setupHooks() from being hijacked
5959
// and the cost of doing so is negligible.
60-
async_wrap.setupHooks({ init,
60+
async_wrap.setupHooks({ init: emitInitNative,
6161
before: emitBeforeNative,
6262
after: emitAfterNative,
6363
destroy: emitDestroyNative });
@@ -228,21 +228,21 @@ class AsyncResource {
228228
if (async_hook_fields[kInit] === 0)
229229
return;
230230

231-
init(this[async_id_symbol], type, triggerAsyncId, this);
231+
emitInitNative(this[async_id_symbol], type, triggerAsyncId, this);
232232
}
233233

234234
emitBefore() {
235-
emitBeforeS(this[async_id_symbol], this[trigger_id_symbol]);
235+
emitBeforeScript(this[async_id_symbol], this[trigger_id_symbol]);
236236
return this;
237237
}
238238

239239
emitAfter() {
240-
emitAfterS(this[async_id_symbol]);
240+
emitAfterScript(this[async_id_symbol]);
241241
return this;
242242
}
243243

244244
emitDestroy() {
245-
emitDestroyS(this[async_id_symbol]);
245+
emitDestroyScript(this[async_id_symbol]);
246246
return this;
247247
}
248248

@@ -311,7 +311,7 @@ function setInitTriggerId(triggerAsyncId) {
311311
}
312312

313313

314-
function emitInitS(asyncId, type, triggerAsyncId, resource) {
314+
function emitInitScript(asyncId, type, triggerAsyncId, resource) {
315315
// Short circuit all checks for the common case. Which is that no hooks have
316316
// been set. Do this to remove performance impact for embedders (and core).
317317
// Even though it bypasses all the argument checks. The performance savings
@@ -334,7 +334,7 @@ function emitInitS(asyncId, type, triggerAsyncId, resource) {
334334
if (!Number.isSafeInteger(triggerAsyncId) || triggerAsyncId < 0)
335335
throw new RangeError('triggerAsyncId must be an unsigned integer');
336336

337-
init(asyncId, type, triggerAsyncId, resource);
337+
emitInitNative(asyncId, type, triggerAsyncId, resource);
338338
}
339339

340340
function emitHookFactory(symbol, name) {
@@ -370,9 +370,7 @@ function emitHookFactory(symbol, name) {
370370
}
371371

372372

373-
// Usage: emitBeforeS(asyncId[, triggerAsyncId]). If triggerAsyncId is omitted
374-
// then asyncId will be used instead.
375-
function emitBeforeS(asyncId, triggerAsyncId) {
373+
function emitBeforeScript(asyncId, triggerAsyncId) {
376374
// CHECK(Number.isSafeInteger(asyncId) && asyncId > 0)
377375
// CHECK(Number.isSafeInteger(triggerAsyncId) && triggerAsyncId > 0)
378376

@@ -392,15 +390,15 @@ function emitBeforeS(asyncId, triggerAsyncId) {
392390
// TODO(trevnorris): Calling emitBefore/emitAfter from native can't adjust the
393391
// kIdStackIndex. But what happens if the user doesn't have both before and
394392
// after callbacks.
395-
function emitAfterS(asyncId) {
393+
function emitAfterScript(asyncId) {
396394
if (async_hook_fields[kAfter] > 0)
397395
emitAfterNative(asyncId);
398396

399397
popAsyncIds(asyncId);
400398
}
401399

402400

403-
function emitDestroyS(asyncId) {
401+
function emitDestroyScript(asyncId) {
404402
// Return early if there are no destroy callbacks, or on attempt to emit
405403
// destroy on the void.
406404
if (async_hook_fields[kDestroy] === 0 || asyncId === 0)
@@ -422,7 +420,7 @@ function emitDestroyS(asyncId) {
422420
// change in the future depending on whether it can be determined if there's a
423421
// slim chance of the application remaining stable after handling one of these
424422
// exceptions.
425-
function init(asyncId, type, triggerAsyncId, resource) {
423+
function emitInitNative(asyncId, type, triggerAsyncId, resource) {
426424
processing_hook += 1;
427425
// Use a single try/catch for all hook to avoid setting up one per iteration.
428426
try {
@@ -467,10 +465,10 @@ module.exports = {
467465
newUid,
468466
initTriggerId,
469467
setInitTriggerId,
470-
emitInit: emitInitS,
471-
emitBefore: emitBeforeS,
472-
emitAfter: emitAfterS,
473-
emitDestroy: emitDestroyS,
468+
emitInit: emitInitScript,
469+
emitBefore: emitBeforeScript,
470+
emitAfter: emitAfterScript,
471+
emitDestroy: emitDestroyScript,
474472
};
475473

476474
// currentId was renamed to executionAsyncId. This was in 8.2.0 during the

0 commit comments

Comments
 (0)