mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
async_hooks: make AsyncResource match emitInit
AsyncResource previously called emitInitNative. Since AsyncResource is just an abstraction on top of the emitEventScript functions, it should call emitInitScript instead. 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
628485ea01
commit
31417b6882
3 changed files with 18 additions and 21 deletions
|
@ -207,28 +207,16 @@ function triggerAsyncId() {
|
|||
// Embedder API //
|
||||
|
||||
class AsyncResource {
|
||||
constructor(type, triggerAsyncId) {
|
||||
this[async_id_symbol] = ++async_uid_fields[kAsyncUidCntr];
|
||||
// Read and reset the current kInitTriggerId so that when the constructor
|
||||
// finishes the kInitTriggerId field is always 0.
|
||||
if (triggerAsyncId === undefined) {
|
||||
triggerAsyncId = initTriggerId();
|
||||
// If a triggerAsyncId was passed, any kInitTriggerId still must be null'd.
|
||||
} else {
|
||||
async_uid_fields[kInitTriggerId] = 0;
|
||||
}
|
||||
this[trigger_id_symbol] = triggerAsyncId;
|
||||
|
||||
if (typeof type !== 'string' || type.length <= 0)
|
||||
throw new TypeError('type must be a string with length > 0');
|
||||
constructor(type, triggerAsyncId = initTriggerId()) {
|
||||
// Unlike emitInitScript, AsyncResource doesn't supports null as the
|
||||
// triggerAsyncId.
|
||||
if (!Number.isSafeInteger(triggerAsyncId) || triggerAsyncId < 0)
|
||||
throw new RangeError('triggerAsyncId must be an unsigned integer');
|
||||
|
||||
// Return immediately if there's nothing to do.
|
||||
if (async_hook_fields[kInit] === 0)
|
||||
return;
|
||||
this[async_id_symbol] = ++async_uid_fields[kAsyncUidCntr];
|
||||
this[trigger_id_symbol] = triggerAsyncId;
|
||||
|
||||
emitInitNative(this[async_id_symbol], type, triggerAsyncId, this);
|
||||
emitInitScript(this[async_id_symbol], type, this[trigger_id_symbol], this);
|
||||
}
|
||||
|
||||
emitBefore() {
|
||||
|
@ -323,6 +311,9 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
|
|||
// manually means that the embedder must have used initTriggerId().
|
||||
if (triggerAsyncId === null) {
|
||||
triggerAsyncId = initTriggerId();
|
||||
} else {
|
||||
// If a triggerAsyncId was passed, any kInitTriggerId still must be null'd.
|
||||
async_uid_fields[kInitTriggerId] = 0;
|
||||
}
|
||||
|
||||
// TODO(trevnorris): I'd prefer allowing these checks to not exist, or only
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue