Skip to content

Commit 116c887

Browse files
author
Eric Wendelin
committed
Fix IE9- thrown Error. Remove opera10b; replaced by opera11 handler. Fixes #7.
1 parent ad0c28a commit 116c887

File tree

6 files changed

+33
-100
lines changed

6 files changed

+33
-100
lines changed

dist/error-stack-parser.js

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
/* global StackFrame: false */
21
(function (root, factory) {
32
'use strict';
43
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers.
54
if (typeof define === 'function' && define.amd) {
6-
define(['stackframe'], factory);
5+
define('error-stack-parser', ['stackframe'], factory);
76
} else if (typeof exports === 'object') {
87
module.exports = factory(require('stackframe'));
98
} else {
@@ -13,41 +12,12 @@
1312
'use strict';
1413

1514
// ES5 Polyfills
16-
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
17-
if (!Function.prototype.bind) {
18-
Function.prototype.bind = function (oThis) {
19-
if (typeof this !== 'function') {
20-
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
21-
}
22-
23-
var aArgs = Array.prototype.slice.call(arguments, 1);
24-
var fToBind = this;
25-
var NoOp = function () {
26-
};
27-
var fBound = function () {
28-
return fToBind.apply(this instanceof NoOp && oThis ? this : oThis,
29-
aArgs.concat(Array.prototype.slice.call(arguments)));
30-
};
31-
32-
NoOp.prototype = this.prototype;
33-
fBound.prototype = new NoOp();
34-
35-
return fBound;
36-
};
37-
}
38-
3915
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
4016
if (!Array.prototype.map) {
4117
Array.prototype.map = function(callback, thisArg) {
42-
if (this === void 0 || this === null) {
43-
throw new TypeError("this is null or not defined");
44-
}
4518
var O = Object(this);
4619
var len = O.length >>> 0;
4720
var T;
48-
if (typeof callback !== "function") {
49-
throw new TypeError(callback + " is not a function");
50-
}
5121
if (arguments.length > 1) {
5222
T = thisArg;
5323
}
@@ -72,15 +42,8 @@
7242
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
7343
if (!Array.prototype.filter) {
7444
Array.prototype.filter = function(callback/*, thisArg*/) {
75-
if (this === void 0 || this === null) {
76-
throw new TypeError("this is null or not defined");
77-
}
78-
7945
var t = Object(this);
8046
var len = t.length >>> 0;
81-
if (typeof callback !== "function") {
82-
throw new TypeError(callback + " is not a function");
83-
}
8447

8548
var res = [];
8649
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
@@ -109,9 +72,9 @@
10972
parse: function ErrorStackParser$$parse(error) {
11073
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') {
11174
return this.parseOpera(error);
112-
} else if (error.stack.match(CHROME_IE_STACK_REGEXP)) {
75+
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
11376
return this.parseV8OrIE(error);
114-
} else if (error.stack.match(FIREFOX_SAFARI_STACK_REGEXP)) {
77+
} else if (error.stack && error.stack.match(FIREFOX_SAFARI_STACK_REGEXP)) {
11578
return this.parseFFOrSafari(error);
11679
} else {
11780
throw new Error('Cannot parse given Error object');
@@ -141,28 +104,26 @@
141104
var locationParts = this.extractLocation(tokens.pop().replace(/[\(\)\s]/g, ''));
142105
var functionName = (!tokens[0] || tokens[0] === 'Anonymous') ? undefined : tokens[0];
143106
return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2]);
144-
}.bind(this));
107+
}, this);
145108
},
146109

147110
parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) {
148111
return error.stack.split('\n').filter(function (line) {
149112
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP);
150-
}.bind(this)).map(function (line) {
113+
}, this).map(function (line) {
151114
var tokens = line.split('@');
152115
var locationParts = this.extractLocation(tokens.pop());
153116
var functionName = tokens.shift() || undefined;
154117
return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2]);
155-
}.bind(this));
118+
}, this);
156119
},
157120

158121
parseOpera: function ErrorStackParser$$parseOpera(e) {
159122
if (!e.stacktrace || (e.message.indexOf('\n') > -1 &&
160123
e.message.split('\n').length > e.stacktrace.split('\n').length)) {
161124
return this.parseOpera9(e);
162125
} else if (!e.stack) {
163-
return this.parseOpera10a(e);
164-
} else if (e.stacktrace.indexOf("called from line") < 0) {
165-
return this.parseOpera10b(e);
126+
return this.parseOpera10(e);
166127
} else {
167128
return this.parseOpera11(e);
168129
}
@@ -183,7 +144,7 @@
183144
return result;
184145
},
185146

186-
parseOpera10a: function ErrorStackParser$$parseOpera10a(e) {
147+
parseOpera10: function ErrorStackParser$$parseOpera10(e) {
187148
var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
188149
var lines = e.stacktrace.split('\n');
189150
var result = [];
@@ -203,7 +164,7 @@
203164
return error.stack.split('\n').filter(function (line) {
204165
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) &&
205166
!line.match(/^Error created at/);
206-
}.bind(this)).map(function (line) {
167+
}, this).map(function (line) {
207168
var tokens = line.split('@');
208169
var locationParts = this.extractLocation(tokens.pop());
209170
var functionCall = (tokens.shift() || '');
@@ -216,7 +177,7 @@
216177
}
217178
var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? undefined : argsRaw.split(',');
218179
return new StackFrame(functionName, args, locationParts[0], locationParts[1], locationParts[2]);
219-
}.bind(this));
180+
}, this);
220181
}
221182
};
222183
}));

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