summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Script-getAllColumnOffsets.js
blob: 1661ca2ad20060dfd1dd77106ef9749dd722f519 (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
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
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 3 4 . 2 1 3 4 . 2 1 3 4 . 2 1 5 6 ! 7"
);

// 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)}",
  "              ^    ^   ^        ^       ^"
);

// 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 2 1 3 4"
);

// getColumnOffsets correctly places the various parts of a SwitchStatement.
assertOffsetColumns(
  "function f(n) { switch(n) { default: print(n); } }",
  "                       ^             ^    ^      ^"
);

// getColumnOffsets correctly places the various parts of a BreakStatement.
assertOffsetColumns(
  "function f(n) { do { print(n); if (n === 3) { break; } } while(false); }",
  "                ^    ^    ^        ^          ^                ^       ^",
  "0 1 2 3 4 6"
);

// If the loop condition is unreachable, we currently don't report its offset.
assertOffsetColumns(
  "function f(n) { do { print(n); break; } while(false); }",
  "                ^    ^    ^    ^                      ^",
);

// getColumnOffsets correctly places the various parts of a ContinueStatement.
assertOffsetColumns(
  "function f(n) { do { print(n); continue; } while(false); }",
  "                ^    ^    ^    ^                 ^       ^"
);

// getColumnOffsets correctly places the various parts of a WithStatement.
assertOffsetColumns(
  "function f(n) { with({}) { print(n); } }",
  "                     ^     ^    ^      ^"
);

// getColumnOffsets correctly places the various parts of a IfStatement.
assertOffsetColumns(
  "function f(n) { if (n == 3) print(n); }",
  "                    ^       ^    ^    ^"
);

// 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); }",
  "                    ^                 ^        ^    ^    ^"
);

// getColumnOffsets correctly places the various parts of a DoWhileStatement.
assertOffsetColumns(
  "function f(n) { do { print(n); } while(false); }",
  "                ^    ^    ^            ^       ^"
);

// 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 3 2 4"
);

// 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 3 2 4"
);

// 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 3 2 4"
);

// 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 4 3 5"
);

// 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 3 2 4"
);

// 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 3 2 4"
);