Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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.)
Expand Down