1 // Copyright 2015 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 assertEquals(0, "".length); 8 assertEquals(1, "a".length); 9 assertEquals(2, ("a" + "b").length); 10 11 function id(x) { return x; } 12 13 function f1(x) { 14 return x.length; 15 } 16 assertEquals(0, f1("")); 17 assertEquals(1, f1("a")); 18 %OptimizeFunctionOnNextCall(f1); 19 assertEquals(2, f1("a" + "b")); 20 assertEquals(3, f1(id("a") + id("b" + id("c")))) 21 22 function f2(x, y, z) { 23 x = x ? "" + y : "" + z; 24 return x.length; 25 } 26 assertEquals(0, f2(true, "", "a")); 27 assertEquals(1, f2(false, "", "a")); 28 %OptimizeFunctionOnNextCall(f2); 29 assertEquals(0, f2(true, "", "a")); 30 assertEquals(1, f2(false, "", "a")); 31 assertEquals(3, f2(true, id("a") + id("b" + id("c")), "")); 32