Skip to content

Commit a2bed79

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: nodejs#26555 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent b21e7c7 commit a2bed79

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

lib/internal/timers.js

Lines changed: 2 additions & 23 deletions
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;

lib/timers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function listOnTimeout(list, now) {
331331

332332
try {
333333
const args = timer._timerArgs;
334-
if (!args)
334+
if (args === undefined)
335335
timer._onTimeout();
336336
else
337337
Reflect.apply(timer._onTimeout, timer, args);
@@ -470,8 +470,9 @@ function setTimeout(callback, after, arg1, arg2, arg3) {
470470
}
471471

472472
setTimeout[internalUtil.promisify.custom] = function(after, value) {
473+
const args = value !== undefined ? [value] : value;
473474
return new Promise((resolve) => {
474-
active(new Timeout(resolve, after, [value], false));
475+
active(new Timeout(resolve, after, args, false));
475476
});
476477
};
477478

0 commit comments

Comments
 (0)