v8/test/mjsunit/regress/regress-v8-12194.js
Marja Hölttä 0d42c9d0b1 [builtins] Unify ArrayPrototypeSlice & ReduceArrayPrototypeSlice
They need to agree about when to delegate to CloneFastJSArray, since it
produces arrays which are potentially COW. If they don't agree, TF
generates code which produces a COW array and then expects it to be
non-COW -> immediate deopt.

This CL gets rid of the discrepancy in the case when there's exactly
one argument and it's the number 0.

Some corner cases remain, e.g., 1st argument not a number but ToInteger
returns 0. These should be extremely rare in the real world.

Bug: v8:12194
Change-Id: I10230245c97f8997da4d79702f29ebff11297229
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3147910
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76745}
2021-09-09 08:48:03 +00:00

75 lines
1.5 KiB
JavaScript

// 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 --opt --no-always-opt --no-stress-opt
// Flags: --deopt-every-n-times=0 --no-force-slow-path
(function TestSliceWithoutParams() {
let array = [0, 1, 2];
function f() {
let array2 = array.slice();
array2[1] = array2[0];
}
%PrepareFunctionForOptimization(f);
f();
%OptimizeFunctionOnNextCall(f);
f();
// Assert that the function was not deoptimized.
assertOptimized(f);
})();
(function TestSliceWithStartZero() {
let array = [0, 1, 2];
function f() {
let array2 = array.slice(0);
array2[1] = array2[0];
}
%PrepareFunctionForOptimization(f);
f();
%OptimizeFunctionOnNextCall(f);
f();
// Assert that the function was not deoptimized.
assertOptimized(f);
})();
(function TestSliceWithStartNonZero() {
let array = [0, 1, 2];
function f() {
let array2 = array.slice(1);
array2[1] = array2[0];
}
%PrepareFunctionForOptimization(f);
f();
%OptimizeFunctionOnNextCall(f);
f();
// Assert that the function was not deoptimized.
assertOptimized(f);
})();
(function TestSliceWithStartZeroEndNonUndefined() {
let array = [0, 1, 2];
function f() {
let array2 = array.slice(0, 1);
array2[1] = array2[0];
}
%PrepareFunctionForOptimization(f);
f();
%OptimizeFunctionOnNextCall(f);
f();
// Assert that the function was not deoptimized.
assertOptimized(f);
})();