Skip to content

Commit b2fe9fd

Browse files
author
Eric Wendelin
committed
Allow (native) locations. Fixes #10.
1 parent 138479e commit b2fe9fd

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

error-stack-parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
* @return Array[String]
3939
*/
4040
extractLocation: function ErrorStackParser$$extractLocation(urlLike) {
41-
// Guard against strings like "(native)"
41+
// Fail-fast but return locations like "(native)"
4242
if (urlLike.indexOf(':') === -1) {
43-
return [];
43+
return [urlLike];
4444
}
4545

46-
var locationParts = urlLike.split(':');
46+
var locationParts = urlLike.replace(/[\(\)\s]/g, '').split(':');
4747
var lastNumber = locationParts.pop();
4848
var possibleNumber = locationParts[locationParts.length - 1];
4949
if (!isNaN(parseFloat(possibleNumber)) && isFinite(possibleNumber)) {
@@ -57,7 +57,7 @@
5757
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) {
5858
return error.stack.split('\n').slice(1).map(function (line) {
5959
var tokens = line.replace(/^\s+/, '').split(/\s+/).slice(1);
60-
var locationParts = this.extractLocation(tokens.pop().replace(/[\(\)\s]/g, ''));
60+
var locationParts = this.extractLocation(tokens.pop());
6161
var functionName = (!tokens[0] || tokens[0] === 'Anonymous') ? undefined : tokens[0];
6262
return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2]);
6363
}, this);

spec/error-stack-parser-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('ErrorStackParser', function () {
5656
it('should parse V8 entries with no location', function () {
5757
var stackFrames = unit.parse({stack: "Error\n at Array.forEach (native)"});
5858
expect(stackFrames.length).toBe(1);
59-
expect(stackFrames[0]).toMatchStackFrame(['Array.forEach', undefined, undefined, undefined, undefined]);
59+
expect(stackFrames[0]).toMatchStackFrame(['Array.forEach', undefined, '(native)', undefined, undefined]);
6060
});
6161

6262
it('should parse V8 Error.stack entries with port numbers', function () {

0 commit comments

Comments
 (0)