summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/error-cause-copied.js
diff options
context:
space:
mode:
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);