summaryrefslogtreecommitdiffstats
path: root/devtools/shared/platform/stack.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /devtools/shared/platform/stack.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/platform/stack.js')
-rw-r--r--devtools/shared/platform/stack.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/devtools/shared/platform/stack.js b/devtools/shared/platform/stack.js
new file mode 100644
index 0000000000..65ff644091
--- /dev/null
+++ b/devtools/shared/platform/stack.js
@@ -0,0 +1,64 @@
+/* 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/. */
+
+// A few wrappers for stack-manipulation. This version of the module
+// is used in chrome code.
+
+"use strict";
+
+/**
+ * Return the Nth path from the stack excluding substr.
+ *
+ * @param {Number}
+ * n the Nth path from the stack to describe.
+ * @param {String} substr
+ * A segment of the path that should be excluded.
+ */
+function getNthPathExcluding(n, substr) {
+ let stack = Components.stack.formattedStack.split("\n");
+
+ // Remove this method from the stack
+ stack = stack.splice(1);
+
+ stack = stack.map(line => {
+ if (line.includes(" -> ")) {
+ return line.split(" -> ")[1];
+ }
+ return line;
+ });
+
+ if (substr) {
+ stack = stack.filter(line => {
+ return line && !line.includes(substr);
+ });
+ }
+
+ if (!stack[n]) {
+ n = 0;
+ }
+ return stack[n] || "";
+}
+
+/**
+ * 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.getNthPathExcluding = getNthPathExcluding;
+exports.getStack = getStack;