summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Debugger-adoptFrame.js
blob: f5a911fe6ced43550a6bf981fd0a768e884145ae (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
// validate the common behavior of of Debugger.adoptFrame

load(libdir + "asserts.js");

const g = newGlobal({ newCompartment: true });

const dbg1 = new Debugger();
const gDO1 = dbg1.addDebuggee(g);

let suspendedFrame;
dbg1.onDebuggerStatement = function() {
  // Test working with an onStack frame.
  const frame1 = dbg1.getNewestFrame();

  const dbg = new Debugger();
  assertErrorMessage(
    () => dbg.adoptFrame(frame1),
    Error,
    "Debugger.Frame's global is not a debuggee"
  );

  dbg.addDebuggee(g);

  const frame2 = dbg.adoptFrame(frame1);

  assertMatchingFrame(frame1, frame2);

  suspendedFrame = frame1;
};
const generator = g.eval(`
function* fn() {
  debugger;
  yield;
}
fn();
`);
generator.next();

(function() {
  // Test working with a suspended generator frame.
  const dbg = new Debugger();
  assertErrorMessage(
    () => dbg.adoptFrame(suspendedFrame),
    Error,
    "Debugger.Frame's global is not a debuggee"
  );

  dbg.addDebuggee(g);

  const frame2 = dbg.adoptFrame(suspendedFrame);

  assertMatchingFrame(frame2, suspendedFrame);
})();

generator.next();
const deadFrame = suspendedFrame;

(function() {
  // Test working with a dead frame.
  const dbg = new Debugger();

  // This doesn't throw because the dead frame doesn't have any
  // debuggee-specific data associated with it anymore.
  dbg.adoptFrame(deadFrame);

  dbg.addDebuggee(g);

  const frame2 = dbg.adoptFrame(deadFrame);

  assertMatchingFrame(frame2, deadFrame);
})();

function assertMatchingFrame(frame1, frame2) {
  assertEq(frame2.onStack, frame1.onStack);
  assertEq(frame2.terminated, frame1.terminated);

  if (!frame2.terminated) {
    assertEq(frame2.type, frame1.type);
    assertEq(frame2.offset, frame1.offset);
  }
}