diff --git a/lib/timers.js b/lib/timers.js index d9692479a91..fc5d07dbc7c 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -26,6 +26,9 @@ var assert = require('assert').ok; // Timeout values > TIMEOUT_MAX are set to 1. var TIMEOUT_MAX = 2147483647; // 2^31-1 +//Hold reference to the global date so if stubbed the times still work +var Date = this.Date; + var debug; if (process.env.NODE_DEBUG && /timer/.test(process.env.NODE_DEBUG)) { debug = function() { require('util').error.apply(this, arguments); }; diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js index 2c45bf05ef7..4b7e57a0dbc 100644 --- a/test/pummel/test-timers.js +++ b/test/pummel/test-timers.js @@ -44,6 +44,15 @@ setTimeout(function() { setTimeout_called = true; }, 1000); +assert.doesNotThrow(function() { + var copy = Date; + Date = 'Not a Date'; + interval_count = 0; + setInterval(function() { clearInterval(this); }, 100); + setTimeout(function() { return true; }, 100); + Date = copy; +}, TypeError); + // this timer shouldn't execute var id = setTimeout(function() { assert.equal(true, false); }, 500); clearTimeout(id);