|
1 | | -// TODO: AMD/CommonJS/etc wrapper |
2 | | -(function stackParser() { |
3 | | - function StackFrame(functionName, args, srcUrl, lineNumber, columnNumber) { |
| 1 | +// TODO: split into new module |
| 2 | +(function (root, factory) { |
| 3 | + if (typeof define === 'function' && define.amd) { |
| 4 | + define([], factory); |
| 5 | + } else if (typeof exports === 'object') { |
| 6 | + module.exports = factory(); |
| 7 | + } else { |
| 8 | + root.StackFrame = factory(); |
| 9 | + } |
| 10 | +}(this, function () { |
| 11 | + return function StackFrame(functionName, args, srcUrl, lineNumber, columnNumber) { |
4 | 12 | this.fn = functionName; |
5 | 13 | this.args = args; |
6 | 14 | this.src = srcUrl; |
7 | 15 | this.line = lineNumber; |
8 | 16 | this.column = columnNumber; |
9 | 17 | } |
10 | | - |
11 | | - function StackParser() { |
| 18 | +})); |
| 19 | + |
| 20 | +// TODO?: Error.prototype.parseError = function parseError(e) {}; |
| 21 | +(function (root, factory) { |
| 22 | + if (typeof define === 'function' && define.amd) { |
| 23 | + define([], factory); |
| 24 | + } else if (typeof exports === 'object') { |
| 25 | + module.exports = factory(); |
| 26 | + } else { |
| 27 | + root.StackParser = factory(); |
| 28 | + } |
| 29 | +}(this, function () { |
| 30 | + return function StackParser() { |
12 | 31 | this.firefoxSafariStackEntryRegExp = /\S+\:\d+/; |
13 | 32 | this.chromeIEStackEntryRegExp = /\s+at /; |
14 | 33 |
|
|
35 | 54 | " at foo (http://path/to/file.js:20:5)\n" + |
36 | 55 | " at http://path/to/file.js:24:4"*/ |
37 | 56 |
|
38 | | - return error.stack.split('\n').splice(1).map(function(line) { |
| 57 | + return error.stack.split('\n').splice(1).map(function (line) { |
39 | 58 | var tokens = line.split(/\s+/).splice(2); |
40 | 59 | var location = tokens.pop().replace(/[\(\)\s]/g, '').split(':'); |
41 | 60 | var functionName = (!tokens[0] || tokens[0] === 'Anonymous') ? '' : tokens[0]; |
|
49 | 68 | "foo@http://path/to/file.js:82\n" + |
50 | 69 | "[native code]" */ |
51 | 70 |
|
52 | | - return error.stack.split('\n').filter(function(line) { |
| 71 | + return error.stack.split('\n').filter(function (line) { |
53 | 72 | return !!line.match(this.firefoxSafariStackEntryRegExp); |
54 | | - }.bind(this)).map(function(line) { |
| 73 | + }.bind(this)).map(function (line) { |
55 | 74 | var tokens = line.split('@'); |
56 | 75 | var location = tokens.pop().split(':'); |
57 | 76 | var functionName = tokens.shift() || ''; |
|
61 | 80 |
|
62 | 81 | this.parseOpera = function parseOpera(e) { |
63 | 82 | if (!e.stacktrace || (e.message.indexOf('\n') > -1 |
64 | | - && e.message.split('\n').length > e.stacktrace.split('\n').length)) { |
| 83 | + && e.message.split('\n').length > e.stacktrace.split('\n').length)) { |
65 | 84 | return this.parseOpera9(e); |
66 | 85 | } else if (!e.stack) { |
67 | 86 | return this.parseOpera10a(e); |
|
108 | 127 |
|
109 | 128 | // Opera 10.65+ Error.stack very similar to FF/Safari |
110 | 129 | this.parseOpera11 = function parseOpera11(error) { |
111 | | - return error.stack.split('\n').filter(function(line) { |
| 130 | + return error.stack.split('\n').filter(function (line) { |
112 | 131 | return !!line.match(this.firefoxSafariStackEntryRegExp); |
113 | | - }.bind(this)).map(function(line) { |
| 132 | + }.bind(this)).map(function (line) { |
114 | 133 | var tokens = line.split('@'); |
115 | 134 | var location = tokens.pop().split(':'); |
116 | 135 | var functionCall = (tokens.shift() || ''); |
|
120 | 139 | }); |
121 | 140 | } |
122 | 141 | } |
| 142 | +})); |
123 | 143 |
|
124 | | -// Error.prototype.parseError = function parseError(e) {}; |
125 | | - |
126 | | - window.StackFrame = StackFrame; |
127 | | - window.StackParser = StackParser; |
128 | | -})(); |
|
0 commit comments