Skip to content

Commit 8106d75

Browse files
committed
Improve handling of eval() stack frames.
This removes parts of stack lines related to the eval lines and columns. This was done this way to avoid breaking current stack traces until we have a good solution for including them.
1 parent df8b4e4 commit 8106d75

9 files changed

+134
-43
lines changed

dist/error-stack-parser-with-polyfills.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/error-stack-parser-with-polyfills.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/error-stack-parser.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
'use strict';
1515

1616
var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/;
17-
var CHROME_IE_STACK_REGEXP = /\s*at .*(\S+\:\d+|\(native\))/;
17+
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m;
18+
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/;
1819

1920
return {
2021
/**
@@ -60,27 +61,37 @@
6061
return error.stack.split('\n').filter(function (line) {
6162
return !!line.match(CHROME_IE_STACK_REGEXP);
6263
}, this).map(function (line) {
63-
if (line.indexOf('(eval at ') > -1) {
64-
// TODO: we need a way of representing location within eval()'d String
65-
// throw away all intermediate "eval at XXX" and location within eval()'d string
66-
line = line.replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, '');
64+
if (line.indexOf('(eval ') > -1) {
65+
// Throw away eval information until we implement stacktrace.js/stackframe#8
66+
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, '');
6767
}
68-
var tokens = line.replace(/^\s+/, '').split(/\s+/).slice(1);
68+
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1);
6969
var locationParts = this.extractLocation(tokens.pop());
7070
var functionName = tokens.join(' ') || undefined;
71+
var fileName = locationParts[0] === 'eval' ? undefined : locationParts[0];
7172

72-
return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2], line);
73+
return new StackFrame(functionName, undefined, fileName, locationParts[1], locationParts[2], line);
7374
}, this);
7475
},
7576

7677
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) {
7778
return error.stack.split('\n').filter(function (line) {
78-
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP);
79+
return !line.match(SAFARI_NATIVE_CODE_REGEXP);
7980
}, this).map(function (line) {
80-
var tokens = line.split('@');
81-
var locationParts = this.extractLocation(tokens.pop());
82-
var functionName = tokens.shift() || undefined;
83-
return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2], line);
81+
// Throw away eval information until we implement stacktrace.js/stackframe#8
82+
if (line.indexOf(' > eval') > -1) {
83+
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1');
84+
}
85+
86+
if (line.indexOf('@') === -1 && line.indexOf(':') === -1) {
87+
// Safari eval frames only have function names and nothing else
88+
return new StackFrame(line);
89+
} else {
90+
var tokens = line.split('@');
91+
var locationParts = this.extractLocation(tokens.pop());
92+
var functionName = tokens.shift() || undefined;
93+
return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2], line);
94+
}
8495
}, this);
8596
},
8697

0 commit comments

Comments
 (0)