Skip to content

Commit 1527825

Browse files
authored
lib: remove redundant destroyHook checks
PR-URL: #60120 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]>
1 parent 0fb0406 commit 1527825

File tree

5 files changed

+8
-19
lines changed

5 files changed

+8
-19
lines changed

lib/internal/async_hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ function emitAfterScript(asyncId) {
532532

533533
function emitDestroyScript(asyncId) {
534534
// Return early if there are no destroy callbacks, or invalid asyncId.
535-
if (!hasHooks(kDestroy) || asyncId <= 0)
535+
if (!hasHooks(kDestroy) || !(asyncId > 0))
536536
return;
537537
async_wrap.queueDestroyAsyncId(asyncId);
538538
}

lib/internal/process/task_queues.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const {
2727
getDefaultTriggerAsyncId,
2828
newAsyncId,
2929
initHooksExist,
30-
destroyHooksExist,
3130
emitInit,
3231
emitBefore,
3332
emitAfter,
@@ -94,8 +93,7 @@ function processTicksAndRejections() {
9493
}
9594
}
9695
} finally {
97-
if (destroyHooksExist())
98-
emitDestroy(asyncId);
96+
emitDestroy(asyncId);
9997
}
10098

10199
emitAfter(asyncId);

lib/internal/timers.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ const {
9292
getDefaultTriggerAsyncId,
9393
newAsyncId,
9494
initHooksExist,
95-
destroyHooksExist,
9695
// The needed emit*() functions.
9796
emitInit,
9897
emitBefore,
@@ -508,8 +507,7 @@ function getTimerCallbacks(runNextTicks) {
508507
} finally {
509508
immediate._onImmediate = null;
510509

511-
if (destroyHooksExist())
512-
emitDestroy(asyncId);
510+
emitDestroy(asyncId);
513511

514512
outstandingQueue.head = immediate = immediate._idleNext;
515513
}
@@ -585,8 +583,7 @@ function getTimerCallbacks(runNextTicks) {
585583
if (timer[kRefed])
586584
timeoutInfo[0]--;
587585

588-
if (destroyHooksExist())
589-
emitDestroy(asyncId);
586+
emitDestroy(asyncId);
590587
}
591588
continue;
592589
}
@@ -621,8 +618,7 @@ function getTimerCallbacks(runNextTicks) {
621618
if (timer[kRefed])
622619
timeoutInfo[0]--;
623620

624-
if (destroyHooksExist())
625-
emitDestroy(asyncId);
621+
emitDestroy(asyncId);
626622
}
627623
}
628624

lib/timers.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ let timersPromises;
6363
let timers;
6464

6565
const {
66-
destroyHooksExist,
6766
// The needed emit*() functions.
6867
emitDestroy,
6968
} = require('internal/async_hooks');
@@ -78,9 +77,7 @@ function unenroll(item) {
7877
if (item[kHasPrimitive])
7978
delete knownTimersById[item[async_id_symbol]];
8079

81-
// Fewer checks may be possible, but these cover everything.
82-
if (destroyHooksExist() && item[async_id_symbol] !== undefined)
83-
emitDestroy(item[async_id_symbol]);
80+
emitDestroy(item[async_id_symbol]);
8481

8582
L.remove(item);
8683

@@ -239,9 +236,7 @@ function clearImmediate(immediate) {
239236
}
240237
immediate[kRefed] = null;
241238

242-
if (destroyHooksExist() && immediate[async_id_symbol] !== undefined) {
243-
emitDestroy(immediate[async_id_symbol]);
244-
}
239+
emitDestroy(immediate[async_id_symbol]);
245240

246241
immediate._onImmediate = null;
247242

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Error: test
22
at one (*fixtures*async-error.js:4:9)
33
at two (*fixtures*async-error.js:17:9)
4-
at process.processTicksAndRejections (node:internal*process*task_queues:105:5)
4+
at process.processTicksAndRejections (node:internal*process*task_queues:103:5)
55
at async three (*fixtures*async-error.js:20:3)
66
at async four (*fixtures*async-error.js:24:3)
77
at async main (*async_error_nexttick_main.js:7:5)

0 commit comments

Comments
 (0)