Skip to content

Add support for setEvalOrigin #37

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
25 changes: 23 additions & 2 deletions error-stack-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,43 @@
}, this);

return filtered.map(function(line) {
var evalStackFrame;
if (line.indexOf('(eval ') > -1) {
// Throw away eval information until we implement stacktrace.js/stackframe#8
var regExp = /\), (<[^>]+>:\d+:\d+)\)$/;
var evalParts = regExp.exec(line);
if (evalParts) {
var evalLocationParts = this.extractLocation(evalParts[1]);

evalStackFrame = new StackFrame({
functionName: 'eval',
fileName: evalLocationParts[0],
lineNumber: evalLocationParts[1],
columnNumber: evalLocationParts[2],
source: line,
isEval: true
});
}

line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, '');
}
var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1);
var locationParts = this.extractLocation(tokens.pop());
var functionName = tokens.join(' ') || undefined;
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0];

return new StackFrame({
var stackFrame = new StackFrame({
functionName: functionName,
fileName: fileName,
lineNumber: locationParts[1],
columnNumber: locationParts[2],
source: line
});

if (evalStackFrame) {
stackFrame.setEvalOrigin(evalStackFrame);
}

return stackFrame;
}, this);
},

Expand Down
14 changes: 14 additions & 0 deletions spec/error-stack-parser-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ describe('ErrorStackParser', function() {
expect(stackFrames[4]).toMatchStackFrame([undefined, undefined, 'http://localhost:8080/file.js', 31, 13]);
});

it('should parse and set eval origin for eval() from V8', function() {
var stackFrames = unit.parse(CapturedExceptions.CHROME_58_EVAL);
expect(stackFrames).toBeTruthy();
expect(stackFrames.length).toBe(6);
expect(stackFrames[0]).toMatchStackFrame(['willThrow', undefined, 'index.js', 11, undefined]);
expect(stackFrames[0].getEvalOrigin()).toMatchStackFrame(['eval', undefined, '<anonymous>', 3, 3]);
expect(stackFrames[1]).toMatchStackFrame(['eval', undefined, 'index.js', 11, undefined]);
expect(stackFrames[1].getEvalOrigin()).toMatchStackFrame(['eval', undefined, '<anonymous>', 6, 1]);
expect(stackFrames[2]).toMatchStackFrame(['h', undefined, 'index.js', 11, undefined]);
expect(stackFrames[3]).toMatchStackFrame(['g', undefined, 'index.js', 6, undefined]);
expect(stackFrames[4]).toMatchStackFrame(['f', undefined, 'index.js', 2, undefined]);
expect(stackFrames[5]).toMatchStackFrame([undefined, undefined, 'index.js', 23, undefined]);
});

it('should parse IE 10 Error stacks', function() {
var stackFrames = unit.parse(CapturedExceptions.IE_10);
expect(stackFrames).toBeTruthy();
Expand Down
12 changes: 12 additions & 0 deletions spec/fixtures/captured-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ CapturedExceptions.CHROME_48_NESTED_EVAL = {
'at http://localhost:8080/file.js:31:13\n'
};

CapturedExceptions.CHROME_58_EVAL = {
message: 'message string',
name: 'Error',
stack: 'Error: message string\n' +
'at willThrow (eval at h (index.js:11), <anonymous>:3:3)\n' +
'at eval (eval at h (index.js:11), <anonymous>:6:1)\n' +
'at h (index.js:11)\n' +
'at g (index.js:6)\n' +
'at f (index.js:2)\n' +
'at index.js:23\n'
};

CapturedExceptions.FIREFOX_3 = {
fileName: 'http://127.0.0.1:8000/js/stacktrace.js',
lineNumber: 44,
Expand Down