From 7347fb3e2c445222598646262cec262f9dacee91 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 31 Aug 2010 16:45:17 -0700 Subject: [PATCH] Make sure setInterval(cb, 0) loops infinitely --- src/node.js | 2 +- test/pummel/test-timers.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index f329c0055c..a4ec922adc 100644 --- a/src/node.js +++ b/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; }; diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js index d656f2bf95..8b3c39efdd 100644 --- a/test/pummel/test-timers.js +++ b/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); });