diff --git a/lib/timers.js b/lib/timers.js index 9e2336d058ba..6d6066a01f07 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -170,8 +170,9 @@ exports.active = function(item) { exports.setTimeout = function(callback, after) { var timer; - after = ~~after; - if (after < 1 || after > TIMEOUT_MAX) { + after *= 1; // coalesce to number or NaN + + if (!(after >= 1 && after <= TIMEOUT_MAX)) { after = 1; // schedule on next tick, follows browser behaviour } @@ -222,8 +223,9 @@ exports.setInterval = function(callback, repeat) { if (process.domain) timer.domain = process.domain; - repeat = ~~repeat; - if (repeat < 1 || repeat > TIMEOUT_MAX) { + repeat *= 1; // coalesce to number or NaN + + if (!(repeat >= 1 && repeat <= TIMEOUT_MAX)) { repeat = 1; // schedule on next tick, follows browser behaviour } diff --git a/test/simple/test-timers.js b/test/simple/test-timers.js index 51e251e17383..98e6bc3def1d 100644 --- a/test/simple/test-timers.js +++ b/test/simple/test-timers.js @@ -45,7 +45,8 @@ var inputs = [ 1, 1.0, 10, - 2147483648 // browser behaviour: timeouts > 2^31-1 run on next tick + 2147483648, // browser behaviour: timeouts > 2^31-1 run on next tick + 12345678901234 // ditto ]; var timeouts = [];