blob: 0117b8e8e57a14bbce1d626948bbbcd43e4cdf65 [file] [log] [blame]
mark.lam@apple.com1d936142015-12-03 05:42:56 +00001//@ runFTLNoCJIT
2var o1 = {
3 i: 0,
4 valueOf: function() { return this.i; }
5};
6
7result = 0;
8function foo(a, b) {
9 var result = 0;
10 for (var j = 0; j < 10; j++) {
11 if (a > b)
12 result += a * b;
13 else
14 result += b * 1;
15 }
mark.lam@apple.com1aa8de92016-01-05 20:38:46 +000016
17 // Busy work just to allow the DFG and FTL to optimize this out. If the above causes
18 // us to speculation fail out to the baseline, this busy work will take a lot longer
19 // to run.
20 // This loop below also gets the DFG to compile this function sooner.
21 var origResult = result;
22 for (var i = 1; i < 1000; i++)
23 result = result * i;
24 result = origResult < result ? origResult : result;
mark.lam@apple.com1d936142015-12-03 05:42:56 +000025 return result;
26}
27noInline(foo);
28
29var iterations;
30var expectedResult;
31if (this.window) {
32 // The layout test doesn't like too many iterations and may time out.
33 iterations = 10000;
mark.lam@apple.com1aa8de92016-01-05 20:38:46 +000034 expectedResult = 5000495600;
mark.lam@apple.com1d936142015-12-03 05:42:56 +000035} else {
36 iterations = 100000;
mark.lam@apple.com1aa8de92016-01-05 20:38:46 +000037 expectedResult = 500004995600;
mark.lam@apple.com1d936142015-12-03 05:42:56 +000038}
39
40
41for (var i = 0; i <= iterations; i++) {
mark.lam@apple.com1aa8de92016-01-05 20:38:46 +000042 o1.i = i;
43 if (i % 2)
44 result += foo(o1, 10);
45 else
46 result += foo(i, 10);
mark.lam@apple.com1d936142015-12-03 05:42:56 +000047}
48
49if (result != expectedResult)
50 throw "Bad result: " + result;