summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib/debuggerNXHelper.js
blob: 61792da84d07521a7156127692f0b4098f63f520 (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
82
83
84
85
86
87
88
89
90
function testDebuggerHooksNX(dbg, g, testHook) {
  function testDebuggerHook(hookName, trigger) {
    var hit = false;
    dbg[hookName] = () => {
      hit = true;
      dbg[hookName] = undefined;
      testHook(hookName);
    };
    trigger();
    assertEq(hit, true);
  }

  // Hooks on the Debugger instance itself.
  testDebuggerHook("onDebuggerStatement",
                   () => { g.eval("debugger;"); });

  testDebuggerHook("onExceptionUnwind",
                   () => {
                     try {
                       g.eval("throw 42;");
                     } catch (e) {
                       assertEq(e, 42);
                     }
                   });

  testDebuggerHook("onNewScript",
                   () => { g.eval("42"); });

  testDebuggerHook("onEnterFrame",
                   () => { g.eval("(() => {})()"); });

  testDebuggerHook("onNewGlobalObject",
                   () => { newGlobal(); });

  if ('Promise' in g) {
      testDebuggerHook("onNewPromise",
                       () => { new g.Promise(()=>{}); });

      testDebuggerHook("onPromiseSettled",
                       () => {
                         var p = new g.Promise(()=>{});
                         g.settlePromiseNow(p);
                       });
  }

  // Hooks on frames.
  var onStepHit = false;
  var onPopHit = false;
  dbg.onEnterFrame = (frame) => {
    dbg.onEnterFrame = undefined;

    frame.onStep = () => {
      onStepHit = true;
      frame.onStep = undefined;
      testHook("onStep");
    };

    frame.onPop = () => {
      onPopHit = true;
      testHook("onPop");
    };
  };
  g.eval("42");
  assertEq(onStepHit, true);

  // We can't actually assert that onPop executed because there's one test
  // that tests NX works across a removeDebuggee/addDebuggee toggle. The
  // removeDebuggee purges D.F instances, so the onPop won't be called even
  // when the global is re-added.
  //assertEq(onPopHit, true);

  // Breakpoints
  var breakpointHits = 0;
  dbg.onDebuggerStatement = (frame) => {
    dbg.onDebuggerStatement = undefined;
    var line0 = frame.script.getOffsetLocation(frame.offset).lineNumber;
    var offs = frame.script.getLineOffsets(line0 + 1);
    for (let i = 0; i < offs.length; i++) {
      frame.script.setBreakpoint(offs[i], {
        hit: () => {
          breakpointHits++;
          testHook("breakpoint");
        }
      });
    }
  };
  g.eval(`debugger;
         s = 'a'`);
  assertEq(breakpointHits >= 1, true);
}