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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
load(libdir + "assert-offset-columns.js");
// getColumnOffsets correctly places the various parts of a ForStatement.
assertOffsetColumns(
"function f(n) { for (var i = 0; i < n; ++i) hits.push('.'); hits.push('!'); }",
" ^ ^ ^ ^ ^ ^ ^ ^ ^",
// 0 1 2 3 4 5 6 7 8
"0 1 2 4 5 . 3 1 2 4 5 . 3 1 2 4 5 . 3 1 2 6 7 ! 8"
);
// getColumnOffsets correctly places multiple variable declarations.
assertOffsetColumns(
"function f(n){var w0,x1=3,y2=4,z3=9}",
" ^ ^ ^^"
);
// getColumnOffsets correctly places comma separated expressions.
assertOffsetColumns(
"function f(n){print(n),print(n),print(n)}",
" ^ ^^ ^ ^ ^ ^ ^",
// 0 12 3 4 5 6 7
"0 2 1 3 4 3 5 6 5 7"
);
// getColumnOffsets correctly places object properties.
assertOffsetColumns(
// Should hit each property in the object.
"function f(n){var o={a:1,b:2,c:3}}",
" ^^ ^ ^ ^"
);
// getColumnOffsets correctly places array properties.
assertOffsetColumns(
// Should hit each item in the array.
"function f(n){var a=[1,2,n]}",
" ^ ^ ^"
);
// getColumnOffsets correctly places function calls.
assertOffsetColumns(
"function ppppp() { return 1; }\n" +
"function f(){ 1 && ppppp(ppppp()) && new Error() }",
" ^ ^ ^ ^ ^",
// 0 1 2 3 4
"0 2 1 3 4"
);
// getColumnOffsets correctly places the various parts of a SwitchStatement.
assertOffsetColumns(
"function f(n) { switch(n) { default: print(n); } }",
" ^ ^ ^^ ^",
// 0 1 23 4
"0 1 3 2 4"
);
// getColumnOffsets correctly places the various parts of a BreakStatement.
assertOffsetColumns(
"function f(n) { do { print(n); if (n === 3) { break; } } while(false); }",
" ^ ^ ^^ ^ ^ ^ ^",
// 0 1 23 4 5 6 7
"0 1 3 2 4 5 7"
);
// If the loop condition is unreachable, we currently don't report its offset.
assertOffsetColumns(
"function f(n) { do { print(n); break; } while(false); }",
" ^ ^ ^^ ^ ^",
// 0 1 23 4 5
"0 1 3 2 4 5"
);
// getColumnOffsets correctly places the various parts of a ContinueStatement.
assertOffsetColumns(
"function f(n) { do { print(n); continue; } while(false); }",
" ^ ^ ^^ ^ ^ ^",
// 0 1 23 4 5 6
"0 1 3 2 4 5 6"
);
// getColumnOffsets correctly places the various parts of a WithStatement.
assertOffsetColumns(
"function f(n) { with({}) { print(n); } }",
" ^ ^ ^^ ^",
// 0 1 23 4
"0 1 3 2 4"
);
// getColumnOffsets correctly places the various parts of a IfStatement.
assertOffsetColumns(
"function f(n) { if (n == 3) print(n); }",
" ^ ^ ^^ ^",
// 0 1 23 4
"0 1 3 2 4"
);
// getColumnOffsets correctly places the various parts of a IfStatement
// with an if/else
assertOffsetColumns(
"function f(n) { if (n == 2); else if (n === 3) print(n); }",
" ^ ^ ^ ^^ ^",
// 0 1 2 34 5
"0 1 2 4 3 5"
);
// getColumnOffsets correctly places the various parts of a DoWhileStatement.
assertOffsetColumns(
"function f(n) { do { print(n); } while(false); }",
" ^ ^ ^^ ^ ^",
// 0 1 23 4 5
"0 1 3 2 4 5"
);
// getColumnOffsets correctly places the part of normal ::Dot node with identifier root.
assertOffsetColumns(
"var args = [];\n" +
"var obj = { base: { a(){ return { b(){} }; } } };\n" +
"function f(n) { obj.base.a().b(...args); }",
" ^ ^ ^ ^ ^ ^",
// 0 1 2 3 4 5
"0 1 4 2 5"
);
// getColumnOffsets correctly places the part of normal ::Dot node with "this" root.
assertOffsetColumns(
"var args = [];\n" +
"var obj = { base: { a(){ return { b(){} }; } } };\n" +
"var f = function() { this.base.a().b(...args); }.bind(obj);",
" ^ ^ ^ ^ ^ ^",
// 0 1 2 3 4 5
"0 1 4 2 5"
);
// getColumnOffsets correctly places the part of normal ::Dot node with "super" base.
assertOffsetColumns(
"var args = [];\n" +
"var obj = { base: { a(){ return { b(){} }; } } };\n" +
"var f = { __proto__: obj, f(n) { super.base.a().b(...args); } }.f;",
" ^ ^ ^ ^ ^ ^",
// 0 1 2 3 4 5
"0 1 4 2 5"
);
// getColumnOffsets correctly places the part of normal ::Dot node with other base.
assertOffsetColumns(
"var args = [];\n" +
"var obj = { base: { a(){ return { b(){} }; } } };\n" +
"function f(n) { (0, obj).base.a().b(...args); }",
" ^ ^ ^ ^ ^ ^ ^",
// 0 1 2 3 4 5 6
"0 1 2 5 3 6"
);
// getColumnOffsets correctly places the part of folded ::Elem node.
assertOffsetColumns(
"var args = [];\n" +
"var obj = { base: { a(){ return { b(){} }; } } };\n" +
// Constant folding makes the static string behave like a dot access.
"function f(n) { obj.base['a']()['b'](...args); }",
" ^ ^ ^ ^ ^ ^",
// 0 1 2 3 4 5
"0 1 4 2 5"
);
// getColumnOffsets correctly places the part of computed ::Elem node.
assertOffsetColumns(
"var args = [], a = 'a', b = 'b';\n" +
"var obj = { base: { a(){ return { b(){} }; } } };\n" +
"function f(n) { obj.base[a]()[b](...args); }",
" ^ ^ ^^ ^ ^",
// 0 1 23 4 5
"0 1 4 2 5"
);
// getColumnOffsets correctly places the evaluation of ...args when
// OptimizeSpreadCall fails.
assertOffsetColumns(
"var args = [,];\n" +
"var obj = { base: { a(){ return { b(){} }; } } };\n" +
"function f(n) { obj.base.a().b(...args); }",
" ^ ^ ^ ^ ^ ^",
// 0 1 2 3 4 5
"0 1 4 3 2 5"
);
|