Skip to content

Commit 8b76072

Browse files
committed
Replace use of Array.map and Array.filter in order to avoid the need for polyfills. Release v1.3.3
1 parent 5a194c1 commit 8b76072

11 files changed

+88
-84
lines changed

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "error-stack-parser",
33
"repository": "stacktracejs/error-stack-parser",
44
"description": "Extract meaning from JS Errors",
5-
"version": "1.2.2",
5+
"version": "1.3.3",
66
"keywords": [
77
"stacktrace",
88
"error",

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

Lines changed: 0 additions & 2 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/error-stack-parser.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,32 @@
1717
var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m;
1818
var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/;
1919

20+
function _map(array, fn, thisArg) {
21+
if (typeof Array.prototype.map === 'function') {
22+
return array.map(fn, thisArg);
23+
} else {
24+
var output = new Array(array.length);
25+
for (var i = 0; i < array.length; i++) {
26+
output[i] = fn.call(thisArg, array[i]);
27+
}
28+
return output;
29+
}
30+
}
31+
32+
function _filter(array, fn, thisArg) {
33+
if (typeof Array.prototype.filter === 'function') {
34+
return array.filter(fn, thisArg);
35+
} else {
36+
var output = [];
37+
for (var i = 0; i < array.length; i++) {
38+
if (fn.call(thisArg, array[i])) {
39+
output.push(array[i]);
40+
}
41+
}
42+
return output;
43+
}
44+
}
45+
2046
return {
2147
/**
2248
* Given an Error object, extract the most information from it.
@@ -28,7 +54,7 @@
2854
return this.parseOpera(error);
2955
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
3056
return this.parseV8OrIE(error);
31-
} else if (error.stack && error.stack.match(FIREFOX_SAFARI_STACK_REGEXP)) {
57+
} else if (error.stack) {
3258
return this.parseFFOrSafari(error);
3359
} else {
3460
throw new Error('Cannot parse given Error object');
@@ -58,9 +84,11 @@
5884
},
5985

6086
parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) {
61-
return error.stack.split('\n').filter(function (line) {
87+
var filtered = _filter(error.stack.split('\n'), function (line) {
6288
return !!line.match(CHROME_IE_STACK_REGEXP);
63-
}, this).map(function (line) {
89+
}, this);
90+
91+
return _map(filtered, function (line) {
6492
if (line.indexOf('(eval ') > -1) {
6593
// Throw away eval information until we implement stacktrace.js/stackframe#8
6694
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, '');
@@ -75,9 +103,11 @@
75103
},
76104

77105
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) {
78-
return error.stack.split('\n').filter(function (line) {
106+
var filtered = _filter(error.stack.split('\n'), function (line) {
79107
return !line.match(SAFARI_NATIVE_CODE_REGEXP);
80-
}, this).map(function (line) {
108+
}, this);
109+
110+
return _map(filtered, function (line) {
81111
// Throw away eval information until we implement stacktrace.js/stackframe#8
82112
if (line.indexOf(' > eval') > -1) {
83113
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1');
@@ -138,10 +168,12 @@
138168

139169
// Opera 10.65+ Error.stack very similar to FF/Safari
140170
parseOpera11: function ErrorStackParser$$parseOpera11(error) {
141-
return error.stack.split('\n').filter(function (line) {
171+
var filtered = _filter(error.stack.split('\n'), function (line) {
142172
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) &&
143173
!line.match(/^Error created at/);
144-
}, this).map(function (line) {
174+
}, this);
175+
176+
return _map(filtered, function (line) {
145177
var tokens = line.split('@');
146178
var locationParts = this.extractLocation(tokens.pop());
147179
var functionCall = (tokens.shift() || '');

dist/error-stack-parser.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.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.

0 commit comments

Comments
 (0)