]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/controlFlowProfiler/loop-statements.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / controlFlowProfiler / loop-statements.js
1 load("./driver/driver.js");
2
3 function forRegular(limit) {
4 var sum = 0;
5 for (var i = 0; i < limit; i++) {
6 sum += i;
7 }
8
9 return sum;
10 }
11
12 function forIn(o) {
13 var s = "";
14 var p;
15 for (p in o) {
16 s += p;
17 }
18 }
19
20 function forOf(a) {
21 var s = "";
22 var p;
23 for (p of a) {
24 s += p;
25 }
26 }
27
28 function whileLoop(limit) {
29 var i = 0;
30 var sum = 0;
31 while (i < limit) {
32 sum += i;
33 i++;
34 }
35
36 return sum;
37 }
38
39 assert(!hasBasicBlockExecuted(forRegular, "var sum"), "should not have executed yet.");
40
41 forRegular(0);
42 assert(hasBasicBlockExecuted(forRegular, "var sum"), "should have executed.");
43 assert(!hasBasicBlockExecuted(forRegular, "sum += i"), "should not have executed yet.");
44
45 forRegular(1);
46 assert(hasBasicBlockExecuted(forRegular, "sum += i"), "should have executed.");
47
48
49 assert(!hasBasicBlockExecuted(forIn, "var s"), "should not have executed yet.");
50
51 forIn({});
52 assert(hasBasicBlockExecuted(forIn, "var s"), "should have executed.");
53 assert(!hasBasicBlockExecuted(forIn, "s += p"), "should not have executed yet.");
54
55 forIn({foo: "bar"});
56 assert(hasBasicBlockExecuted(forIn, "s += p"), "should have executed.");
57
58
59 assert(!hasBasicBlockExecuted(forOf, "var s"), "should not have executed yet.");
60
61 forOf([]);
62 assert(hasBasicBlockExecuted(forOf, "var s"), "should have executed.");
63 assert(!hasBasicBlockExecuted(forOf, "s += p"), "should not have executed yet.");
64
65 forOf(["a"]);
66 assert(hasBasicBlockExecuted(forOf, "s += p"), "should have executed.");
67
68
69 assert(!hasBasicBlockExecuted(whileLoop, "var sum"), "should not have executed yet.");
70
71 whileLoop(0);
72 assert(hasBasicBlockExecuted(whileLoop, "var sum"), "should have executed.");
73 assert(!hasBasicBlockExecuted(whileLoop, "sum += i"), "should not have executed yet.");
74
75 whileLoop(1);
76 assert(hasBasicBlockExecuted(whileLoop, "sum += i"), "should have executed.");