Skip to content

Commit 0fef905

Browse files
committed
When uninstalling Raven, also drop the window.onerror handler from
TraceKit
1 parent acf1047 commit 0fef905

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/raven.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ var Raven = {
211211
* @return {Raven}
212212
*/
213213
uninstall: function() {
214-
TraceKit.report.unsubscribe(handleStackInfo);
214+
TraceKit.report.uninstall();
215215

216216
return Raven;
217217
},

test/raven.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,11 +1151,10 @@ describe('Raven (public API)', function() {
11511151
});
11521152

11531153
describe('.uninstall', function() {
1154-
it('should unsubscribe from TraceKit', function() {
1155-
this.sinon.stub(TraceKit.report, 'unsubscribe');
1154+
it('should uninstall from TraceKit', function() {
1155+
this.sinon.stub(TraceKit.report, 'uninstall');
11561156
Raven.uninstall();
1157-
assert.isTrue(TraceKit.report.unsubscribe.calledOnce);
1158-
assert.equal(TraceKit.report.unsubscribe.lastCall.args[0], handleStackInfo);
1157+
assert.isTrue(TraceKit.report.uninstall.calledOnce);
11591158
});
11601159
});
11611160

vendor/TraceKit/tracekit.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ TraceKit.report = (function reportModuleWrapper() {
9999
}
100100
}
101101

102+
/**
103+
* Remove all crash handlers.
104+
*/
105+
function unsubscribeAll() {
106+
uninstallGlobalHandler();
107+
handlers = [];
108+
}
109+
102110
/**
103111
* Dispatch stack information to all handlers.
104112
* @param {Object.<string, *>} stack
@@ -180,14 +188,24 @@ TraceKit.report = (function reportModuleWrapper() {
180188

181189
function installGlobalHandler ()
182190
{
183-
if (_onErrorHandlerInstalled === true) {
191+
if (_onErrorHandlerInstalled) {
184192
return;
185193
}
186194
_oldOnerrorHandler = window.onerror;
187195
window.onerror = traceKitWindowOnError;
188196
_onErrorHandlerInstalled = true;
189197
}
190198

199+
function uninstallGlobalHandler ()
200+
{
201+
if (!_onErrorHandlerInstalled) {
202+
return;
203+
}
204+
window.onerror = _oldOnerrorHandler;
205+
_onErrorHandlerInstalled = false;
206+
_oldOnerrorHandler = undefined;
207+
}
208+
191209
/**
192210
* Reports an unhandled Error to TraceKit.
193211
* @param {Error} ex
@@ -231,6 +249,7 @@ TraceKit.report = (function reportModuleWrapper() {
231249

232250
report.subscribe = subscribe;
233251
report.unsubscribe = unsubscribe;
252+
report.uninstall = unsubscribeAll;
234253
return report;
235254
}());
236255

0 commit comments

Comments
 (0)