forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrace-location.js
159 lines (146 loc) · 6.82 KB
/
brace-location.js
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
load("./driver/driver.js");
function foo() {}
function bar() {}
function baz() {}
function testIf(x) {
if (x < 10) { foo(); } else if (x < 20) { bar(); } else { baz() }
}
testIf(9);
// Note, the check will be against the basic block that contains the first matched character.
// So in this following case, the block that contains the '{'.
checkBasicBlock(testIf, "{ foo", ShouldHaveExecuted);
// In this case, it will test the basic block that contains the ' ' character.
checkBasicBlock(testIf, " foo", ShouldHaveExecuted);
checkBasicBlock(testIf, "} else if", ShouldHaveExecuted);
checkBasicBlock(testIf, "else if", ShouldNotHaveExecuted);
checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
checkBasicBlock(testIf, "else {", ShouldNotHaveExecuted);
checkBasicBlock(testIf, "{ baz", ShouldNotHaveExecuted);
checkBasicBlock(testIf, " baz", ShouldNotHaveExecuted);
testIf(21);
checkBasicBlock(testIf, "else if (x < 20)", ShouldHaveExecuted);
checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
checkBasicBlock(testIf, "else {", ShouldHaveExecuted);
checkBasicBlock(testIf, "{ baz", ShouldHaveExecuted);
checkBasicBlock(testIf, " baz", ShouldHaveExecuted);
testIf(11);
checkBasicBlock(testIf, "{ bar", ShouldHaveExecuted);
checkBasicBlock(testIf, " bar", ShouldHaveExecuted);
function testForRegular(x) {
for (var i = 0; i < x; i++) { foo(); } bar();
}
testForRegular(0);
checkBasicBlock(testForRegular, "{ foo", ShouldNotHaveExecuted);
checkBasicBlock(testForRegular, "} bar", ShouldNotHaveExecuted);
checkBasicBlock(testForRegular, " bar", ShouldHaveExecuted);
testForRegular(1);
checkBasicBlock(testForRegular, "{ foo", ShouldHaveExecuted);
checkBasicBlock(testForRegular, "} bar", ShouldHaveExecuted);
function testForIn(x) {
for (var i in x) { foo(); } bar();
}
testForIn({});
checkBasicBlock(testForIn, "{ foo", ShouldNotHaveExecuted);
checkBasicBlock(testForIn, "} bar", ShouldNotHaveExecuted);
checkBasicBlock(testForIn, " bar", ShouldHaveExecuted);
testForIn({foo: 20});
checkBasicBlock(testForIn, "{ foo", ShouldHaveExecuted);
checkBasicBlock(testForIn, "} bar", ShouldHaveExecuted);
function testForOf(x) {
for (var i of x) { foo(); } bar();
}
testForOf([]);
checkBasicBlock(testForOf, "{ foo", ShouldNotHaveExecuted);
checkBasicBlock(testForOf, " foo", ShouldNotHaveExecuted);
checkBasicBlock(testForOf, "} bar", ShouldNotHaveExecuted);
checkBasicBlock(testForOf, " bar", ShouldHaveExecuted);
testForOf([20]);
checkBasicBlock(testForOf, "{ foo", ShouldHaveExecuted);
checkBasicBlock(testForOf, "} bar", ShouldHaveExecuted);
function testWhile(x) {
var i = 0; while (i++ < x) { foo(); } bar();
}
testWhile(0);
checkBasicBlock(testWhile, "{ foo", ShouldNotHaveExecuted);
checkBasicBlock(testWhile, " foo", ShouldNotHaveExecuted);
checkBasicBlock(testWhile, "} bar", ShouldNotHaveExecuted);
checkBasicBlock(testWhile, " bar", ShouldHaveExecuted);
testWhile(1);
checkBasicBlock(testWhile, "{ foo", ShouldHaveExecuted);
checkBasicBlock(testWhile, "} bar", ShouldHaveExecuted);
// No braces tests.
function testIfNoBraces(x) {
if (x < 10) foo(); else if (x < 20) bar(); else baz();
}
testIfNoBraces(9);
checkBasicBlock(testIfNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "; else if", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, " else if", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, " bar", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, "else baz", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, "baz", ShouldNotHaveExecuted);
testIfNoBraces(21);
checkBasicBlock(testIfNoBraces, "else baz", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "baz", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "; else baz", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, "else if (x < 20)", ShouldHaveExecuted);
// Note that the whitespace preceding bar is part of the previous basic block.
// An if statement's if-true basic block text offset begins at the start offset
// of the if-true block, in this case, just the expression "bar()".
checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted);
testIfNoBraces(11);
checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "bar", ShouldHaveExecuted);
function testForRegularNoBraces(x) {
for (var i = 0; i < x; i++) foo(); bar();
}
testForRegularNoBraces(0);
checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForRegularNoBraces, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testForRegularNoBraces, "; bar", ShouldNotHaveExecuted);
checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted);
testForRegularNoBraces(1);
checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForRegularNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted);
function testForInNoBraces(x) {
for (var i in x) foo(); bar();
}
testForInNoBraces({});
checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForInNoBraces, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testForInNoBraces, "; bar", ShouldNotHaveExecuted);
checkBasicBlock(testForInNoBraces, " bar", ShouldHaveExecuted);
testForInNoBraces({foo: 20});
checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForInNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testForInNoBraces, "; bar", ShouldHaveExecuted);
function testForOfNoBraces(x) {
for (var i of x) foo(); bar();
}
testForOfNoBraces([]);
checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForOfNoBraces, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testForOfNoBraces, "; bar", ShouldNotHaveExecuted);
checkBasicBlock(testForOfNoBraces, " bar", ShouldHaveExecuted);
testForOfNoBraces([20]);
checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForOfNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testForOfNoBraces, "; bar", ShouldHaveExecuted);
function testWhileNoBraces(x) {
var i = 0; while (i++ < x) foo(); bar();
}
testWhileNoBraces(0);
checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testWhileNoBraces, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testWhileNoBraces, "; bar", ShouldNotHaveExecuted);
checkBasicBlock(testWhileNoBraces, " bar", ShouldHaveExecuted);
testWhileNoBraces(1);
checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testWhileNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testWhileNoBraces, "; bar", ShouldHaveExecuted);