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: https://github.com/nodejs/node/pull/26555 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
b21e7c7bcf
commit
a2bed79726
@ -102,34 +102,13 @@ Timeout.prototype.refresh = function() {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
function setUnrefTimeout(callback, after, arg1, arg2, arg3) {
|
function setUnrefTimeout(callback, after) {
|
||||||
// Type checking identical to setTimeout()
|
// Type checking identical to setTimeout()
|
||||||
if (typeof callback !== 'function') {
|
if (typeof callback !== 'function') {
|
||||||
throw new ERR_INVALID_CALLBACK();
|
throw new ERR_INVALID_CALLBACK();
|
||||||
}
|
}
|
||||||
|
|
||||||
let i, args;
|
const timer = new Timeout(callback, after, undefined, false);
|
||||||
switch (arguments.length) {
|
|
||||||
// fast cases
|
|
||||||
case 1:
|
|
||||||
case 2:
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
args = [arg1];
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
args = [arg1, arg2];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
args = [arg1, arg2, arg3];
|
|
||||||
for (i = 5; i < arguments.length; i++) {
|
|
||||||
// Extend array dynamically, makes .apply run much faster in v6.0.0
|
|
||||||
args[i - 2] = arguments[i];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timer = new Timeout(callback, after, args, false);
|
|
||||||
getTimers()._unrefActive(timer);
|
getTimers()._unrefActive(timer);
|
||||||
|
|
||||||
return timer;
|
return timer;
|
||||||
|
@ -331,7 +331,7 @@ function listOnTimeout(list, now) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const args = timer._timerArgs;
|
const args = timer._timerArgs;
|
||||||
if (!args)
|
if (args === undefined)
|
||||||
timer._onTimeout();
|
timer._onTimeout();
|
||||||
else
|
else
|
||||||
Reflect.apply(timer._onTimeout, timer, args);
|
Reflect.apply(timer._onTimeout, timer, args);
|
||||||
@ -470,8 +470,9 @@ function setTimeout(callback, after, arg1, arg2, arg3) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTimeout[internalUtil.promisify.custom] = function(after, value) {
|
setTimeout[internalUtil.promisify.custom] = function(after, value) {
|
||||||
|
const args = value !== undefined ? [value] : value;
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
active(new Timeout(resolve, after, [value], false));
|
active(new Timeout(resolve, after, args, false));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user