Bug 1869043 add a main thread record of track audio outputs r=padenot
[gecko.git] / remote / shared / Stack.sys.mjs
blobd0c7f9407d46b92ab0033de362c616820f7dfe68
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/. */
5 /**
6  * An object that contains details of a stack frame.
7  *
8  * @typedef {object} StackFrame
9  * @see nsIStackFrame
10  *
11  * @property {string=} asyncCause
12  *     Type of asynchronous call by which this frame was invoked.
13  * @property {number} columnNumber
14  *     The column number for this stack frame.
15  * @property {string} filename
16  *     The source URL for this stack frame.
17  * @property {string} function
18  *     SpiderMonkey’s inferred name for this stack frame’s function, or null.
19  * @property {number} lineNumber
20  *     The line number for this stack frame (starts with 1).
21  * @property {number} sourceId
22  *     The process-unique internal integer ID of this source.
23  */
25 /**
26  * Return a list of stack frames from the given stack.
27  *
28  * Convert stack objects to the JSON attributes expected by consumers.
29  *
30  * @param {object} stack
31  *     The native stack object to process.
32  *
33  * @returns {Array<StackFrame>=}
34  */
35 export function getFramesFromStack(stack) {
36   if (!stack || (Cu && Cu.isDeadWrapper(stack))) {
37     // If the global from which this error came from has been nuked,
38     // stack is going to be a dead wrapper.
39     return null;
40   }
42   const frames = [];
43   while (stack) {
44     frames.push({
45       asyncCause: stack.asyncCause,
46       columnNumber: stack.column,
47       filename: stack.source,
48       functionName: stack.functionDisplayName || "",
49       lineNumber: stack.line,
50       sourceId: stack.sourceId,
51     });
53     stack = stack.parent || stack.asyncParent;
54   }
56   return frames;
59 /**
60  * Check if a frame is from chrome scope.
61  *
62  * @param {object} frame
63  *     The frame to check
64  *
65  * @returns {boolean}
66  *     True, if frame is from chrome scope
67  */
68 export function isChromeFrame(frame) {
69   return (
70     frame.filename.startsWith("chrome://") ||
71     frame.filename.startsWith("resource://")
72   );