diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2011-11-12 13:31:26 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2011-11-12 13:31:28 +0100 |
commit | 098fef674038dcc42ae991205fdc6e5d649c2b6a (patch) | |
tree | a8fc5b5fd7a434e8d4b14fc5d7851e766cc71ec0 /lib | |
parent | 8082858ee7a2c3ac9c0f7415c51a463783e912cd (diff) | |
download | node-new-098fef674038dcc42ae991205fdc6e5d649c2b6a.tar.gz |
timers: remember extra setTimeout() arguments when timeout==0
Fixes #2079.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/timers.js | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/lib/timers.js b/lib/timers.js index 59b016ef3b..39eb4d9161 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -144,19 +144,23 @@ exports.active = function(item) { exports.setTimeout = function(callback, after) { - var timer, c, args; + var timer; if (after <= 0) { // Use the slow case for after == 0 timer = new Timer(); - timer.ontimeout = callback; - args = Array.prototype.slice.call(arguments, 2); - timer._onTimeout = function() { - callback.apply(timer, args); - timer.close(); + if (arguments.length <= 2) { + timer._onTimeout = callback; + } else { + var args = Array.prototype.slice.call(arguments, 2); + timer._onTimeout = function() { + callback.apply(timer, args); + timer.close(); + } } + timer.ontimeout = timer._onTimeout; timer.start(0, 0); } else { timer = { _idleTimeout: after }; @@ -166,16 +170,7 @@ exports.setTimeout = function(callback, after) { if (arguments.length <= 2) { timer._onTimeout = callback; } else { - /* - * Sometimes setTimeout is called with arguments, EG - * - * setTimeout(callback, 2000, "hello", "world") - * - * If that's the case we need to call the callback with - * those args. The overhead of an extra closure is not - * desired in the normal case. - */ - args = Array.prototype.slice.call(arguments, 2); + var args = Array.prototype.slice.call(arguments, 2); timer._onTimeout = function() { callback.apply(timer, args); } |