зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1386584 - Remove JSM boilerplate in devtools/shared/platform/chrome/stack;r=ochameau
MozReview-Commit-ID: EgbKH70NsM9 --HG-- extra : rebase_source : 00cb0d2d0732b55ca39d22adc819d9aabb547a5a
This commit is contained in:
Родитель
5d3697a9b0
Коммит
9679ff0b5a
|
@ -7,69 +7,55 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
(function (factory) {
|
||||
// This file might be require()d, but might also be loaded via
|
||||
// Cu.import. Account for the differences here.
|
||||
if (this.module && module.id.indexOf("stack") >= 0) {
|
||||
// require.
|
||||
const {components, Cu} = require("chrome");
|
||||
factory.call(this, components, Cu, exports);
|
||||
} else {
|
||||
// Cu.import.
|
||||
this.isWorker = false;
|
||||
factory.call(this, Components, Components.utils, this);
|
||||
this.EXPORTED_SYMBOLS = ["callFunctionWithAsyncStack", "describeNthCaller",
|
||||
"getStack"];
|
||||
}
|
||||
}).call(this, function (components, Cu, exports) {
|
||||
/**
|
||||
* Return a description of the Nth caller, suitable for logging.
|
||||
*
|
||||
* @param {Number} n the caller to describe
|
||||
* @return {String} a description of the nth caller.
|
||||
*/
|
||||
function describeNthCaller(n) {
|
||||
if (isWorker) {
|
||||
return "";
|
||||
}
|
||||
const { Cu, components } = require("chrome");
|
||||
|
||||
let caller = components.stack;
|
||||
// Do one extra iteration to skip this function.
|
||||
while (n >= 0) {
|
||||
--n;
|
||||
caller = caller.caller;
|
||||
}
|
||||
|
||||
let func = caller.name;
|
||||
let file = caller.filename;
|
||||
if (file.includes(" -> ")) {
|
||||
file = caller.filename.split(/ -> /)[1];
|
||||
}
|
||||
let path = file + ":" + caller.lineNumber;
|
||||
|
||||
return func + "() -> " + path;
|
||||
/**
|
||||
* Return a description of the Nth caller, suitable for logging.
|
||||
*
|
||||
* @param {Number} n the caller to describe
|
||||
* @return {String} a description of the nth caller.
|
||||
*/
|
||||
function describeNthCaller(n) {
|
||||
if (isWorker) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a stack object that can be serialized and, when
|
||||
* deserialized, passed to callFunctionWithAsyncStack.
|
||||
*/
|
||||
function getStack() {
|
||||
return components.stack.caller;
|
||||
let caller = components.stack;
|
||||
// Do one extra iteration to skip this function.
|
||||
while (n >= 0) {
|
||||
--n;
|
||||
caller = caller.caller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like Cu.callFunctionWithAsyncStack but handles the isWorker case
|
||||
* -- |Cu| isn't defined in workers.
|
||||
*/
|
||||
function callFunctionWithAsyncStack(callee, stack, id) {
|
||||
if (isWorker) {
|
||||
return callee();
|
||||
}
|
||||
return Cu.callFunctionWithAsyncStack(callee, stack, id);
|
||||
let func = caller.name;
|
||||
let file = caller.filename;
|
||||
if (file.includes(" -> ")) {
|
||||
file = caller.filename.split(/ -> /)[1];
|
||||
}
|
||||
let path = file + ":" + caller.lineNumber;
|
||||
|
||||
exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack;
|
||||
exports.describeNthCaller = describeNthCaller;
|
||||
exports.getStack = getStack;
|
||||
});
|
||||
return func + "() -> " + path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a stack object that can be serialized and, when
|
||||
* deserialized, passed to callFunctionWithAsyncStack.
|
||||
*/
|
||||
function getStack() {
|
||||
return components.stack.caller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like Cu.callFunctionWithAsyncStack but handles the isWorker case
|
||||
* -- |Cu| isn't defined in workers.
|
||||
*/
|
||||
function callFunctionWithAsyncStack(callee, stack, id) {
|
||||
if (isWorker) {
|
||||
return callee();
|
||||
}
|
||||
return Cu.callFunctionWithAsyncStack(callee, stack, id);
|
||||
}
|
||||
|
||||
exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack;
|
||||
exports.describeNthCaller = describeNthCaller;
|
||||
exports.getStack = getStack;
|
||||
|
|
Загрузка…
Ссылка в новой задаче