Skip to content

Commit 3713f4a

Browse files
committed
Altered Chrome stacktrace line regular expression to cover both reported cases of anonymous functions
1 parent 1745ba8 commit 3713f4a

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

test/raven.test.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,23 @@ describe('TraceKit', function(){
5656
// named functions and anonymous functions
5757
var stack_str = "" +
5858
" 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]
59+
" at new <anonymous> (http://example.com/js/test.js:63)\n" + // stack[0]
60+
" at namedFunc0 (http://example.com/js/script.js:10)\n" + // stack[1]
61+
" at http://example.com/js/test.js:65\n" + // stack[2]
62+
" at namedFunc2 (http://example.com/js/script.js:20)\n" + // stack[3]
63+
" at http://example.com/js/test.js:67\n" + // stack[4]
64+
" at namedFunc4 (http://example.com/js/script.js:100001)"; // stack[5]
6465
var mock_err = { stack: stack_str };
6566
var trace = TraceKit.computeStackTrace.computeStackTraceFromStackProp(mock_err);
6667

6768
// Make sure TraceKit didn't remove the anonymous functions
6869
// 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');
70+
assert.equal(trace.stack[0].func, 'new <anonymous>');
71+
assert.equal(trace.stack[1].func, 'namedFunc0');
72+
assert.equal(trace.stack[2].func, '?');
73+
assert.equal(trace.stack[3].func, 'namedFunc2');
74+
assert.equal(trace.stack[4].func, '?');
75+
assert.equal(trace.stack[5].func, 'namedFunc4');
7476
});
7577
});
7678
describe('error notifications', function(){

vendor/TraceKit/tracekit.js

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

634-
var chrome = /^\s*at (\S*) ?\(?((?:file|https?|chrome-extension):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
634+
var chrome = /^\s*at ([^\(]+)? ?\(?((?: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 = [],
638638
parts,
639639
element,
640+
func,
640641
reference = /^(.*) is undefined$/.exec(ex.message);
641642

642643
for (var i = 0, j = lines.length; i < j; ++i) {
@@ -651,7 +652,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
651652
} else if ((parts = chrome.exec(lines[i]))) {
652653
element = {
653654
'url': parts[2],
654-
'func': parts[1] || UNKNOWN_FUNCTION,
655+
'func': (parts[1] || UNKNOWN_FUNCTION).trim(),
655656
'line': +parts[3],
656657
'column': parts[4] ? +parts[4] : null
657658
};

0 commit comments

Comments
 (0)