1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const EXPORTED_SYMBOLS = ["getFramesFromStack", "isChromeFrame"];
10 * An object that contains details of a stack frame.
12 * @typedef {Object} StackFrame
15 * @property {String=} asyncCause
16 * Type of asynchronous call by which this frame was invoked.
17 * @property {Number} columnNumber
18 * The column number for this stack frame.
19 * @property {String} filename
20 * The source URL for this stack frame.
21 * @property {String} function
22 * SpiderMonkey’s inferred name for this stack frame’s function, or null.
23 * @property {Number} lineNumber
24 * The line number for this stack frame (starts with 1).
25 * @property {Number} sourceId
26 * The process-unique internal integer ID of this source.
30 * Return a list of stack frames from the given stack.
32 * Convert stack objects to the JSON attributes expected by consumers.
34 * @param {Object} stack
35 * The native stack object to process.
37 * @returns {Array<StackFrame>=}
39 function getFramesFromStack(stack) {
40 if (!stack || (Cu && Cu.isDeadWrapper(stack))) {
41 // If the global from which this error came from has been nuked,
42 // stack is going to be a dead wrapper.
49 asyncCause: stack.asyncCause,
50 columnNumber: stack.column,
51 filename: stack.source,
52 functionName: stack.functionDisplayName || "",
53 lineNumber: stack.line,
54 sourceId: stack.sourceId,
57 stack = stack.parent || stack.asyncParent;
64 * Check if a frame is from chrome scope.
66 * @param {Object} frame
70 * True, if frame is from chrome scope
72 function isChromeFrame(frame) {
74 frame.filename.startsWith("chrome://") ||
75 frame.filename.startsWith("resource://")