Skip to content

Commit 4df4911

Browse files
committed
WIP: setEvalOrigin for v8
1 parent b50a335 commit 4df4911

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

error-stack-parser.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,43 @@
5454
}, this);
5555

5656
return filtered.map(function(line) {
57+
var evalStackFrame;
5758
if (line.indexOf('(eval ') > -1) {
58-
// Throw away eval information until we implement stacktrace.js/stackframe#8
59+
var regExp = /\), (<[^>]+>:\d+:\d+)\)$/;
60+
var evalParts = regExp.exec(line);
61+
if (evalParts) {
62+
var evalLocationParts = this.extractLocation(evalParts[1]);
63+
64+
evalStackFrame = new StackFrame({
65+
functionName: 'eval',
66+
fileName: evalLocationParts[0],
67+
lineNumber: evalLocationParts[1],
68+
columnNumber: evalLocationParts[2],
69+
source: line,
70+
isEval: true
71+
});
72+
}
73+
5974
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, '');
6075
}
6176
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1);
6277
var locationParts = this.extractLocation(tokens.pop());
6378
var functionName = tokens.join(' ') || undefined;
6479
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0];
6580

66-
return new StackFrame({
81+
var stackFrame = new StackFrame({
6782
functionName: functionName,
6883
fileName: fileName,
6984
lineNumber: locationParts[1],
7085
columnNumber: locationParts[2],
7186
source: line
7287
});
88+
89+
if (evalStackFrame) {
90+
stackFrame.setEvalOrigin(evalStackFrame);
91+
}
92+
93+
return stackFrame;
7394
}, this);
7495
},
7596

spec/error-stack-parser-spec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ describe('ErrorStackParser', function() {
116116
expect(stackFrames[4]).toMatchStackFrame([undefined, undefined, 'http://localhost:8080/file.js', 31, 13]);
117117
});
118118

119+
it('should parse and set eval origin for eval() from V8', function() {
120+
var stackFrames = unit.parse(CapturedExceptions.CHROME_58_EVAL);
121+
expect(stackFrames).toBeTruthy();
122+
expect(stackFrames.length).toBe(6);
123+
expect(stackFrames[0]).toMatchStackFrame(['willThrow', undefined, 'index.js', 11, undefined]);
124+
expect(stackFrames[0].getEvalOrigin()).toMatchStackFrame(['eval', undefined, '<anonymous>', 3, 3]);
125+
expect(stackFrames[1]).toMatchStackFrame(['eval', undefined, 'index.js', 11, undefined]);
126+
expect(stackFrames[1].getEvalOrigin()).toMatchStackFrame(['eval', undefined, '<anonymous>', 6, 1]);
127+
expect(stackFrames[2]).toMatchStackFrame(['h', undefined, 'index.js', 11, undefined]);
128+
expect(stackFrames[3]).toMatchStackFrame(['g', undefined, 'index.js', 6, undefined]);
129+
expect(stackFrames[4]).toMatchStackFrame(['f', undefined, 'index.js', 2, undefined]);
130+
expect(stackFrames[5]).toMatchStackFrame([undefined, undefined, 'index.js', 23, undefined]);
131+
});
132+
119133
it('should parse IE 10 Error stacks', function() {
120134
var stackFrames = unit.parse(CapturedExceptions.IE_10);
121135
expect(stackFrames).toBeTruthy();
@@ -210,7 +224,8 @@ describe('ErrorStackParser', function() {
210224
});
211225

212226
it('should handle webpack eval stacks', function() {
213-
var stackframes = unit.parse({stack: 'ReferenceError: chilxdren is not defined\n ' +
227+
var stackframes = unit.parse({
228+
stack: 'ReferenceError: chilxdren is not defined\n ' +
214229
'at Layout (eval at proxyClass (webpack:///../react-hot-loader/~/react-proxy/modules/createClassProxy.js?), <anonymous>:4:17)'
215230
});
216231
expect(stackframes.length).toBe(1);

spec/fixtures/captured-errors.js

+12
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ CapturedExceptions.CHROME_48_NESTED_EVAL = {
194194
'at http://localhost:8080/file.js:31:13\n'
195195
};
196196

197+
CapturedExceptions.CHROME_58_EVAL = {
198+
message: 'message string',
199+
name: 'Error',
200+
stack: 'Error: message string\n' +
201+
'at willThrow (eval at h (index.js:11), <anonymous>:3:3)\n' +
202+
'at eval (eval at h (index.js:11), <anonymous>:6:1)\n' +
203+
'at h (index.js:11)\n' +
204+
'at g (index.js:6)\n' +
205+
'at f (index.js:2)\n' +
206+
'at index.js:23\n'
207+
};
208+
197209
CapturedExceptions.FIREFOX_3 = {
198210
fileName: 'http://127.0.0.1:8000/js/stacktrace.js',
199211
lineNumber: 44,

0 commit comments

Comments
 (0)