Skip to content

Commit

Permalink
Update setTimeout/setInterval to use a separate arguments array inste…
Browse files Browse the repository at this point in the history
…ad of trying to directly modify the Arguments object.
  • Loading branch information
csnover committed Jan 24, 2011
1 parent a99bd71 commit 9b7483a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tracekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,14 @@ TraceKit.computeStackTrace = (function () {
* functions.
*/
(function (w) {
var _oldSetTimeout = w.setTimeout;
var slice = Array.prototype.slice,
_oldSetTimeout = w.setTimeout;

w.setTimeout = function () {
var _oldCallback = arguments[0];
var args = slice.call(arguments, 0),
_oldCallback = args[0];

arguments[0] = function () {
args[0] = function () {
try {
_oldCallback.apply(this, arguments);
}
Expand All @@ -971,17 +974,18 @@ TraceKit.computeStackTrace = (function () {
}
};

return _oldSetTimeout.apply(this, arguments);
return _oldSetTimeout.apply(this, args);
};

// If you are reading this, you should know that setInterval is
// bad! Don’t use it!
// http://zetafleet.com/blog/why-i-consider-setinterval-harmful
var _oldSetInterval = w.setInterval;
w.setInterval = function () {
var _oldCallback = arguments[0];
var args = slice.call(arguments, 0),
_oldCallback = args[0];

arguments[0] = function () {
args[0] = function () {
try {
_oldCallback.apply(this, arguments);
}
Expand All @@ -991,7 +995,7 @@ TraceKit.computeStackTrace = (function () {
}
};

return _oldSetInterval.apply(this, arguments);
return _oldSetInterval.apply(this, args);
};
}(window));

Expand Down

0 comments on commit 9b7483a

Please sign in to comment.