This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 961194 - Pull out stack utils in loader to prevent circular depen…
…dencies in SDK
- Loading branch information
Showing
4 changed files
with
79 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
|
||
}); |