forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop-statements.js
78 lines (56 loc) · 1.9 KB
/
loop-statements.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
var hasBasicBlockExecuted = $vm.hasBasicBlockExecuted;
load("./driver/driver.js");
function forRegular(limit) {
var sum = 0;
for (var i = 0; i < limit; i++) {
sum += i;
}
return sum;
}
function forIn(o) {
var s = "";
var p;
for (p in o) {
s += p;
}
}
function forOf(a) {
var s = "";
var p;
for (p of a) {
s += p;
}
}
function whileLoop(limit) {
var i = 0;
var sum = 0;
while (i < limit) {
sum += i;
i++;
}
return sum;
}
assert(!hasBasicBlockExecuted(forRegular, "var sum"), "should not have executed yet.");
forRegular(0);
assert(hasBasicBlockExecuted(forRegular, "var sum"), "should have executed.");
assert(!hasBasicBlockExecuted(forRegular, "sum += i"), "should not have executed yet.");
forRegular(1);
assert(hasBasicBlockExecuted(forRegular, "sum += i"), "should have executed.");
assert(!hasBasicBlockExecuted(forIn, "var s"), "should not have executed yet.");
forIn({});
assert(hasBasicBlockExecuted(forIn, "var s"), "should have executed.");
assert(!hasBasicBlockExecuted(forIn, "s += p"), "should not have executed yet.");
forIn({foo: "bar"});
assert(hasBasicBlockExecuted(forIn, "s += p"), "should have executed.");
assert(!hasBasicBlockExecuted(forOf, "var s"), "should not have executed yet.");
forOf([]);
assert(hasBasicBlockExecuted(forOf, "var s"), "should have executed.");
assert(!hasBasicBlockExecuted(forOf, "s += p"), "should not have executed yet.");
forOf(["a"]);
assert(hasBasicBlockExecuted(forOf, "s += p"), "should have executed.");
assert(!hasBasicBlockExecuted(whileLoop, "var sum"), "should not have executed yet.");
whileLoop(0);
assert(hasBasicBlockExecuted(whileLoop, "var sum"), "should have executed.");
assert(!hasBasicBlockExecuted(whileLoop, "sum += i"), "should not have executed yet.");
whileLoop(1);
assert(hasBasicBlockExecuted(whileLoop, "sum += i"), "should have executed.");