|
3 | 3 | 'use strict'; |
4 | 4 | // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers. |
5 | 5 | if (typeof define === 'function' && define.amd) { |
6 | | - define(['error-stack-parser', 'stack-generator'], factory); |
| 6 | + define(['error-stack-parser', 'stack-generator', 'stacktrace-gps'], factory); |
7 | 7 | } else if (typeof exports === 'object') { |
8 | | - module.exports = factory(require('error-stack-parser'), require('stack-generator')); |
| 8 | + module.exports = factory(require('error-stack-parser'), require('stack-generator'), require('stacktrace-gps')); |
9 | 9 | } else { |
10 | | - root.StackTrace = factory(root.ErrorStackParser, root.StackGenerator); |
| 10 | + root.StackTrace = factory(root.ErrorStackParser, root.StackGenerator, root.StackTraceGPS); |
11 | 11 | } |
12 | | -}(this, function (ErrorStackParser, StackGenerator) { |
| 12 | +}(this, function (ErrorStackParser, StackGenerator, StackTraceGPS) { |
13 | 13 | // { filter: fnRef |
14 | 14 | // sourceMap: ??? |
15 | 15 | // cors: ??? |
|
18 | 18 | // formatter: fnRef |
19 | 19 | // } |
20 | 20 |
|
21 | | - // Do not process or try to enhance filtered StackFrames |
22 | | - // new StackTrace() |
23 | | - // .withEnhancedFunctionNames() |
24 | | - // .withEnhancedSourceLocations() |
25 | | - // .withFilter(fn) |
26 | | - // .withMaxStackSize(10) |
27 | | - // .withFormatter(fn) |
28 | | - // .instrument(fn) |
29 | | - // .get(opts) => Array[StackFrame] |
30 | | - |
31 | 21 | /** |
32 | 22 | * Merge 2 given Objects. If a conflict occurs the second object wins. |
33 | 23 | * Does not do deep merges. |
|
57 | 47 | * @private |
58 | 48 | */ |
59 | 49 | function _isStrictMode() { |
60 | | - return (eval("var __temp = null"), (typeof __temp === "undefined")); |
| 50 | + return (eval("var __temp = null"), (typeof __temp === "undefined")); // jshint ignore:line |
61 | 51 | } |
62 | 52 |
|
63 | 53 | return function StackTrace() { |
64 | 54 | // TODO: utils to facilitate automatic bug reporting |
65 | | - |
| 55 | + this.gps = undefined; |
66 | 56 | this.options = {}; |
67 | 57 |
|
68 | 58 | /** |
|
72 | 62 | */ |
73 | 63 | this.get = function (opts) { |
74 | 64 | try { |
75 | | - throw new Error("From StackTrace.get()"); |
| 65 | + throw new Error('From StackTrace.get()'); |
76 | 66 | } catch (e) { |
77 | | - if (e['stack'] || e['opera#sourceloc']) { |
| 67 | + if (e.stack || e['opera#sourceloc']) { |
78 | 68 | return this.fromError(e, _merge(this.options, opts)); |
79 | 69 | } else { |
80 | 70 | return this.generateArtificially(_merge(this.options, opts)); |
|
91 | 81 | this.fromError = function fromError(error, opts) { |
92 | 82 | opts = _merge(this.options, opts); |
93 | 83 |
|
94 | | - var stackframes = new ErrorStackParser().parse(error); //ErrorStackParser.parse(error) |
| 84 | + var stackframes = ErrorStackParser.parse(error); |
95 | 85 | if (typeof opts.filter === 'function') { |
96 | | - // TODO: stackframes = stackframes.filter(opts.filter); |
97 | | - } |
98 | | - // TODO: apply enhancements here |
99 | | - if (typeof opts.formatter === 'function') { |
100 | | - // TODO: stackframes = stackframes.map(opts.formatter); |
| 86 | + stackframes = stackframes.filter(opts.filter); |
101 | 87 | } |
102 | 88 |
|
| 89 | + stackframes.map(function(sf) { |
| 90 | + if (typeof this.gps !== 'function') { |
| 91 | + this.gps = new StackTraceGPS(); |
| 92 | + } |
| 93 | + this.gps.findFunctionName(sf, function(name) { |
| 94 | + sf.setFunctionName(name); |
| 95 | + return sf; |
| 96 | + }, function(err) { |
| 97 | + return sf; |
| 98 | + }); |
| 99 | + }.bind(this)); |
| 100 | + |
103 | 101 | return stackframes; |
104 | 102 | }; |
105 | 103 |
|
|
111 | 109 | this.generateArtificially = function generateArtificially(opts) { |
112 | 110 | return StackGenerator.backtrace(opts); |
113 | 111 | }; |
114 | | - |
115 | | - this.withFilter = function withFilter(fn) { |
116 | | - if (typeof fn !== 'function') { |
117 | | - throw new TypeError('Can only apply filter with a function') |
118 | | - } |
119 | | - this.options.filter = fn; |
120 | | - return this; |
121 | | - }; |
122 | | - |
123 | | - this.withFormatter = function withFormatter(fn) { |
124 | | - this.options.formatter = fn; |
125 | | - return this; |
126 | | - }; |
127 | | - } |
| 112 | + }; |
128 | 113 | })); |
129 | 114 |
|
0 commit comments