summaryrefslogtreecommitdiffstats
path: root/remote/shared/Stack.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /remote/shared/Stack.sys.mjs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/shared/Stack.sys.mjs')
-rw-r--r--remote/shared/Stack.sys.mjs73
1 files changed, 73 insertions, 0 deletions
diff --git a/remote/shared/Stack.sys.mjs b/remote/shared/Stack.sys.mjs
new file mode 100644
index 0000000000..d0c7f9407d
--- /dev/null
+++ b/remote/shared/Stack.sys.mjs
@@ -0,0 +1,73 @@
+/* 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.
+ *
+ * @typedef {object} StackFrame
+ * @see nsIStackFrame
+ *
+ * @property {string=} asyncCause
+ * Type of asynchronous call by which this frame was invoked.
+ * @property {number} columnNumber
+ * The column number for this stack frame.
+ * @property {string} filename
+ * The source URL for this stack frame.
+ * @property {string} function
+ * SpiderMonkey’s inferred name for this stack frame’s function, or null.
+ * @property {number} lineNumber
+ * The line number for this stack frame (starts with 1).
+ * @property {number} sourceId
+ * 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.
+ *
+ * @param {object} stack
+ * The native stack object to process.
+ *
+ * @returns {Array<StackFrame>=}
+ */
+export function getFramesFromStack(stack) {
+ 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.
+ *
+ * @param {object} frame
+ * The frame to check
+ *
+ * @returns {boolean}
+ * True, if frame is from chrome scope
+ */
+export function isChromeFrame(frame) {
+ return (
+ frame.filename.startsWith("chrome://") ||
+ frame.filename.startsWith("resource://")
+ );
+}