regress-1189077.js 1.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// Copyright 2021 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

const string_max_length = %StringMaxLength();
const longest_double = -2.2250738585105353E-308;
const s18 = "A".repeat(string_max_length - 18);
const s23 = "A".repeat(string_max_length - 23);
const s24 = "A".repeat(string_max_length - 24);
const s25 = "A".repeat(string_max_length - 25);

(function() {
  function f() {
    return s18 + longest_double;
  }

  %PrepareFunctionForOptimization(f);
  assertThrows(f, RangeError);
  %OptimizeFunctionOnNextCall(f);
  assertThrows(f, RangeError);
})();

(function() {
  function f() {
    return s23 + longest_double;
  }

  %PrepareFunctionForOptimization(f);
  assertThrows(f, RangeError);
  %OptimizeFunctionOnNextCall(f);
  assertThrows(f, RangeError);
})();

(function() {
  function f() {
    return s24 + longest_double;
  }

  %PrepareFunctionForOptimization(f);
  assertEquals(string_max_length, f().length);
  %OptimizeFunctionOnNextCall(f);
  assertEquals(string_max_length, f().length);
})();

(function() {
  function f() {
    return s25 + longest_double;
  }

  %PrepareFunctionForOptimization(f);
  assertEquals(string_max_length - 1, f().length);
  %OptimizeFunctionOnNextCall(f);
  assertEquals(string_max_length - 1, f().length);
})();