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