string-concat-deopt.js 2.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax

(() => {
  function f(a) {
    return "abc".concat();
  }

12
  %PrepareFunctionForOptimization(f);
13 14 15 16 17 18 19 20 21 22 23
  assertEquals("abc", f());
  assertEquals("abc", f());
  %OptimizeFunctionOnNextCall(f);
  assertEquals("abc", f());
})();

(() => {
  function f(a) {
    return "abc".concat(a);
  }

24
  %PrepareFunctionForOptimization(f);
25 26 27 28 29 30 31 32 33 34
  assertEquals("abcde", f("de"));
  assertEquals("abcde", f("de"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals("abcde", f("de"));
})();

(() => {
  function f(a) {
    return "abc".concat(a);
  }
35 36

  %PrepareFunctionForOptimization(f);
37 38 39 40 41 42 43 44 45 46 47
  assertEquals("abcde", f("de"));
  assertEquals("abcde", f("de"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals("abc1", f(1));
})();

(() => {
  function f(a) {
    return "abc".concat(a);
  }

48
  %PrepareFunctionForOptimization(f);
49 50 51
  assertEquals("abcde", f("de"));
  assertEquals("abcde", f("de"));
  %OptimizeFunctionOnNextCall(f);
52
  var s = "x".repeat(%StringMaxLength());
53 54 55 56 57 58 59 60 61
  assertThrows(() => f(s), RangeError);
})();


(() => {
  function f(a) {
    return "ab".concat("c");
  }

62
  %PrepareFunctionForOptimization(f);
63 64 65 66 67 68 69 70 71 72 73
  assertEquals("abc", f());
  assertEquals("abc", f());
  %OptimizeFunctionOnNextCall(f);
  assertEquals("abc", f());
})();

(() => {
  function f(a) {
    return "ab".concat("c", a);
  }

74
  %PrepareFunctionForOptimization(f);
75 76 77 78 79 80 81 82 83 84
  assertEquals("abcde", f("de"));
  assertEquals("abcde", f("de"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals("abcde", f("de"));
})();

(() => {
  function f(a) {
    return "ab".concat("c", a);
  }
85 86

  %PrepareFunctionForOptimization(f);
87 88 89 90 91 92 93 94 95 96 97
  assertEquals("abcde", f("de"));
  assertEquals("abcde", f("de"));
  %OptimizeFunctionOnNextCall(f);
  assertEquals("abc1", f(1));
})();

(() => {
  function f(a) {
    return "ab".concat("c", a);
  }

98
  %PrepareFunctionForOptimization(f);
99 100 101
  assertEquals("abcde", f("de"));
  assertEquals("abcde", f("de"));
  %OptimizeFunctionOnNextCall(f);
102
  var s = "x".repeat(%StringMaxLength());
103 104
  assertThrows(() => f(s), RangeError);
})();