Skip to content

Commit e7595f5

Browse files
committed
Avoid recursion when using the console plugin
Fixes #320 #364 #369
1 parent 5cececa commit e7595f5

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

plugins/console.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ var logForGivenLevel = function(level) {
2525
if (originalConsoleLevel) {
2626
// IE9 doesn't allow calling apply on console functions directly
2727
// See: https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function#answer-5473193
28-
Function.prototype.bind
29-
.call(originalConsoleLevel, originalConsole)
30-
.apply(originalConsole, args);
28+
Function.prototype.bind
29+
.call(originalConsoleLevel, originalConsole)
30+
.apply(originalConsole, args);
3131
}
3232
};
3333
};

src/raven.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ var _Raven = window.Raven,
2525
},
2626
authQueryString,
2727
isRavenInstalled = false,
28-
2928
objectPrototype = Object.prototype,
29+
// capture a reference to window.console first before
30+
// the console plugin has a chance to monkey patch
31+
originalConsole = window.console || {},
3032
startTime = now();
3133

3234
/*
@@ -850,10 +852,10 @@ function uuid4() {
850852
}
851853

852854
function logDebug(level) {
853-
if (window.console && console[level] && Raven.debug) {
855+
if (originalConsole[level] && Raven.debug) {
854856
// _slice is coming from vendor/TraceKit/tracekit.js
855857
// so it's accessible globally
856-
console[level].apply(console, _slice.call(arguments, 1));
858+
originalConsole[level].apply(originalConsole, _slice.call(arguments, 1));
857859
}
858860
}
859861

test/raven.test.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function flushRavenState() {
2121
},
2222
startTime = 0;
2323
ravenNotConfiguredError = undefined;
24+
originalConsole = window.console || {};
2425

2526
Raven.uninstall();
2627
}
@@ -325,21 +326,21 @@ describe('globals', function() {
325326

326327
it('should not write to console when Raven.debug is false', function() {
327328
Raven.debug = false;
328-
this.sinon.stub(console, level);
329+
this.sinon.stub(originalConsole, level);
329330
logDebug(level, message);
330-
assert.isFalse(console[level].called);
331+
assert.isFalse(originalConsole[level].called);
331332
});
332333

333334
it('should write to console when Raven.debug is true', function() {
334335
Raven.debug = true;
335-
this.sinon.stub(console, level);
336+
this.sinon.stub(originalConsole, level);
336337
logDebug(level, message);
337-
assert.isTrue(console[level].calledOnce);
338+
assert.isTrue(originalConsole[level].calledOnce);
338339
});
339340

340341
it('should handle variadic arguments', function() {
341342
Raven.debug = true;
342-
this.sinon.stub(console, level);
343+
this.sinon.stub(originalConsole, level);
343344
logDebug(level, message, {}, 'foo');
344345
});
345346
});

0 commit comments

Comments
 (0)