]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/controlFlowProfiler/brace-location.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / controlFlowProfiler / brace-location.js
CommitLineData
ed1e77d3
A
1load("./driver/driver.js");
2
3function foo() {}
4function bar() {}
5function baz() {}
6
7function testIf(x) {
8 if (x < 10) { foo(); } else if (x < 20) { bar(); } else { baz() }
9}
10testIf(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 '{'.
13checkBasicBlock(testIf, "{ foo", ShouldHaveExecuted);
14// In this case, it will test the basic block that contains the ' ' character.
15checkBasicBlock(testIf, " foo", ShouldHaveExecuted);
16checkBasicBlock(testIf, "} else if", ShouldHaveExecuted);
17checkBasicBlock(testIf, "else if", ShouldNotHaveExecuted);
18checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
19checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
20checkBasicBlock(testIf, "else {", ShouldNotHaveExecuted);
21checkBasicBlock(testIf, "{ baz", ShouldNotHaveExecuted);
22checkBasicBlock(testIf, " baz", ShouldNotHaveExecuted);
23testIf(21);
24checkBasicBlock(testIf, "else if (x < 20)", ShouldHaveExecuted);
25checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
26checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
27checkBasicBlock(testIf, "else {", ShouldHaveExecuted);
28checkBasicBlock(testIf, "{ baz", ShouldHaveExecuted);
29checkBasicBlock(testIf, " baz", ShouldHaveExecuted);
30testIf(11);
31checkBasicBlock(testIf, "{ bar", ShouldHaveExecuted);
32checkBasicBlock(testIf, " bar", ShouldHaveExecuted);
33
34function testForRegular(x) {
35 for (var i = 0; i < x; i++) { foo(); } bar();
36}
37testForRegular(0);
38checkBasicBlock(testForRegular, "{ foo", ShouldNotHaveExecuted);
39checkBasicBlock(testForRegular, "} bar", ShouldNotHaveExecuted);
40checkBasicBlock(testForRegular, " bar", ShouldHaveExecuted);
41testForRegular(1);
42checkBasicBlock(testForRegular, "{ foo", ShouldHaveExecuted);
43checkBasicBlock(testForRegular, "} bar", ShouldHaveExecuted);
44
45function testForIn(x) {
46 for (var i in x) { foo(); } bar();
47}
48testForIn({});
49checkBasicBlock(testForIn, "{ foo", ShouldNotHaveExecuted);
50checkBasicBlock(testForIn, "} bar", ShouldNotHaveExecuted);
51checkBasicBlock(testForIn, " bar", ShouldHaveExecuted);
52testForIn({foo: 20});
53checkBasicBlock(testForIn, "{ foo", ShouldHaveExecuted);
54checkBasicBlock(testForIn, "} bar", ShouldHaveExecuted);
55
56function testForOf(x) {
57 for (var i of x) { foo(); } bar();
58}
59testForOf([]);
60checkBasicBlock(testForOf, "{ foo", ShouldNotHaveExecuted);
61checkBasicBlock(testForOf, " foo", ShouldNotHaveExecuted);
62checkBasicBlock(testForOf, "} bar", ShouldNotHaveExecuted);
63checkBasicBlock(testForOf, " bar", ShouldHaveExecuted);
64testForOf([20]);
65checkBasicBlock(testForOf, "{ foo", ShouldHaveExecuted);
66checkBasicBlock(testForOf, "} bar", ShouldHaveExecuted);
67
68function testWhile(x) {
69 var i = 0; while (i++ < x) { foo(); } bar();
70}
71testWhile(0);
72checkBasicBlock(testWhile, "{ foo", ShouldNotHaveExecuted);
73checkBasicBlock(testWhile, " foo", ShouldNotHaveExecuted);
74checkBasicBlock(testWhile, "} bar", ShouldNotHaveExecuted);
75checkBasicBlock(testWhile, " bar", ShouldHaveExecuted);
76testWhile(1);
77checkBasicBlock(testWhile, "{ foo", ShouldHaveExecuted);
78checkBasicBlock(testWhile, "} bar", ShouldHaveExecuted);
79
80
81// No braces tests.
82
83function testIfNoBraces(x) {
84 if (x < 10) foo(); else if (x < 20) bar(); else baz();
85}
86testIfNoBraces(9);
87checkBasicBlock(testIfNoBraces, "foo", ShouldHaveExecuted);
88checkBasicBlock(testIfNoBraces, " foo", ShouldHaveExecuted);
89checkBasicBlock(testIfNoBraces, "; else if", ShouldHaveExecuted);
90checkBasicBlock(testIfNoBraces, " else if", ShouldNotHaveExecuted);
91checkBasicBlock(testIfNoBraces, " bar", ShouldNotHaveExecuted);
92checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted);
93checkBasicBlock(testIfNoBraces, "else baz", ShouldNotHaveExecuted);
94checkBasicBlock(testIfNoBraces, "baz", ShouldNotHaveExecuted);
95testIfNoBraces(21);
96checkBasicBlock(testIfNoBraces, "else baz", ShouldHaveExecuted);
97checkBasicBlock(testIfNoBraces, "baz", ShouldHaveExecuted);
98checkBasicBlock(testIfNoBraces, "; else baz", ShouldNotHaveExecuted);
99checkBasicBlock(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()".
103checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted);
104checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted);
105testIfNoBraces(11);
106checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted);
107checkBasicBlock(testIfNoBraces, "bar", ShouldHaveExecuted);
108
109function testForRegularNoBraces(x) {
110 for (var i = 0; i < x; i++) foo(); bar();
111}
112testForRegularNoBraces(0);
113checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted);
114checkBasicBlock(testForRegularNoBraces, "foo", ShouldNotHaveExecuted);
115checkBasicBlock(testForRegularNoBraces, "; bar", ShouldNotHaveExecuted);
116checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted);
117testForRegularNoBraces(1);
118checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted);
119checkBasicBlock(testForRegularNoBraces, "foo", ShouldHaveExecuted);
120checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted);
121
122function testForInNoBraces(x) {
123 for (var i in x) foo(); bar();
124}
125testForInNoBraces({});
126checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted);
127checkBasicBlock(testForInNoBraces, "foo", ShouldNotHaveExecuted);
128checkBasicBlock(testForInNoBraces, "; bar", ShouldNotHaveExecuted);
129checkBasicBlock(testForInNoBraces, " bar", ShouldHaveExecuted);
130testForInNoBraces({foo: 20});
131checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted);
132checkBasicBlock(testForInNoBraces, "foo", ShouldHaveExecuted);
133checkBasicBlock(testForInNoBraces, "; bar", ShouldHaveExecuted);
134
135function testForOfNoBraces(x) {
136 for (var i of x) foo(); bar();
137}
138testForOfNoBraces([]);
139checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted);
140checkBasicBlock(testForOfNoBraces, "foo", ShouldNotHaveExecuted);
141checkBasicBlock(testForOfNoBraces, "; bar", ShouldNotHaveExecuted);
142checkBasicBlock(testForOfNoBraces, " bar", ShouldHaveExecuted);
143testForOfNoBraces([20]);
144checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted);
145checkBasicBlock(testForOfNoBraces, "foo", ShouldHaveExecuted);
146checkBasicBlock(testForOfNoBraces, "; bar", ShouldHaveExecuted);
147
148function testWhileNoBraces(x) {
149 var i = 0; while (i++ < x) foo(); bar();
150}
151testWhileNoBraces(0);
152checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted);
153checkBasicBlock(testWhileNoBraces, "foo", ShouldNotHaveExecuted);
154checkBasicBlock(testWhileNoBraces, "; bar", ShouldNotHaveExecuted);
155checkBasicBlock(testWhileNoBraces, " bar", ShouldHaveExecuted);
156testWhileNoBraces(1);
157checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted);
158checkBasicBlock(testWhileNoBraces, "foo", ShouldHaveExecuted);
159checkBasicBlock(testWhileNoBraces, "; bar", ShouldHaveExecuted);