From a1043b2df2c76dcea9afd940a0b9c7943c8f0133 Mon Sep 17 00:00:00 2001 From: simonkcleung Date: Wed, 16 Jul 2014 22:00:03 +0800 Subject: [PATCH] Update timers.js #7931 callback should run as if `global.callback()` in setTimout/setInterval --- lib/timers.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/timers.js b/lib/timers.js index 3039b49f2c37..e25052ebb8b3 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -229,7 +229,7 @@ exports.setTimeout = function(callback, after) { timer = new Timeout(after); if (arguments.length <= 2) { - timer._onTimeout = callback; + timer._onTimeout = callback.bind(global); } else { /* * Sometimes setTimeout is called with arguments, EG @@ -241,9 +241,7 @@ exports.setTimeout = function(callback, after) { * desired in the normal case. */ var args = Array.prototype.slice.call(arguments, 2); - timer._onTimeout = function() { - callback.apply(timer, args); - } + timer._onTimeout = callback.bind(global, args); } if (process.domain) timer.domain = process.domain; @@ -284,7 +282,7 @@ exports.setInterval = function(callback, repeat) { return timer; function wrapper() { - callback.apply(this, args); + callback.apply(global, args); // If callback called clearInterval(). if (timer._repeat === false) return; // If timer is unref'd (or was - it's permanently removed from the list.)