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