mark.lam@apple.com | 1d93614 | 2015-12-03 05:42:56 +0000 | [diff] [blame] | 1 | //@ runFTLNoCJIT |
| 2 | var o1 = { |
| 3 | i: 0, |
| 4 | valueOf: function() { return this.i; } |
| 5 | }; |
| 6 | |
| 7 | result = 0; |
| 8 | function 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.com | 1aa8de9 | 2016-01-05 20:38:46 +0000 | [diff] [blame] | 16 | |
| 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.com | 1d93614 | 2015-12-03 05:42:56 +0000 | [diff] [blame] | 25 | return result; |
| 26 | } |
| 27 | noInline(foo); |
| 28 | |
| 29 | var iterations; |
| 30 | var expectedResult; |
| 31 | if (this.window) { |
| 32 | // The layout test doesn't like too many iterations and may time out. |
| 33 | iterations = 10000; |
mark.lam@apple.com | 1aa8de9 | 2016-01-05 20:38:46 +0000 | [diff] [blame] | 34 | expectedResult = 5000495600; |
mark.lam@apple.com | 1d93614 | 2015-12-03 05:42:56 +0000 | [diff] [blame] | 35 | } else { |
| 36 | iterations = 100000; |
mark.lam@apple.com | 1aa8de9 | 2016-01-05 20:38:46 +0000 | [diff] [blame] | 37 | expectedResult = 500004995600; |
mark.lam@apple.com | 1d93614 | 2015-12-03 05:42:56 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | |
| 41 | for (var i = 0; i <= iterations; i++) { |
mark.lam@apple.com | 1aa8de9 | 2016-01-05 20:38:46 +0000 | [diff] [blame] | 42 | o1.i = i; |
| 43 | if (i % 2) |
| 44 | result += foo(o1, 10); |
| 45 | else |
| 46 | result += foo(i, 10); |
mark.lam@apple.com | 1d93614 | 2015-12-03 05:42:56 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | if (result != expectedResult) |
| 50 | throw "Bad result: " + result; |