Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@
},
"lint-staged": {
"src/**/*.js": [
"eslint",
"prettier --write",
"git add"
],
"test/**/*.js": [
"eslint",
"prettier --write",
"git add"
],
"plugins/**/*.js": [
"eslint",
"prettier --write",
"git add"
]
Expand Down
23 changes: 23 additions & 0 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ Raven.prototype = {
TraceKit.report.subscribe(function() {
self._handleOnErrorStackInfo.apply(self, arguments);
});

self._patchFunctionToString();

if (self._globalOptions.instrument && self._globalOptions.instrument.tryCatch) {
self._instrumentTryCatch();
}
Expand Down Expand Up @@ -378,6 +381,7 @@ Raven.prototype = {
uninstall: function() {
TraceKit.report.uninstall();

this._unpatchFunctionToString();
this._restoreBuiltIns();

Error.stackTraceLimit = this._originalErrorStackTraceLimit;
Expand Down Expand Up @@ -940,6 +944,25 @@ Raven.prototype = {
});
},

_patchFunctionToString: function() {
var self = this;
self._originalFunctionToString = Function.prototype.toString;
// eslint-disable-next-line no-extend-native
Function.prototype.toString = function() {
if (typeof this === 'function' && this.__raven__) {
return self._originalFunctionToString.apply(this.__orig_method__, arguments);
}
return self._originalFunctionToString.apply(this, arguments);
};
},

_unpatchFunctionToString: function() {
if (this._originalFunctionToString) {
// eslint-disable-next-line no-extend-native
Function.prototype.toString = this._originalFunctionToString;
}
},

/**
* Wrap timer functions and event targets to catch errors and provide
* better metadata.
Expand Down
2 changes: 2 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ function isSameStacktrace(stack1, stack2) {
function fill(obj, name, replacement, track) {
var orig = obj[name];
obj[name] = replacement(orig);
obj[name].__raven__ = true;
obj[name].__orig_method__ = orig;
if (track) {
track.push([obj, name, orig]);
}
Expand Down
40 changes: 40 additions & 0 deletions test/integration/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,46 @@ describe('integration', function() {
}
);
});

it('should preserve native code detection compatibility', function(done) {
var iframe = this.iframe;

iframeExecute(
iframe,
done,
function() {
done();
},
function() {
assert.include(
Function.prototype.toString.call(window.setTimeout),
'[native code]'
);
assert.include(
Function.prototype.toString.call(window.setInterval),
'[native code]'
);
assert.include(
Function.prototype.toString.call(window.addEventListener),
'[native code]'
);
assert.include(
Function.prototype.toString.call(window.removeEventListener),
'[native code]'
);
assert.include(
Function.prototype.toString.call(window.requestAnimationFrame),
'[native code]'
);
if ('fetch' in window) {
assert.include(
Function.prototype.toString.call(window.fetch),
'[native code]'
);
}
}
);
});
});

describe('uninstall', function() {
Expand Down