summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/error-cause-copied.js
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 /js/src/jit-test/tests/debug/error-cause-copied.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/debug/error-cause-copied.js')
-rw-r--r--js/src/jit-test/tests/debug/error-cause-copied.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/error-cause-copied.js b/js/src/jit-test/tests/debug/error-cause-copied.js
new file mode 100644
index 0000000000..b36c8de164
--- /dev/null
+++ b/js/src/jit-test/tests/debug/error-cause-copied.js
@@ -0,0 +1,50 @@
+// Test that the ErrorCopier copies the optional "cause" property of error objects.
+
+let g = newGlobal({newCompartment: true});
+let dbg = new Debugger(g);
+let hits = 0;
+dbg.onDebuggerStatement = function (frame) {
+ hits++;
+
+ // Use |getVariable()| so we can easily throw our custom error from the
+ // with-statement scope.
+ let caught;
+ try {
+ frame.environment.getVariable("x");
+ } catch (e) {
+ caught = e;
+ }
+
+ // The ErrorCopier copied error, so |caught| isn't equal to |g.error|.
+ assertEq(caught !== g.error, true);
+
+ // Ensure the "cause" property is correctly copied.
+ assertEq(caught.cause, g.cause);
+};
+
+// The error must be same-compartment with the debugger compartment for the
+// ErrorCopier.
+g.eval(`
+ var cause = new Object();
+ var error = new Error("", {cause});
+`);
+
+// Scope must be outside of debugger compartment to avoid triggering a
+// DebuggeeWouldRun error.
+let scope = {
+ get x() {
+ throw g.error;
+ }
+};
+
+g.eval(`
+ function f(scope) {
+ with (scope) {
+ debugger;
+ }
+ }
+`);
+
+g.f(scope);
+
+assertEq(hits, 1);