Browse Source

Make sure setInterval(cb, 0) loops infinitely

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
7347fb3e2c
  1. 2
      src/node.js
  2. 7
      test/pummel/test-timers.js

2
src/node.js

@ -604,7 +604,7 @@ global.setTimeout = function (callback, after) {
global.setInterval = function (callback, repeat) {
var timer = new process.Timer();
addTimerListener.apply(timer, arguments);
timer.start(repeat, repeat);
timer.start(repeat, repeat ? repeat : 1);
return timer;
};

7
test/pummel/test-timers.js

@ -74,7 +74,14 @@ setInterval(function(param1, param2){
clearInterval(this);
}, 1000, "param1", "param2");
// setInterval(cb, 0) should be called multiple times.
count4 = 0;
interval4 = setInterval(function () {
if (++count4 > 10) clearInterval(interval4);
}, 0);
process.addListener("exit", function () {
assert.equal(true, setTimeout_called);
assert.equal(3, interval_count);
assert.equal(11, count4);
});

Loading…
Cancel
Save