This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
/
stack-utils.js
67 lines (60 loc) · 2.13 KB
/
stack-utils.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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
;(function(id, factory) { // Module boilerplate :(
if (typeof(define) === "function") { // RequireJS
define(factory);
} else if (typeof(require) === "function") { // CommonJS
factory.call(this, require, exports, module);
} else if (~String(this).indexOf("BackstagePass")) { // JSM
this[factory.name] = {};
factory(function require(uri) {
var imports = {};
this["Components"].utils.import(uri, imports);
return imports;
}, this[factory.name], { uri: __URI__, id: id });
this.EXPORTED_SYMBOLS = [factory.name];
} else if (~String(this).indexOf("Sandbox")) { // Sandbox
factory(function require(uri) {}, this, { uri: __URI__, id: id });
} else { // Browser or alike
var globals = this
factory(function require(id) {
return globals[id];
}, (globals[id] = {}), { uri: document.location.href + "#" + id, id: id });
}
}).call(this, "stackUtils", function stackUtils (require, exports, module) {
"use strict";
module.metadata = {
"stability": "unstable"
};
function parseURI(uri) { return String(uri).split(" -> ").pop(); }
exports.parseURI = parseURI;
function parseStack(stack) {
let lines = String(stack).split("\n");
return lines.reduce(function(frames, line) {
if (line) {
let atIndex = line.indexOf("@");
let columnIndex = line.lastIndexOf(":");
let fileName = parseURI(line.slice(atIndex + 1, columnIndex));
let lineNumber = parseInt(line.slice(columnIndex + 1));
let name = line.slice(0, atIndex).split("(").shift();
frames.unshift({
fileName: fileName,
name: name,
lineNumber: lineNumber
});
}
return frames;
}, []);
}
exports.parseStack = parseStack;
function serializeStack(frames) {
return frames.reduce(function(stack, frame) {
return frame.name + "@" +
frame.fileName + ":" +
frame.lineNumber + "\n" +
stack;
}, "");
}
exports.serializeStack = serializeStack;
});