string-deopt.js 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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 --opt --no-always-opt

(()=> {
  function f(a, b, c) {
    return a.indexOf(b, c);
10 11
  };
  %PrepareFunctionForOptimization(f);
12 13 14 15
  f("abc", "de", 1);
  f("abc", "de", 1);
  %OptimizeFunctionOnNextCall(f);
  f("abc", "de", {});
16
  %PrepareFunctionForOptimization(f);
17 18 19 20 21 22 23 24
  %OptimizeFunctionOnNextCall(f);
  f("abc", "de", {});
  assertOptimized(f);
})();

(()=> {
  function f(a, b, c) {
    return a.indexOf(b, c);
25 26
  };
  %PrepareFunctionForOptimization(f);
27 28 29 30
  f("abc", "de", 1);
  f("abc", "de", 1);
  %OptimizeFunctionOnNextCall(f);
  f("abc", {}, 1);
31
  %PrepareFunctionForOptimization(f);
32 33 34 35
  %OptimizeFunctionOnNextCall(f);
  f("abc", {}, 1);
  assertOptimized(f);
})();
36 37 38 39

(()=> {
  function f(a, b, c) {
    return a.substring(b, c);
40 41
  };
  %PrepareFunctionForOptimization(f);
42 43 44 45
  f("abcde", 1, 4);
  f("abcde", 1, 4);
  %OptimizeFunctionOnNextCall(f);
  f("abcde", 1, {});
46
  %PrepareFunctionForOptimization(f);
47 48 49 50 51 52 53 54
  %OptimizeFunctionOnNextCall(f);
  f("abcde", 1, {});
  assertOptimized(f);
})();

(()=> {
  function f(a, b, c) {
    return a.substring(b, c);
55 56
  };
  %PrepareFunctionForOptimization(f);
57 58 59 60
  f("abcde", 1, 4);
  f("abcde", 1, 4);
  %OptimizeFunctionOnNextCall(f);
  f("abcde", {}, 4);
61
  %PrepareFunctionForOptimization(f);
62 63 64 65
  %OptimizeFunctionOnNextCall(f);
  f("abcde", {}, 4);
  assertOptimized(f);
})();