Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
lib: remove redundant destroyHook checks
  • Loading branch information
gurgunday committed Oct 4, 2025
commit 7723487edb9540b8e7444492820408840267c037
2 changes: 1 addition & 1 deletion lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ function emitAfterScript(asyncId) {

function emitDestroyScript(asyncId) {
// Return early if there are no destroy callbacks, or invalid asyncId.
if (!hasHooks(kDestroy) || asyncId <= 0)
if (!hasHooks(kDestroy) || !(asyncId > 0))
return;
async_wrap.queueDestroyAsyncId(asyncId);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/process/task_queues.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
getDefaultTriggerAsyncId,
newAsyncId,
initHooksExist,
destroyHooksExist,

Check failure on line 30 in lib/internal/process/task_queues.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'destroyHooksExist' is assigned a value but never used
emitInit,
emitBefore,
emitAfter,
Expand Down Expand Up @@ -94,8 +94,7 @@
}
}
} finally {
if (destroyHooksExist())
emitDestroy(asyncId);
emitDestroy(asyncId);
}

emitAfter(asyncId);
Expand Down
10 changes: 3 additions & 7 deletions lib/internal/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const {
getDefaultTriggerAsyncId,
newAsyncId,
initHooksExist,
destroyHooksExist,
// The needed emit*() functions.
emitInit,
emitBefore,
Expand Down Expand Up @@ -508,8 +507,7 @@ function getTimerCallbacks(runNextTicks) {
} finally {
immediate._onImmediate = null;

if (destroyHooksExist())
emitDestroy(asyncId);
emitDestroy(asyncId);

outstandingQueue.head = immediate = immediate._idleNext;
}
Expand Down Expand Up @@ -585,8 +583,7 @@ function getTimerCallbacks(runNextTicks) {
if (timer[kRefed])
timeoutInfo[0]--;

if (destroyHooksExist())
emitDestroy(asyncId);
emitDestroy(asyncId);
}
continue;
}
Expand Down Expand Up @@ -621,8 +618,7 @@ function getTimerCallbacks(runNextTicks) {
if (timer[kRefed])
timeoutInfo[0]--;

if (destroyHooksExist())
emitDestroy(asyncId);
emitDestroy(asyncId);
}
}

Expand Down
9 changes: 2 additions & 7 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ let timersPromises;
let timers;

const {
destroyHooksExist,
// The needed emit*() functions.
emitDestroy,
} = require('internal/async_hooks');
Expand All @@ -78,9 +77,7 @@ function unenroll(item) {
if (item[kHasPrimitive])
delete knownTimersById[item[async_id_symbol]];

// Fewer checks may be possible, but these cover everything.
if (destroyHooksExist() && item[async_id_symbol] !== undefined)
emitDestroy(item[async_id_symbol]);
emitDestroy(item[async_id_symbol]);

L.remove(item);

Expand Down Expand Up @@ -239,9 +236,7 @@ function clearImmediate(immediate) {
}
immediate[kRefed] = null;

if (destroyHooksExist() && immediate[async_id_symbol] !== undefined) {
emitDestroy(immediate[async_id_symbol]);
}
emitDestroy(immediate[async_id_symbol]);

immediate._onImmediate = null;

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/errors/async_error_nexttick_main.snapshot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Error: test
at one (*fixtures*async-error.js:4:9)
at two (*fixtures*async-error.js:17:9)
at process.processTicksAndRejections (node:internal*process*task_queues:105:5)
at process.processTicksAndRejections (node:internal*process*task_queues:104:5)
at async three (*fixtures*async-error.js:20:3)
at async four (*fixtures*async-error.js:24:3)
at async main (*async_error_nexttick_main.js:7:5)
Loading