summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Script-getPossibleBreakpoints-02.js
blob: 56ea6620d3a0721b1cfd3b764931bfa988ce5c81 (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
var global = newGlobal({newCompartment: true});
var dbg = Debugger(global);
dbg.onDebuggerStatement = onDebuggerStatement;

global.eval(`
  debugger;
  function f() {
    var o = {};         // 4

    o.a; o.a; o.a; o.a; // 6
    o.a; o.a;           // 7
    o.a; o.a; o.a;      // 8
    o.a;                // 9
  }                     // 10
`);

function onDebuggerStatement(frame) {
  const fScript = frame.script.getChildScripts()[0];

  const allBreakpoints = fScript.getPossibleBreakpoints();
  assertEq(allBreakpoints.length, 12);

  assertBPCount({ line: 4 }, 1);
  assertBPCount({ line: 5 }, 0);
  assertBPCount({ line: 6 }, 4);
  assertBPCount({ line: 7 }, 2);
  assertBPCount({ line: 8 }, 3);
  assertBPCount({ line: 9 }, 1);
  assertBPCount({ line: 10 }, 1);

  assertBPCount({ line: 6, minColumn: 7 }, 3);
  assertBPCount({ line: 6, maxColumn: 16 }, 3);
  assertBPCount({ line: 6, minColumn: 7, maxColumn: 16 }, 2);
  assertBPError({ line: 1, minLine: 1 }, "line", "not allowed alongside 'minLine'/'maxLine'");
  assertBPError({ line: 1, maxLine: 1 }, "line", "not allowed alongside 'minLine'/'maxLine'");
  assertBPError({ line: "1" }, "line", "not an integer");

  assertBPCount({ minLine: 9 }, 2);
  assertBPCount({ minLine: 9, minColumn: 0 }, 2);
  assertBPCount({ minLine: 9, minColumn: 8 }, 1);
  assertBPError({ minLine: "1" }, "minLine", "not an integer");
  assertBPError({ minColumn: 1 }, "minColumn", "not allowed without 'line' or 'minLine'");
  assertBPError({ minLine: 1, minColumn: "1" }, "minColumn", "not an integer");

  assertBPCount({ maxLine: 7 }, 5);
  assertBPCount({ maxLine: 7, maxColumn: 0 }, 5);
  assertBPCount({ maxLine: 7, maxColumn: 8 }, 6);
  assertBPError({ maxLine: "1" }, "maxLine", "not an integer");
  assertBPError({ maxColumn: 1 }, "maxColumn", "not allowed without 'line' or 'maxLine'");
  assertBPError({ maxLine: 1, maxColumn: "1" }, "maxColumn", "not an integer");

  assertBPCount({ minLine: 6, maxLine: 8 }, 6);
  assertBPCount({ minLine: 6, minColumn: 8, maxLine: 8 }, 5);
  assertBPCount({ minLine: 6, maxLine: 8, maxColumn: 8 }, 7);
  assertBPCount({ minLine: 6, minColumn: 8, maxLine: 8, maxColumn: 8 }, 6);

  assertBPCount({
    minOffset: fScript.getPossibleBreakpoints({ line: 6 })[3].offset,
  }, 8);
  assertBPError({ minOffset: "1" }, "minOffset", "not an integer");
  assertBPCount({
    maxOffset: fScript.getPossibleBreakpoints({ line: 6 })[3].offset,
  }, 4);
  assertBPError({ maxOffset: "1" }, "maxOffset", "not an integer");
  assertBPCount({
    minOffset: fScript.getPossibleBreakpoints({ line: 6 })[2].offset,
    maxOffset: fScript.getPossibleBreakpoints({ line: 7 })[1].offset,
  }, 3);

  function assertBPError(query, field, message) {
    try {
      fScript.getPossibleBreakpoints(query);
      assertEq(false, true);
    } catch (err) {
      assertEq(err.message, `getPossibleBreakpoints' '${field}' is ${message}`);
    }
  }

  function assertBPCount(query, count) {
    assertEq(fScript.getPossibleBreakpoints(query).length, count);
  }
};