-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstackinfo.js
70 lines (60 loc) · 1.85 KB
/
stackinfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var printStackTrace = require('stacktrace-js')
var parsers = require('./tracelineParser')
var mode = require('./exceptionMode')
module.exports = function(ex) {
if(parsers[mode] === undefined)
throw new Error("browser "+mode+" not supported")
var options = undefined
if(ex !== undefined) {
if(mode === 'ie' && ex.number === undefined)
ex.number = 1 // work around for this: https://github.com/stacktracejs/stacktrace.js/issues/80
options = {e:ex, guess: true}
}
var trace = printStackTrace(options)
if(ex === undefined) {
trace.splice(0,4) // strip stacktrace-js internals
}
return parseStacktrace(trace)
}
function TraceInfo(traceline) {
this.traceline = traceline
}
TraceInfo.prototype = {
get file() {
return getInfo(this).file
},
get function() {
return getInfo(this).function
},
get line() {
return getInfo(this).line
},
get column() {
return getInfo(this).column
},
get info() {
return getInfo(this)
}
}
function getInfo(traceInfo) {
if(traceInfo.cache === undefined) {
var info = parsers[mode](traceInfo.traceline)
if(info.line !== undefined)
info.line = parseInt(info.line, 10)
if(info.column !== undefined)
info.column = parseInt(info.column, 10)
traceInfo.cache = info
}
return traceInfo.cache
}
function parseStacktrace(trace) {
var results = []
for(var n = 0; n<trace.length; n++) {
results.push(new TraceInfo(trace[n]))
}
return results
}
// here because i'm lazy, they're here for testing only
module.exports.parsers = parsers
module.exports.mode = mode
module.exports.sourceCache = printStackTrace.implementation.prototype.sourceCache // expose this so you can consolidate caches together from different libraries