Skip to content

Commit 143dbb3

Browse files
committed
timers: remove dead code and simplify args check
The `setUnrefTimeout` function is never called with more arguments than two. So quite some code was dead and never used. This removes that code and simplifies the args check not to coerce objects to booleans. PR-URL: #26555 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent bc09d2f commit 143dbb3

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

Diff for: lib/internal/timers.js

+2-23
Original file line numberDiff line numberDiff line change
@@ -102,34 +102,13 @@ Timeout.prototype.refresh = function() {
102102
return this;
103103
};
104104

105-
function setUnrefTimeout(callback, after, arg1, arg2, arg3) {
105+
function setUnrefTimeout(callback, after) {
106106
// Type checking identical to setTimeout()
107107
if (typeof callback !== 'function') {
108108
throw new ERR_INVALID_CALLBACK();
109109
}
110110

111-
let i, args;
112-
switch (arguments.length) {
113-
// fast cases
114-
case 1:
115-
case 2:
116-
break;
117-
case 3:
118-
args = [arg1];
119-
break;
120-
case 4:
121-
args = [arg1, arg2];
122-
break;
123-
default:
124-
args = [arg1, arg2, arg3];
125-
for (i = 5; i < arguments.length; i++) {
126-
// Extend array dynamically, makes .apply run much faster in v6.0.0
127-
args[i - 2] = arguments[i];
128-
}
129-
break;
130-
}
131-
132-
const timer = new Timeout(callback, after, args, false);
111+
const timer = new Timeout(callback, after, undefined, false);
133112
getTimers()._unrefActive(timer);
134113

135114
return timer;

Diff for: lib/timers.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function listOnTimeout(list, now) {
323323

324324
try {
325325
const args = timer._timerArgs;
326-
if (!args)
326+
if (args === undefined)
327327
timer._onTimeout();
328328
else
329329
Reflect.apply(timer._onTimeout, timer, args);
@@ -462,8 +462,9 @@ function setTimeout(callback, after, arg1, arg2, arg3) {
462462
}
463463

464464
setTimeout[internalUtil.promisify.custom] = function(after, value) {
465+
const args = value !== undefined ? [value] : value;
465466
return new Promise((resolve) => {
466-
active(new Timeout(resolve, after, [value], false));
467+
active(new Timeout(resolve, after, args, false));
467468
});
468469
};
469470

0 commit comments

Comments
 (0)