Permalink
Browse files

Update setTimeout/setInterval to use a separate arguments array inste…

…ad of trying to directly modify the Arguments object.
  • Loading branch information...
1 parent a99bd71 commit 9b7483a4e85b272fef6446a03fd0effe7c63673b @csnover committed Jan 24, 2011
Showing with 11 additions and 7 deletions.
  1. +11 −7 tracekit.js
View
@@ -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);
}
@@ -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);
}
@@ -991,7 +995,7 @@ TraceKit.computeStackTrace = (function () {
}
};
- return _oldSetInterval.apply(this, arguments);
+ return _oldSetInterval.apply(this, args);
};
}(window));

0 comments on commit 9b7483a

Please sign in to comment.