Debian Codegraph @

js/src/jit-test/tests/debug/Script-getPossibleBreakpoints-02.js

raw
1
2 var global = newGlobal({newCompartment: true});
3 var dbg = Debugger(global);
4 dbg.onDebuggerStatement = onDebuggerStatement;
5
6 global.eval(`
7 debugger;
8 function f() {
9 var o = {}; // 4
10
11 o.a; o.a; o.a; o.a; // 6
12 o.a; o.a; // 7
13 o.a; o.a; o.a; // 8
14 o.a; // 9
15 } // 10
16 `);
17
18 function onDebuggerStatement(frame) {
19 const fScript = frame.script.getChildScripts()[0];
20
21 const allBreakpoints = fScript.getPossibleBreakpoints();
22 assertEq(allBreakpoints.length, 12);
23
24 assertBPCount({ line: 4 }, 1);
25 assertBPCount({ line: 5 }, 0);
26 assertBPCount({ line: 6 }, 4);
27 assertBPCount({ line: 7 }, 2);
28 assertBPCount({ line: 8 }, 3);
29 assertBPCount({ line: 9 }, 1);
30 assertBPCount({ line: 10 }, 1);
31
32 assertBPCount({ line: 6, minColumn: 8 }, 3);
33 assertBPCount({ line: 6, maxColumn: 17 }, 3);
34 assertBPCount({ line: 6, minColumn: 8, maxColumn: 17 }, 2);
35 assertBPError({ line: 1, minLine: 1 }, "line", "not allowed alongside 'minLine'/'maxLine'");
36 assertBPError({ line: 1, maxLine: 1 }, "line", "not allowed alongside 'minLine'/'maxLine'");
37 assertBPError({ line: "1" }, "line", "not an integer");
38
39 assertBPCount({ minLine: 9 }, 2);
40 assertBPCount({ minLine: 9, minColumn: 1 }, 2);
41 assertBPCount({ minLine: 9, minColumn: 9 }, 1);
42 assertBPError({ minLine: "1" }, "minLine", "not an integer");
43 assertBPError({ minColumn: 2 }, "minColumn", "not allowed without 'line' or 'minLine'");
44 assertBPError({ minLine: 1, minColumn: "2" }, "minColumn", "not a positive integer in valid range");
45 assertBPError({ minLine: 1, minColumn: 0 }, "minColumn", "not a positive integer in valid range");
46 assertBPError({ minLine: 1, minColumn: -1 }, "minColumn", "not a positive integer in valid range");
47
48 assertBPCount({ maxLine: 7 }, 5);
49 assertBPCount({ maxLine: 7, maxColumn: 1 }, 5);
50 assertBPCount({ maxLine: 7, maxColumn: 9 }, 6);
51 assertBPError({ maxLine: "1" }, "maxLine", "not an integer");
52 assertBPError({ maxColumn: 2 }, "maxColumn", "not allowed without 'line' or 'maxLine'");
53 assertBPError({ maxLine: 1, maxColumn: "2" }, "maxColumn", "not a positive integer in valid range");
54 assertBPError({ maxLine: 1, maxColumn: 0 }, "maxColumn", "not a positive integer in valid range");
55 assertBPError({ maxLine: 1, maxColumn: -1 }, "maxColumn", "not a positive integer in valid range");
56
57 assertBPCount({ minLine: 6, maxLine: 8 }, 6);
58 assertBPCount({ minLine: 6, minColumn: 9, maxLine: 8 }, 5);
59 assertBPCount({ minLine: 6, maxLine: 8, maxColumn: 9 }, 7);
60 assertBPCount({ minLine: 6, minColumn: 9, maxLine: 8, maxColumn: 9 }, 6);
61
62 assertBPCount({
63 minOffset: fScript.getPossibleBreakpoints({ line: 6 })[3].offset,
64 }, 8);
65 assertBPError({ minOffset: "1" }, "minOffset", "not an integer");
66 assertBPCount({
67 maxOffset: fScript.getPossibleBreakpoints({ line: 6 })[3].offset,
68 }, 4);
69 assertBPError({ maxOffset: "1" }, "maxOffset", "not an integer");
70 assertBPCount({
71 minOffset: fScript.getPossibleBreakpoints({ line: 6 })[2].offset,
72 maxOffset: fScript.getPossibleBreakpoints({ line: 7 })[1].offset,
73 }, 3);
74
75 function assertBPError(query, field, message) {
76 try {
77 fScript.getPossibleBreakpoints(query);
78 assertEq(false, true);
79 } catch (err) {
80 assertEq(err.message, `getPossibleBreakpoints' '${field}' is ${message}`);
81 }
82 }
83
84 function assertBPCount(query, count) {
85 assertEq(fScript.getPossibleBreakpoints(query).length, count);
86 }
87 };