Debian Codegraph @

js/src/jit-test/tests/debug/Script-getAllColumnOffsets.js

raw
1 load(libdir + "assert-offset-columns.js");
2
3 // getColumnOffsets correctly places the various parts of a ForStatement.
4 assertOffsetColumns(
5 "function f(n) { for (var i = 0; i < n; ++i) hits.push('.'); hits.push('!'); }",
6 " ^ ^ ^ ^ ^ ^ ^ ^ ^",
7 // 0 1 2 3 4 5 6 7 8
8 "0 1 2 4 5 . 3 1 2 4 5 . 3 1 2 4 5 . 3 1 2 6 7 ! 8"
9 );
10
11 // getColumnOffsets correctly places multiple variable declarations.
12 assertOffsetColumns(
13 "function f(n){var w0,x1=3,y2=4,z3=9}",
14 " ^ ^ ^^"
15 );
16
17 // getColumnOffsets correctly places comma separated expressions.
18 assertOffsetColumns(
19 "function f(n){print(n),print(n),print(n)}",
20 " ^ ^^ ^ ^ ^ ^ ^",
21 // 0 12 3 4 5 6 7
22 "0 2 1 3 4 3 5 6 5 7"
23 );
24
25 // getColumnOffsets correctly places object properties.
26 assertOffsetColumns(
27 // Should hit each property in the object.
28 "function f(n){var o={a:1,b:2,c:3}}",
29 " ^^ ^ ^ ^"
30 );
31
32 // getColumnOffsets correctly places array properties.
33 assertOffsetColumns(
34 // Should hit each item in the array.
35 "function f(n){var a=[1,2,n]}",
36 " ^ ^ ^"
37 );
38
39 // getColumnOffsets correctly places function calls.
40 assertOffsetColumns(
41 "function ppppp() { return 1; }\n" +
42 "function f(){ 1 && ppppp(ppppp()) && new Error() }",
43 " ^ ^ ^ ^ ^",
44 // 0 1 2 3 4
45 "0 2 1 3 4"
46 );
47
48 // getColumnOffsets correctly places the various parts of a SwitchStatement.
49 assertOffsetColumns(
50 "function f(n) { switch(n) { default: print(n); } }",
51 " ^ ^ ^^ ^",
52 // 0 1 23 4
53 "0 1 3 2 4"
54 );
55
56 // getColumnOffsets correctly places the various parts of a BreakStatement.
57 assertOffsetColumns(
58 "function f(n) { do { print(n); if (n === 3) { break; } } while(false); }",
59 " ^ ^ ^^ ^ ^ ^ ^",
60 // 0 1 23 4 5 6 7
61 "0 1 3 2 4 5 7"
62 );
63
64 // If the loop condition is unreachable, we currently don't report its offset.
65 assertOffsetColumns(
66 "function f(n) { do { print(n); break; } while(false); }",
67 " ^ ^ ^^ ^ ^",
68 // 0 1 23 4 5
69 "0 1 3 2 4 5"
70 );
71
72 // getColumnOffsets correctly places the various parts of a ContinueStatement.
73 assertOffsetColumns(
74 "function f(n) { do { print(n); continue; } while(false); }",
75 " ^ ^ ^^ ^ ^ ^",
76 // 0 1 23 4 5 6
77 "0 1 3 2 4 5 6"
78 );
79
80 // getColumnOffsets correctly places the various parts of a WithStatement.
81 assertOffsetColumns(
82 "function f(n) { with({}) { print(n); } }",
83 " ^ ^ ^^ ^",
84 // 0 1 23 4
85 "0 1 3 2 4"
86 );
87
88 // getColumnOffsets correctly places the various parts of a IfStatement.
89 assertOffsetColumns(
90 "function f(n) { if (n == 3) print(n); }",
91 " ^ ^ ^^ ^",
92 // 0 1 23 4
93 "0 1 3 2 4"
94 );
95
96 // getColumnOffsets correctly places the various parts of a IfStatement
97 // with an if/else
98 assertOffsetColumns(
99 "function f(n) { if (n == 2); else if (n === 3) print(n); }",
100 " ^ ^ ^ ^^ ^",
101 // 0 1 2 34 5
102 "0 1 2 4 3 5"
103 );
104
105 // getColumnOffsets correctly places the various parts of a DoWhileStatement.
106 assertOffsetColumns(
107 "function f(n) { do { print(n); } while(false); }",
108 " ^ ^ ^^ ^ ^",
109 // 0 1 23 4 5
110 "0 1 3 2 4 5"
111 );
112
113 // getColumnOffsets correctly places the part of normal ::Dot node with identifier root.
114 assertOffsetColumns(
115 "var args = [];\n" +
116 "var obj = { base: { a(){ return { b(){} }; } } };\n" +
117 "function f(n) { obj.base.a().b(...args); }",
118 " ^ ^ ^ ^ ^ ^",
119 // 0 1 2 3 4 5
120 "0 1 4 2 5"
121 );
122
123 // getColumnOffsets correctly places the part of normal ::Dot node with "this" root.
124 assertOffsetColumns(
125 "var args = [];\n" +
126 "var obj = { base: { a(){ return { b(){} }; } } };\n" +
127 "var f = function() { this.base.a().b(...args); }.bind(obj);",
128 " ^ ^ ^ ^ ^ ^",
129 // 0 1 2 3 4 5
130 "0 1 4 2 5"
131 );
132
133 // getColumnOffsets correctly places the part of normal ::Dot node with "super" base.
134 assertOffsetColumns(
135 "var args = [];\n" +
136 "var obj = { base: { a(){ return { b(){} }; } } };\n" +
137 "var f = { __proto__: obj, f(n) { super.base.a().b(...args); } }.f;",
138 " ^ ^ ^ ^ ^ ^",
139 // 0 1 2 3 4 5
140 "0 1 4 2 5"
141 );
142
143 // getColumnOffsets correctly places the part of normal ::Dot node with other base.
144 assertOffsetColumns(
145 "var args = [];\n" +
146 "var obj = { base: { a(){ return { b(){} }; } } };\n" +
147 "function f(n) { (0, obj).base.a().b(...args); }",
148 " ^ ^ ^ ^ ^ ^ ^",
149 // 0 1 2 3 4 5 6
150 "0 1 2 5 3 6"
151 );
152
153 // getColumnOffsets correctly places the part of folded ::Elem node.
154 assertOffsetColumns(
155 "var args = [];\n" +
156 "var obj = { base: { a(){ return { b(){} }; } } };\n" +
157 // Constant folding makes the static string behave like a dot access.
158 "function f(n) { obj.base['a']()['b'](...args); }",
159 " ^ ^ ^ ^ ^ ^",
160 // 0 1 2 3 4 5
161 "0 1 4 2 5"
162 );
163
164 // getColumnOffsets correctly places the part of computed ::Elem node.
165 assertOffsetColumns(
166 "var args = [], a = 'a', b = 'b';\n" +
167 "var obj = { base: { a(){ return { b(){} }; } } };\n" +
168 "function f(n) { obj.base[a]()[b](...args); }",
169 " ^ ^ ^^ ^ ^",
170 // 0 1 23 4 5
171 "0 1 4 2 5"
172 );
173
174 // getColumnOffsets correctly places the evaluation of ...args when
175 // OptimizeSpreadCall fails.
176 assertOffsetColumns(
177 "var args = [,];\n" +
178 "var obj = { base: { a(){ return { b(){} }; } } };\n" +
179 "function f(n) { obj.base.a().b(...args); }",
180 " ^ ^ ^ ^ ^ ^",
181 // 0 1 2 3 4 5
182 "0 1 4 3 2 5"
183 );