summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/error-cause-copied.js
blob: b36c8de16475d48a850095c00632074e2188c120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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);