Skip to content

Commit 07dbd06

Browse files
author
Eric Wendelin
committed
Handle native functions in V8 stack traces. Fixes stacktracejs/stacktrace.js#108
1 parent c86dc01 commit 07dbd06

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

error-stack-parser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
* @return Array[String]
3939
*/
4040
extractLocation: function ErrorStackParser$$extractLocation(urlLike) {
41+
// Guard against strings like "(native)"
42+
if (urlLike.indexOf(':') === -1) {
43+
return [];
44+
}
45+
4146
var locationParts = urlLike.split(':');
4247
var lastNumber = locationParts.pop();
4348
var possibleNumber = locationParts[locationParts.length - 1];

spec/error-stack-parser-spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ describe('ErrorStackParser', function () {
5353
expect(stackFrames[3]).toMatchStackFrame([undefined, undefined, 'http://path/to/file.js', 24, 4]);
5454
});
5555

56+
it('should parse V8 entries with no location', function () {
57+
var stackFrames = unit.parse({stack: "Error\n at Array.forEach (native)"});
58+
expect(stackFrames.length).toBe(1);
59+
expect(stackFrames[0]).toMatchStackFrame(['Array.forEach', undefined, undefined, undefined, undefined]);
60+
});
61+
5662
it('should parse V8 Error.stack entries with port numbers', function () {
5763
var stackFrames = unit.parse(CapturedExceptions.CHROME_36);
5864
expect(stackFrames).toBeTruthy();

0 commit comments

Comments
 (0)