|
1 | | -/* global StackFrame: false */ |
2 | 1 | (function (root, factory) { |
3 | 2 | 'use strict'; |
4 | 3 | // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. |
5 | 4 | if (typeof define === 'function' && define.amd) { |
6 | | - define(['stackframe'], factory); |
| 5 | + define('error-stack-parser', ['stackframe'], factory); |
7 | 6 | } else if (typeof exports === 'object') { |
8 | 7 | module.exports = factory(require('stackframe')); |
9 | 8 | } else { |
|
13 | 12 | 'use strict'; |
14 | 13 |
|
15 | 14 | // 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 | | - |
39 | 15 | // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map |
40 | 16 | if (!Array.prototype.map) { |
41 | 17 | Array.prototype.map = function(callback, thisArg) { |
42 | | - if (this === void 0 || this === null) { |
43 | | - throw new TypeError("this is null or not defined"); |
44 | | - } |
45 | 18 | var O = Object(this); |
46 | 19 | var len = O.length >>> 0; |
47 | 20 | var T; |
48 | | - if (typeof callback !== "function") { |
49 | | - throw new TypeError(callback + " is not a function"); |
50 | | - } |
51 | 21 | if (arguments.length > 1) { |
52 | 22 | T = thisArg; |
53 | 23 | } |
|
72 | 42 | // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter |
73 | 43 | if (!Array.prototype.filter) { |
74 | 44 | 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 | | - |
79 | 45 | var t = Object(this); |
80 | 46 | var len = t.length >>> 0; |
81 | | - if (typeof callback !== "function") { |
82 | | - throw new TypeError(callback + " is not a function"); |
83 | | - } |
84 | 47 |
|
85 | 48 | var res = []; |
86 | 49 | var thisArg = arguments.length >= 2 ? arguments[1] : void 0; |
|
109 | 72 | parse: function ErrorStackParser$$parse(error) { |
110 | 73 | if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { |
111 | 74 | 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)) { |
113 | 76 | 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)) { |
115 | 78 | return this.parseFFOrSafari(error); |
116 | 79 | } else { |
117 | 80 | throw new Error('Cannot parse given Error object'); |
|
141 | 104 | var locationParts = this.extractLocation(tokens.pop().replace(/[\(\)\s]/g, '')); |
142 | 105 | var functionName = (!tokens[0] || tokens[0] === 'Anonymous') ? undefined : tokens[0]; |
143 | 106 | return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2]); |
144 | | - }.bind(this)); |
| 107 | + }, this); |
145 | 108 | }, |
146 | 109 |
|
147 | 110 | parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { |
148 | 111 | return error.stack.split('\n').filter(function (line) { |
149 | 112 | return !!line.match(FIREFOX_SAFARI_STACK_REGEXP); |
150 | | - }.bind(this)).map(function (line) { |
| 113 | + }, this).map(function (line) { |
151 | 114 | var tokens = line.split('@'); |
152 | 115 | var locationParts = this.extractLocation(tokens.pop()); |
153 | 116 | var functionName = tokens.shift() || undefined; |
154 | 117 | return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2]); |
155 | | - }.bind(this)); |
| 118 | + }, this); |
156 | 119 | }, |
157 | 120 |
|
158 | 121 | parseOpera: function ErrorStackParser$$parseOpera(e) { |
159 | 122 | if (!e.stacktrace || (e.message.indexOf('\n') > -1 && |
160 | 123 | e.message.split('\n').length > e.stacktrace.split('\n').length)) { |
161 | 124 | return this.parseOpera9(e); |
162 | 125 | } 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); |
166 | 127 | } else { |
167 | 128 | return this.parseOpera11(e); |
168 | 129 | } |
|
183 | 144 | return result; |
184 | 145 | }, |
185 | 146 |
|
186 | | - parseOpera10a: function ErrorStackParser$$parseOpera10a(e) { |
| 147 | + parseOpera10: function ErrorStackParser$$parseOpera10(e) { |
187 | 148 | var lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i; |
188 | 149 | var lines = e.stacktrace.split('\n'); |
189 | 150 | var result = []; |
|
203 | 164 | return error.stack.split('\n').filter(function (line) { |
204 | 165 | return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && |
205 | 166 | !line.match(/^Error created at/); |
206 | | - }.bind(this)).map(function (line) { |
| 167 | + }, this).map(function (line) { |
207 | 168 | var tokens = line.split('@'); |
208 | 169 | var locationParts = this.extractLocation(tokens.pop()); |
209 | 170 | var functionCall = (tokens.shift() || ''); |
|
216 | 177 | } |
217 | 178 | var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? undefined : argsRaw.split(','); |
218 | 179 | return new StackFrame(functionName, args, locationParts[0], locationParts[1], locationParts[2]); |
219 | | - }.bind(this)); |
| 180 | + }, this); |
220 | 181 | } |
221 | 182 | }; |
222 | 183 | })); |
|
0 commit comments