2021-12-09 23:24:09 +03:00
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An object that contains details of a stack frame.
|
|
|
|
|
*
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @typedef {object} StackFrame
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* @see nsIStackFrame
|
|
|
|
|
*
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @property {string=} asyncCause
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* Type of asynchronous call by which this frame was invoked.
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @property {number} columnNumber
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* The column number for this stack frame.
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @property {string} filename
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* The source URL for this stack frame.
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @property {string} function
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* SpiderMonkey’s inferred name for this stack frame’s function, or null.
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @property {number} lineNumber
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* The line number for this stack frame (starts with 1).
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @property {number} sourceId
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* The process-unique internal integer ID of this source.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a list of stack frames from the given stack.
|
|
|
|
|
*
|
|
|
|
|
* Convert stack objects to the JSON attributes expected by consumers.
|
|
|
|
|
*
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @param {object} stack
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* The native stack object to process.
|
|
|
|
|
*
|
|
|
|
|
* @returns {Array<StackFrame>=}
|
|
|
|
|
*/
|
2022-09-30 14:08:06 +03:00
|
|
|
|
export function getFramesFromStack(stack) {
|
2021-12-09 23:24:09 +03:00
|
|
|
|
if (!stack || (Cu && Cu.isDeadWrapper(stack))) {
|
|
|
|
|
// If the global from which this error came from has been nuked,
|
|
|
|
|
// stack is going to be a dead wrapper.
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const frames = [];
|
|
|
|
|
while (stack) {
|
|
|
|
|
frames.push({
|
|
|
|
|
asyncCause: stack.asyncCause,
|
|
|
|
|
columnNumber: stack.column,
|
|
|
|
|
filename: stack.source,
|
|
|
|
|
functionName: stack.functionDisplayName || "",
|
|
|
|
|
lineNumber: stack.line,
|
|
|
|
|
sourceId: stack.sourceId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
stack = stack.parent || stack.asyncParent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return frames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if a frame is from chrome scope.
|
|
|
|
|
*
|
2023-04-05 19:25:47 +03:00
|
|
|
|
* @param {object} frame
|
2021-12-09 23:24:09 +03:00
|
|
|
|
* The frame to check
|
|
|
|
|
*
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
* True, if frame is from chrome scope
|
|
|
|
|
*/
|
2022-09-30 14:08:06 +03:00
|
|
|
|
export function isChromeFrame(frame) {
|
2021-12-09 23:24:09 +03:00
|
|
|
|
return (
|
|
|
|
|
frame.filename.startsWith("chrome://") ||
|
|
|
|
|
frame.filename.startsWith("resource://")
|
|
|
|
|
);
|
|
|
|
|
}
|