summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/noExecute-06.js
blob: 50b0be2c69f6e0f6959ab9c5ce71b78630b58195 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Tests that NX disallows debuggee execution for multiple debuggers and
// multiple debuggees.

load(libdir + "asserts.js");
load(libdir + "debuggerNXHelper.js");

var g1 = newGlobal();
var g2 = newGlobal();
var dbg1 = new Debugger;
var dbg2 = new Debugger;

g1w1 = dbg1.addDebuggee(g1);

g1w2 = dbg2.addDebuggee(g1);
g2w = dbg2.addDebuggee(g2);

g1.eval(`
        function d(f) { debugger; return f; }
        function f() { return 42; }
        var o = {
          get p() { return 42; },
          set p(x) { }
        };
        `);

g2.eval(`
        function d(f) { debugger; return f; }
        function f() { return 42; }
        var o = {
          get p() { return 42; },
          set p(x) { }
        };
        `);

var strs = ["f();", "o.p", "o.p = 42"];

var fw1;
dbg1.onDebuggerStatement = (frame) => {
  fw1 = frame.arguments[0];
}
g1.eval('d(f)');
dbg1.onDebuggerStatement = undefined;
var fw2;
dbg2.onDebuggerStatement = (frame) => {
  fw2 = frame.arguments[0];
}
g2.eval('d(f)');
dbg2.onDebuggerStatement = undefined;

function testHook(hookName) {
  var newestG1Frame = dbg1.getNewestFrame();
  if (hookName != 'onNewGlobalObject' &&
      hookName != 'onNewScript' &&
      hookName != 'onNewPromise' &&
      hookName != 'onPromiseSettled')
  {
    var newestG2Frame = dbg2.getNewestFrame();
  }

  for (var s of strs) {
    // When this hook is called, g1 has been locked twice, so even invocation
    // functions do not work.
    assertEq(g1w1.executeInGlobal(s).throw.unsafeDereference() instanceof Debugger.DebuggeeWouldRun, true);
    assertEq(g1w2.executeInGlobal(s).throw.unsafeDereference() instanceof Debugger.DebuggeeWouldRun, true);
    if (newestG1Frame) {
      assertEq(newestG1Frame.eval(s).throw.unsafeDereference() instanceof Debugger.DebuggeeWouldRun, true);
    }
    assertEq(fw1.apply(null).throw.unsafeDereference() instanceof Debugger.DebuggeeWouldRun, true);

    // But g2 has only been locked once and so should work.
    assertEq(g2w.executeInGlobal(s).throw, undefined);
    if (newestG2Frame) {
      assertEq(newestG2Frame.eval(s).throw, undefined);
    }
    assertEq(fw2.apply(null).return, 42);
  }
}

testDebuggerHooksNX(dbg1, g1, () => {
  testDebuggerHooksNX(dbg2, g2, testHook);
});