diff --git a/lib/timers.js b/lib/timers.js index b835ba5864..cb049b0333 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -209,9 +209,11 @@ exports.setTimeout = function (callback, after) { exports.clearTimeout = function (timer) { - timer.callback = timer._onTimeout = null; - exports.unenroll(timer); - if (timer instanceof Timer) timer.stop(); // for after === 0 + if (timer) { + timer.callback = timer._onTimeout = null; + exports.unenroll(timer); + if (timer instanceof Timer) timer.stop(); // for after === 0 + } }; diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js index 8b3c39efdd..5841444172 100644 --- a/test/pummel/test-timers.js +++ b/test/pummel/test-timers.js @@ -8,6 +8,10 @@ var WINDOW = 200; // why is does this need to be so big? var interval_count = 0; var setTimeout_called = false; +// check that these don't blow up. +clearTimeout(null); +clearInterval(null); + assert.equal(true, setTimeout instanceof Function); var starttime = new Date; setTimeout(function () {