Skip to content

Avoid recursion when using the console plugin #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2015
Merged
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
6 changes: 3 additions & 3 deletions plugins/console.js
Original file line number Diff line number Diff line change
@@ -25,9 +25,9 @@ var logForGivenLevel = function(level) {
if (originalConsoleLevel) {
// IE9 doesn't allow calling apply on console functions directly
// See: https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function#answer-5473193
Function.prototype.bind
.call(originalConsoleLevel, originalConsole)
.apply(originalConsole, args);
Function.prototype.bind
.call(originalConsoleLevel, originalConsole)
.apply(originalConsole, args);
}
};
};
8 changes: 5 additions & 3 deletions src/raven.js
Original file line number Diff line number Diff line change
@@ -25,8 +25,10 @@ var _Raven = window.Raven,
},
authQueryString,
isRavenInstalled = false,

objectPrototype = Object.prototype,
// capture a reference to window.console first before
// the console plugin has a chance to monkey patch
originalConsole = window.console || {},
startTime = now();

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

function logDebug(level) {
if (window.console && console[level] && Raven.debug) {
if (originalConsole[level] && Raven.debug) {
// _slice is coming from vendor/TraceKit/tracekit.js
// so it's accessible globally
console[level].apply(console, _slice.call(arguments, 1));
originalConsole[level].apply(originalConsole, _slice.call(arguments, 1));
}
}

11 changes: 6 additions & 5 deletions test/raven.test.js
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ function flushRavenState() {
},
startTime = 0;
ravenNotConfiguredError = undefined;
originalConsole = window.console || {};

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

it('should not write to console when Raven.debug is false', function() {
Raven.debug = false;
this.sinon.stub(console, level);
this.sinon.stub(originalConsole, level);
logDebug(level, message);
assert.isFalse(console[level].called);
assert.isFalse(originalConsole[level].called);
});

it('should write to console when Raven.debug is true', function() {
Raven.debug = true;
this.sinon.stub(console, level);
this.sinon.stub(originalConsole, level);
logDebug(level, message);
assert.isTrue(console[level].calledOnce);
assert.isTrue(originalConsole[level].calledOnce);
});

it('should handle variadic arguments', function() {
Raven.debug = true;
this.sinon.stub(console, level);
this.sinon.stub(originalConsole, level);
logDebug(level, message, {}, 'foo');
});
});