Skip to content

Commit ee7fe10

Browse files
committed
Merge pull request #290 from mwcz/fix-chrome-stacktrace-regex
don't remove anonymous functions from stack trace
2 parents f6e8cbe + d94cb5f commit ee7fe10

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

test/raven.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ function now() {
5050
}
5151

5252
describe('TraceKit', function(){
53+
describe('stacktrace info', function() {
54+
it('should not remove anonymous functions from the stack', function() {
55+
// mock up an error object with a stack trace that includes both
56+
// named functions and anonymous functions
57+
var stack_str = "" +
58+
" Error: \n" +
59+
" at namedFunc0 (http://example.com/js/script.js:10)\n" + // stack[0]
60+
" at http://example.com/js/test.js:65\n" + // stack[1]
61+
" at namedFunc2 (http://example.com/js/script.js:20)\n" + // stack[2]
62+
" at http://example.com/js/test.js:67\n" + // stack[3]
63+
" at namedFunc4 (http://example.com/js/script.js:100001)"; // stack[4]
64+
var mock_err = { stack: stack_str };
65+
var trace = TraceKit.computeStackTrace.computeStackTraceFromStackProp(mock_err);
66+
67+
// Make sure TraceKit didn't remove the anonymous functions
68+
// from the stack like it used to :)
69+
assert.equal(trace.stack[0].func, 'namedFunc0');
70+
assert.equal(trace.stack[1].func, '?');
71+
assert.equal(trace.stack[2].func, 'namedFunc2');
72+
assert.equal(trace.stack[3].func, '?');
73+
assert.equal(trace.stack[4].func, 'namedFunc4');
74+
});
75+
});
5376
describe('error notifications', function(){
5477
var testMessage = "__mocha_ignore__";
5578
var subscriptionHandler;

vendor/TraceKit/tracekit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
631631
return null;
632632
}
633633

634-
var chrome = /^\s*at (.+?) ?\(?((?:file|https?|chrome-extension):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
634+
var chrome = /^\s*at (\S*) ?\(?((?:file|https?|chrome-extension):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
635635
gecko = /^\s*(.*?)(?:\((.*?)\))?@((?:file|https?|chrome).*?):(\d+)(?::(\d+))?\s*$/i,
636636
lines = ex.stack.split('\n'),
637637
stack = [],
@@ -1064,6 +1064,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
10641064
}
10651065

10661066
computeStackTrace.augmentStackTraceWithInitialElement = augmentStackTraceWithInitialElement;
1067+
computeStackTrace.computeStackTraceFromStackProp = computeStackTraceFromStackProp;
10671068
computeStackTrace.guessFunctionName = guessFunctionName;
10681069
computeStackTrace.gatherContext = gatherContext;
10691070
computeStackTrace.ofCaller = computeStackTraceOfCaller;

0 commit comments

Comments
 (0)