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 <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent bc09d2f commit 143dbb3

2 files changed

Lines changed: 5 additions & 25 deletions

File tree

‎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
returnthis;
103103
};
104104

105-
functionsetUnrefTimeout(callback,after,arg1,arg2,arg3){
105+
functionsetUnrefTimeout(callback,after){
106106
// Type checking identical to setTimeout()
107107
if(typeofcallback!=='function'){
108108
thrownewERR_INVALID_CALLBACK();
109109
}
110110

111-
leti,args;
112-
switch(arguments.length){
113-
// fast cases
114-
case1:
115-
case2:
116-
break;
117-
case3:
118-
args=[arg1];
119-
break;
120-
case4:
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-
consttimer=newTimeout(callback,after,args,false);
111+
consttimer=newTimeout(callback,after,undefined,false);
133112
getTimers()._unrefActive(timer);
134113

135114
returntimer;

‎lib/timers.js‎

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

324324
try{
325325
constargs=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+
constargs=value!==undefined ? [value] : value;
465466
returnnewPromise((resolve)=>{
466-
active(newTimeout(resolve,after,[value],false));
467+
active(newTimeout(resolve,after,args,false));
467468
});
468469
};
469470

0 commit comments

Comments
 (0)