Update ReadMe.md
[qtwebkit.git] / JSTests / controlFlowProfiler / brace-location.js
blob8663cb8e8d2f73aba9b0fac01cf85bf143fa5e9d
1 load("./driver/driver.js");
3 function foo() {}
4 function bar() {}
5 function baz() {}
7 function testIf(x) {
8     if (x < 10) { foo(); } else if (x < 20) { bar(); } else { baz() }
10 testIf(9);
11 // Note, the check will be against the basic block that contains the first matched character. 
12 // So in this following case, the block that contains the '{'.
13 checkBasicBlock(testIf, "{ foo", ShouldHaveExecuted);
14 // In this case, it will test the basic block that contains the ' ' character.
15 checkBasicBlock(testIf, " foo", ShouldHaveExecuted);
16 checkBasicBlock(testIf, "} else if", ShouldHaveExecuted);
17 checkBasicBlock(testIf, "else if", ShouldNotHaveExecuted);
18 checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
19 checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
20 checkBasicBlock(testIf, "else {", ShouldNotHaveExecuted);
21 checkBasicBlock(testIf, "{ baz", ShouldNotHaveExecuted);
22 checkBasicBlock(testIf, " baz", ShouldNotHaveExecuted);
23 testIf(21);
24 checkBasicBlock(testIf, "else if (x < 20)", ShouldHaveExecuted); 
25 checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted); 
26 checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted); 
27 checkBasicBlock(testIf, "else {", ShouldHaveExecuted); 
28 checkBasicBlock(testIf, "{ baz", ShouldHaveExecuted); 
29 checkBasicBlock(testIf, " baz", ShouldHaveExecuted); 
30 testIf(11);
31 checkBasicBlock(testIf, "{ bar", ShouldHaveExecuted); 
32 checkBasicBlock(testIf, " bar", ShouldHaveExecuted); 
34 function testForRegular(x) {
35     for (var i = 0; i < x; i++) { foo(); } bar();
37 testForRegular(0);
38 checkBasicBlock(testForRegular, "{ foo", ShouldNotHaveExecuted); 
39 checkBasicBlock(testForRegular, "} bar", ShouldNotHaveExecuted); 
40 checkBasicBlock(testForRegular, " bar", ShouldHaveExecuted); 
41 testForRegular(1);
42 checkBasicBlock(testForRegular, "{ foo", ShouldHaveExecuted); 
43 checkBasicBlock(testForRegular, "} bar", ShouldHaveExecuted); 
45 function testForIn(x) {
46     for (var i in x) { foo(); } bar();
48 testForIn({});
49 checkBasicBlock(testForIn, "{ foo", ShouldNotHaveExecuted); 
50 checkBasicBlock(testForIn, "} bar", ShouldNotHaveExecuted); 
51 checkBasicBlock(testForIn, " bar", ShouldHaveExecuted); 
52 testForIn({foo: 20});
53 checkBasicBlock(testForIn, "{ foo", ShouldHaveExecuted); 
54 checkBasicBlock(testForIn, "} bar", ShouldHaveExecuted); 
56 function testForOf(x) {
57     for (var i of x) { foo(); } bar();
59 testForOf([]);
60 checkBasicBlock(testForOf, "{ foo", ShouldNotHaveExecuted); 
61 checkBasicBlock(testForOf, " foo", ShouldNotHaveExecuted); 
62 checkBasicBlock(testForOf, "} bar", ShouldNotHaveExecuted); 
63 checkBasicBlock(testForOf, " bar", ShouldHaveExecuted); 
64 testForOf([20]);
65 checkBasicBlock(testForOf, "{ foo", ShouldHaveExecuted); 
66 checkBasicBlock(testForOf, "} bar", ShouldHaveExecuted); 
68 function testWhile(x) {
69     var i = 0; while (i++ < x) { foo(); } bar();
71 testWhile(0);
72 checkBasicBlock(testWhile, "{ foo", ShouldNotHaveExecuted); 
73 checkBasicBlock(testWhile, " foo", ShouldNotHaveExecuted); 
74 checkBasicBlock(testWhile, "} bar", ShouldNotHaveExecuted); 
75 checkBasicBlock(testWhile, " bar", ShouldHaveExecuted); 
76 testWhile(1);
77 checkBasicBlock(testWhile, "{ foo", ShouldHaveExecuted); 
78 checkBasicBlock(testWhile, "} bar", ShouldHaveExecuted); 
81 // No braces tests.
83 function testIfNoBraces(x) {
84     if (x < 10) foo(); else if (x < 20) bar(); else baz();
86 testIfNoBraces(9);
87 checkBasicBlock(testIfNoBraces, "foo", ShouldHaveExecuted);
88 checkBasicBlock(testIfNoBraces, " foo", ShouldHaveExecuted);
89 checkBasicBlock(testIfNoBraces, "; else if", ShouldHaveExecuted);
90 checkBasicBlock(testIfNoBraces, " else if", ShouldNotHaveExecuted);
91 checkBasicBlock(testIfNoBraces, " bar", ShouldNotHaveExecuted); 
92 checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted); 
93 checkBasicBlock(testIfNoBraces, "else baz", ShouldNotHaveExecuted); 
94 checkBasicBlock(testIfNoBraces, "baz", ShouldNotHaveExecuted); 
95 testIfNoBraces(21);
96 checkBasicBlock(testIfNoBraces, "else baz", ShouldHaveExecuted); 
97 checkBasicBlock(testIfNoBraces, "baz", ShouldHaveExecuted); 
98 checkBasicBlock(testIfNoBraces, "; else baz", ShouldNotHaveExecuted); 
99 checkBasicBlock(testIfNoBraces, "else if (x < 20)", ShouldHaveExecuted);
100 // Note that the whitespace preceding bar is part of the previous basic block.
101 // An if statement's if-true basic block text offset begins at the start offset
102 // of the if-true block, in this case, just the expression "bar()".
103 checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted); 
104 checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted); 
105 testIfNoBraces(11);
106 checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted); 
107 checkBasicBlock(testIfNoBraces, "bar", ShouldHaveExecuted); 
109 function testForRegularNoBraces(x) {
110     for (var i = 0; i < x; i++) foo(); bar();
112 testForRegularNoBraces(0);
113 checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted); 
114 checkBasicBlock(testForRegularNoBraces, "foo", ShouldNotHaveExecuted); 
115 checkBasicBlock(testForRegularNoBraces, "; bar", ShouldNotHaveExecuted); 
116 checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted); 
117 testForRegularNoBraces(1);
118 checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted); 
119 checkBasicBlock(testForRegularNoBraces, "foo", ShouldHaveExecuted); 
120 checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted); 
122 function testForInNoBraces(x) {
123     for (var i in x) foo(); bar();
125 testForInNoBraces({});
126 checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted); 
127 checkBasicBlock(testForInNoBraces, "foo", ShouldNotHaveExecuted); 
128 checkBasicBlock(testForInNoBraces, "; bar", ShouldNotHaveExecuted); 
129 checkBasicBlock(testForInNoBraces, " bar", ShouldHaveExecuted); 
130 testForInNoBraces({foo: 20});
131 checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted); 
132 checkBasicBlock(testForInNoBraces, "foo", ShouldHaveExecuted); 
133 checkBasicBlock(testForInNoBraces, "; bar", ShouldHaveExecuted); 
135 function testForOfNoBraces(x) {
136     for (var i of x) foo(); bar();
138 testForOfNoBraces([]);
139 checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted); 
140 checkBasicBlock(testForOfNoBraces, "foo", ShouldNotHaveExecuted); 
141 checkBasicBlock(testForOfNoBraces, "; bar", ShouldNotHaveExecuted); 
142 checkBasicBlock(testForOfNoBraces, " bar", ShouldHaveExecuted); 
143 testForOfNoBraces([20]);
144 checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted); 
145 checkBasicBlock(testForOfNoBraces, "foo", ShouldHaveExecuted); 
146 checkBasicBlock(testForOfNoBraces, "; bar", ShouldHaveExecuted); 
148 function testWhileNoBraces(x) {
149     var i = 0; while (i++ < x) foo(); bar();
151 testWhileNoBraces(0);
152 checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted); 
153 checkBasicBlock(testWhileNoBraces, "foo", ShouldNotHaveExecuted); 
154 checkBasicBlock(testWhileNoBraces, "; bar", ShouldNotHaveExecuted); 
155 checkBasicBlock(testWhileNoBraces, " bar", ShouldHaveExecuted); 
156 testWhileNoBraces(1);
157 checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted); 
158 checkBasicBlock(testWhileNoBraces, "foo", ShouldHaveExecuted); 
159 checkBasicBlock(testWhileNoBraces, "; bar", ShouldHaveExecuted);