|
1 | | -(function (root, factory) { |
| 1 | +(function(root, factory) { |
2 | 2 | 'use strict'; |
3 | 3 | // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. |
4 | 4 |
|
|
46 | 46 | return { |
47 | 47 | /** |
48 | 48 | * Given an Error object, extract the most information from it. |
49 | | - * @param error {Error} |
50 | | - * @return Array[StackFrame] |
| 49 | + * |
| 50 | + * @param {Error} error object |
| 51 | + * @return {Array} of StackFrames |
51 | 52 | */ |
52 | 53 | parse: function ErrorStackParser$$parse(error) { |
53 | 54 | if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') { |
|
63 | 64 |
|
64 | 65 | /** |
65 | 66 | * Separate line and column numbers from a URL-like string. |
66 | | - * @param urlLike String |
67 | | - * @return Array[String] |
| 67 | + * |
| 68 | + * @param {String} urlLike |
| 69 | + * @return {Array} 3-tuple of URL, Line Number, and Column Number |
68 | 70 | */ |
69 | 71 | extractLocation: function ErrorStackParser$$extractLocation(urlLike) { |
70 | 72 | // Fail-fast but return locations like "(native)" |
|
84 | 86 | }, |
85 | 87 |
|
86 | 88 | parseV8OrIE: function ErrorStackParser$$parseV8OrIE(error) { |
87 | | - var filtered = _filter(error.stack.split('\n'), function (line) { |
| 89 | + var filtered = _filter(error.stack.split('\n'), function(line) { |
88 | 90 | return !!line.match(CHROME_IE_STACK_REGEXP); |
89 | 91 | }, this); |
90 | 92 |
|
91 | | - return _map(filtered, function (line) { |
| 93 | + return _map(filtered, function(line) { |
92 | 94 | if (line.indexOf('(eval ') > -1) { |
93 | 95 | // Throw away eval information until we implement stacktrace.js/stackframe#8 |
94 | 96 | line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); |
95 | 97 | } |
96 | 98 | var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); |
97 | 99 | var locationParts = this.extractLocation(tokens.pop()); |
98 | 100 | var functionName = tokens.join(' ') || undefined; |
99 | | - var fileName = locationParts[0] === 'eval' ? undefined : locationParts[0]; |
| 101 | + var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; |
100 | 102 |
|
101 | 103 | return new StackFrame(functionName, undefined, fileName, locationParts[1], locationParts[2], line); |
102 | 104 | }, this); |
103 | 105 | }, |
104 | 106 |
|
105 | 107 | parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { |
106 | | - var filtered = _filter(error.stack.split('\n'), function (line) { |
| 108 | + var filtered = _filter(error.stack.split('\n'), function(line) { |
107 | 109 | return !line.match(SAFARI_NATIVE_CODE_REGEXP); |
108 | 110 | }, this); |
109 | 111 |
|
110 | | - return _map(filtered, function (line) { |
| 112 | + return _map(filtered, function(line) { |
111 | 113 | // Throw away eval information until we implement stacktrace.js/stackframe#8 |
112 | 114 | if (line.indexOf(' > eval') > -1) { |
113 | 115 | line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); |
|
119 | 121 | } else { |
120 | 122 | var tokens = line.split('@'); |
121 | 123 | var locationParts = this.extractLocation(tokens.pop()); |
122 | | - var functionName = tokens.shift() || undefined; |
123 | | - return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2], line); |
| 124 | + var functionName = tokens.join('@') || undefined; |
| 125 | + return new StackFrame(functionName, |
| 126 | + undefined, |
| 127 | + locationParts[0], |
| 128 | + locationParts[1], |
| 129 | + locationParts[2], |
| 130 | + line); |
124 | 131 | } |
125 | 132 | }, this); |
126 | 133 | }, |
|
159 | 166 | for (var i = 0, len = lines.length; i < len; i += 2) { |
160 | 167 | var match = lineRE.exec(lines[i]); |
161 | 168 | if (match) { |
162 | | - result.push(new StackFrame(match[3] || undefined, undefined, match[2], match[1], undefined, lines[i])); |
| 169 | + result.push( |
| 170 | + new StackFrame( |
| 171 | + match[3] || undefined, |
| 172 | + undefined, |
| 173 | + match[2], |
| 174 | + match[1], |
| 175 | + undefined, |
| 176 | + lines[i] |
| 177 | + ) |
| 178 | + ); |
163 | 179 | } |
164 | 180 | } |
165 | 181 |
|
|
168 | 184 |
|
169 | 185 | // Opera 10.65+ Error.stack very similar to FF/Safari |
170 | 186 | parseOpera11: function ErrorStackParser$$parseOpera11(error) { |
171 | | - var filtered = _filter(error.stack.split('\n'), function (line) { |
172 | | - return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && |
173 | | - !line.match(/^Error created at/); |
| 187 | + var filtered = _filter(error.stack.split('\n'), function(line) { |
| 188 | + return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/); |
174 | 189 | }, this); |
175 | 190 |
|
176 | | - return _map(filtered, function (line) { |
| 191 | + return _map(filtered, function(line) { |
177 | 192 | var tokens = line.split('@'); |
178 | 193 | var locationParts = this.extractLocation(tokens.pop()); |
179 | 194 | var functionCall = (tokens.shift() || ''); |
|
184 | 199 | if (functionCall.match(/\(([^\)]*)\)/)) { |
185 | 200 | argsRaw = functionCall.replace(/^[^\(]+\(([^\)]*)\)$/, '$1'); |
186 | 201 | } |
187 | | - var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? undefined : argsRaw.split(','); |
188 | | - return new StackFrame(functionName, args, locationParts[0], locationParts[1], locationParts[2], line); |
| 202 | + var args = (argsRaw === undefined || argsRaw === '[arguments not available]') ? |
| 203 | + undefined : argsRaw.split(','); |
| 204 | + return new StackFrame( |
| 205 | + functionName, |
| 206 | + args, |
| 207 | + locationParts[0], |
| 208 | + locationParts[1], |
| 209 | + locationParts[2], |
| 210 | + line); |
189 | 211 | }, this); |
190 | 212 | } |
191 | 213 | }; |
|
0 commit comments