702f0ff111
Bug: v8:12865 Change-Id: I539a5b0a9c3c78ef9a767de75b71dd06de337d9a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3647351 Reviewed-by: Maya Lekova <mslekova@chromium.org> Commit-Queue: Darius Mercadier <dmercadier@chromium.org> Cr-Commit-Position: refs/heads/main@{#80740}
105 lines
2.3 KiB
JavaScript
105 lines
2.3 KiB
JavaScript
// Copyright 2022 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.
|
|
|
|
const array_at_size = 100;
|
|
|
|
// SMI array
|
|
(() => {
|
|
const A = new Array(array_at_size);
|
|
|
|
for (let i = 0; i < A.length; i++) {
|
|
A[i] = i;
|
|
}
|
|
|
|
assert(%HasSmiElements(A), "A should have SMI elements for this test");
|
|
|
|
// Commonly used to get the last item.
|
|
function testArrayAtNeg1() {
|
|
return A.at(-1);
|
|
}
|
|
|
|
function testArrayAt0() {
|
|
return A.at(0);
|
|
}
|
|
|
|
function testArrayAt20() {
|
|
return A.at(20);
|
|
}
|
|
|
|
function testArrayAt80() {
|
|
return A.at(80);
|
|
}
|
|
|
|
createSuiteWithWarmup("Array.at(-1)-smi", 1, testArrayAtNeg1);
|
|
createSuiteWithWarmup("Array.at(0)-smi", 1, testArrayAt0);
|
|
createSuiteWithWarmup("Array.at(20)-smi", 1, testArrayAt20);
|
|
createSuiteWithWarmup("Array.at(80)-smi", 1, testArrayAt80);
|
|
})();
|
|
|
|
// Double array
|
|
(() => {
|
|
const A = new Array(array_at_size);
|
|
|
|
for (let i = 0; i < A.length; i++) {
|
|
A[i] = i + 0.5;
|
|
}
|
|
|
|
assert(%HasDoubleElements(A), "A should have Double elements for this test");
|
|
|
|
// Commonly used to get the last item.
|
|
function testArrayAtNeg1() {
|
|
return A.at(-1);
|
|
}
|
|
|
|
function testArrayAt0() {
|
|
return A.at(0);
|
|
}
|
|
|
|
function testArrayAt20() {
|
|
return A.at(20);
|
|
}
|
|
|
|
function testArrayAt80() {
|
|
return A.at(80);
|
|
}
|
|
|
|
createSuiteWithWarmup("Array.at(-1)-double", 1, testArrayAtNeg1);
|
|
createSuiteWithWarmup("Array.at(0)-double", 1, testArrayAt0);
|
|
createSuiteWithWarmup("Array.at(20)-double", 1, testArrayAt20);
|
|
createSuiteWithWarmup("Array.at(80)-double", 1, testArrayAt80);
|
|
})();
|
|
|
|
// Object array
|
|
(() => {
|
|
const A = new Array(array_at_size);
|
|
|
|
for (let i = 0; i < A.length; i++) {
|
|
A[i] = { ["p" + i] : i};
|
|
}
|
|
|
|
assert(%HasObjectElements(A), "A should have Object elements for this test");
|
|
|
|
// Commonly used to get the last item.
|
|
function testArrayAtNeg1() {
|
|
return A.at(-1);
|
|
}
|
|
|
|
function testArrayAt0() {
|
|
return A.at(0);
|
|
}
|
|
|
|
function testArrayAt20() {
|
|
return A.at(20);
|
|
}
|
|
|
|
function testArrayAt80() {
|
|
return A.at(80);
|
|
}
|
|
|
|
createSuiteWithWarmup("Array.at(-1)-object", 1, testArrayAtNeg1);
|
|
createSuiteWithWarmup("Array.at(0)-object", 1, testArrayAt0);
|
|
createSuiteWithWarmup("Array.at(20)-object", 1, testArrayAt20);
|
|
createSuiteWithWarmup("Array.at(80)-object", 1, testArrayAt80);
|
|
})();
|