GeezerVison is showing github.com — timers: remove dead code and simplify args check · nodejs/node@143dbb3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/timers.js +2-23Lines changed: 2 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -102,34 +102,13 @@ Timeout.prototype.refresh = function() { | 102 | 102 | return this; | 103 | 103 | }; | 104 | 104 |
| 105 | | -function setUnrefTimeout(callback, after, arg1, arg2, arg3) { | | 105 | +function setUnrefTimeout(callback, after) { | 106 | 106 | // Type checking identical to setTimeout() | 107 | 107 | if (typeof callback !== 'function') { | 108 | 108 | throw new ERR_INVALID_CALLBACK(); | 109 | 109 | } | 110 | 110 |
| 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); | 133 | 112 | getTimers()._unrefActive(timer); | 134 | 113 |
| 135 | 114 | return timer; | |
Collapse file Copy file name to clipboardExpand all lines: lib/timers.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -323,7 +323,7 @@ function listOnTimeout(list, now) { | 323 | 323 |
| 324 | 324 | try { | 325 | 325 | const args = timer._timerArgs; | 326 | | - if (!args) | | 326 | + if (args === undefined) | 327 | 327 | timer._onTimeout(); | 328 | 328 | else | 329 | 329 | Reflect.apply(timer._onTimeout, timer, args); | @@ -462,8 +462,9 @@ function setTimeout(callback, after, arg1, arg2, arg3) { | 462 | 462 | } | 463 | 463 |
| 464 | 464 | setTimeout[internalUtil.promisify.custom] = function(after, value) { | | 465 | + const args = value !== undefined ? [value] : value; | 465 | 466 | return new Promise((resolve) => { | 466 | | - active(new Timeout(resolve, after, [value], false)); | | 467 | + active(new Timeout(resolve, after, args, false)); | 467 | 468 | }); | 468 | 469 | }; | 469 | 470 |
| |
|