Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 1 | // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Flags: --allow-natives-syntax |
| 6 | |
| 7 | function foo() { |
| 8 | return function(c) { |
| 9 | var double_var = [3.0, 3.5][0]; |
| 10 | var literal = c ? [1, double_var] : [double_var, 3.5]; |
| 11 | return literal[0]; |
| 12 | }; |
| 13 | } |
| 14 | |
| 15 | var f1 = foo(); |
| 16 | var f2 = foo(); |
| 17 | |
| 18 | // Both closures point to full code. |
| 19 | f1(false); |
| 20 | f2(false); |
| 21 | |
| 22 | // Optimize f1, but don't initialize the [1, double_var] literal. |
| 23 | %OptimizeFunctionOnNextCall(f1); |
| 24 | f1(false); |
| 25 | |
| 26 | // Initialize the [1, double_var] literal, and transition the boilerplate to |
| 27 | // double. |
| 28 | f2(true); |
| 29 | |
| 30 | // Trick crankshaft into writing double_var at the wrong position. |
| 31 | var l = f1(true); |
| 32 | assertEquals(1, l); |