Commit 0a8bd766 authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[rab/gsab] Tests for Array.p methods, part 6

In this part: shift, unshift, reverse

Bug: v8:11111
Change-Id: I13c156dc401b6a90b3bcccd9261b7240d8dc7498
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3740720Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81596}
parent b9e2e640
......@@ -156,8 +156,8 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js');
}
})();
(function ArrayPushPop() {
// push() and pop() always fail since setting the length fails.
(function ArrayPushPopShiftUnshift() {
// These functions always fail since setting the length fails.
for (let ctor of ctors) {
const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
......@@ -166,22 +166,26 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js');
const lengthTracking = new ctor(gsab, 0);
const lengthTrackingWithOffset = new ctor(gsab, 2 * ctor.BYTES_PER_ELEMENT);
assertThrows(() => {
Array.prototype.push.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(lengthTrackingWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(lengthTrackingWithOffset, 0); }, TypeError);
for (let func of [Array.prototype.push, Array.prototype.unshift]) {
assertThrows(() => {
func.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
func.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
func.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
func.call(lengthTrackingWithOffset, 0); }, TypeError);
}
for (let func of [Array.prototype.pop, Array.prototype.shift]) {
assertThrows(() => {
func.call(fixedLength); }, TypeError);
assertThrows(() => {
func.call(fixedLengthWithOffset); }, TypeError);
assertThrows(() => {
func.call(lengthTracking); }, TypeError);
assertThrows(() => {
func.call(lengthTrackingWithOffset); }, TypeError);
}
}
})();
......@@ -2948,7 +2948,7 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
}
})();
(function Reverse() {
function Reverse(reverseHelper) {
for (let ctor of ctors) {
const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
......@@ -2972,13 +2972,13 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
fixedLength.reverse();
reverseHelper(fixedLength);
assertEquals([6, 4, 2, 0], ToNumbers(wholeArrayView));
fixedLengthWithOffset.reverse();
reverseHelper(fixedLengthWithOffset);
assertEquals([6, 4, 0, 2], ToNumbers(wholeArrayView));
lengthTracking.reverse();
reverseHelper(lengthTracking);
assertEquals([2, 0, 4, 6], ToNumbers(wholeArrayView));
lengthTrackingWithOffset.reverse();
reverseHelper(lengthTrackingWithOffset);
assertEquals([2, 0, 6, 4], ToNumbers(wholeArrayView));
// Grow.
......@@ -2991,16 +2991,18 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
// [0, 2, 4, 6, 8, 10, ...] << lengthTracking
// [4, 6, 8, 10, ...] << lengthTrackingWithOffset
fixedLength.reverse();
reverseHelper(fixedLength);
assertEquals([6, 4, 2, 0, 8, 10], ToNumbers(wholeArrayView));
fixedLengthWithOffset.reverse();
reverseHelper(fixedLengthWithOffset);
assertEquals([6, 4, 0, 2, 8, 10], ToNumbers(wholeArrayView));
lengthTracking.reverse();
reverseHelper(lengthTracking);
assertEquals([10, 8, 2, 0, 4, 6], ToNumbers(wholeArrayView));
lengthTrackingWithOffset.reverse();
reverseHelper(lengthTrackingWithOffset);
assertEquals([10, 8, 6, 4, 0, 2], ToNumbers(wholeArrayView));
}
})();
}
Reverse(TypedArrayReverseHelper);
Reverse(ArrayReverseHelper);
(function SetWithGrowableTarget() {
for (let ctor of ctors) {
......
......@@ -436,3 +436,6 @@ function AssertAtomicsOperationsThrow(ta, index, error) {
const CopyWithinHelper = (ta, ...rest) => { ta.copyWithin(...rest); };
const ArrayCopyWithinHelper = (ta, ...rest) => {
Array.prototype.copyWithin.call(ta, ...rest); };
const TypedArrayReverseHelper = (ta) => { ta.reverse(); }
const ArrayReverseHelper = (ta) => { Array.prototype.reverse.call(ta); };
......@@ -241,8 +241,8 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js');
}
})();
(function ArrayPushPop() {
// push() and pop() always fail since setting the length fails.
(function ArrayPushPopShiftUnshift() {
// These functions always fail since setting the length fails.
for (let ctor of ctors) {
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
......@@ -251,62 +251,38 @@ d8.file.execute('test/mjsunit/typedarray-helpers.js');
const lengthTracking = new ctor(rab, 0);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
assertThrows(() => {
Array.prototype.push.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(lengthTrackingWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(lengthTrackingWithOffset, 0); }, TypeError);
function testAllFuncsThrow() {
for (let func of [Array.prototype.push, Array.prototype.unshift]) {
assertThrows(() => {
func.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
func.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
func.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
func.call(lengthTrackingWithOffset, 0); }, TypeError);
}
for (let func of [Array.prototype.pop, Array.prototype.shift]) {
assertThrows(() => {
func.call(fixedLength); }, TypeError);
assertThrows(() => {
func.call(fixedLengthWithOffset); }, TypeError);
assertThrows(() => {
func.call(lengthTracking); }, TypeError);
assertThrows(() => {
func.call(lengthTrackingWithOffset); }, TypeError);
}
}
testAllFuncsThrow();
rab.resize(0);
assertThrows(() => {
Array.prototype.push.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(lengthTrackingWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(lengthTrackingWithOffset, 0); }, TypeError);
testAllFuncsThrow();
%ArrayBufferDetach(rab);
assertThrows(() => {
Array.prototype.push.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
Array.prototype.push.call(lengthTrackingWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(fixedLength, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(fixedLengthWithOffset, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(lengthTracking, 0); }, TypeError);
assertThrows(() => {
Array.prototype.pop.call(lengthTrackingWithOffset, 0); }, TypeError);
testAllFuncsThrow();
}
})();
......@@ -5567,7 +5567,7 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
}
})();
(function Reverse() {
function Reverse(reverseHelper, oobThrows) {
for (let ctor of ctors) {
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
......@@ -5591,13 +5591,13 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
fixedLength.reverse();
reverseHelper(fixedLength);
assertEquals([6, 4, 2, 0], ToNumbers(wholeArrayView));
fixedLengthWithOffset.reverse();
reverseHelper(fixedLengthWithOffset);
assertEquals([6, 4, 0, 2], ToNumbers(wholeArrayView));
lengthTracking.reverse();
reverseHelper(lengthTracking);
assertEquals([2, 0, 4, 6], ToNumbers(wholeArrayView));
lengthTrackingWithOffset.reverse();
reverseHelper(lengthTrackingWithOffset);
assertEquals([2, 0, 6, 4], ToNumbers(wholeArrayView));
// Shrink so that fixed length TAs go out of bounds.
......@@ -5608,33 +5608,57 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
// [0, 2, 4, ...] << lengthTracking
// [4, ...] << lengthTrackingWithOffset
assertThrows(() => { fixedLength.reverse(); });
assertThrows(() => { fixedLengthWithOffset.reverse(); });
if (oobThrows) {
assertThrows(() => { reverseHelper(fixedLength); });
assertThrows(() => { reverseHelper(fixedLengthWithOffset); });
} else {
reverseHelper(fixedLength);
assertEquals([0, 2, 4], ToNumbers(wholeArrayView));
reverseHelper(fixedLengthWithOffset);
assertEquals([0, 2, 4], ToNumbers(wholeArrayView));
}
lengthTracking.reverse();
reverseHelper(lengthTracking);
assertEquals([4, 2, 0], ToNumbers(wholeArrayView));
lengthTrackingWithOffset.reverse();
reverseHelper(lengthTrackingWithOffset);
assertEquals([4, 2, 0], ToNumbers(wholeArrayView));
// Shrink so that the TAs with offset go out of bounds.
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
WriteData();
assertThrows(() => { fixedLength.reverse(); });
assertThrows(() => { fixedLengthWithOffset.reverse(); });
assertThrows(() => { lengthTrackingWithOffset.reverse(); });
if (oobThrows) {
assertThrows(() => { reverseHelper(fixedLength); });
assertThrows(() => { reverseHelper(fixedLengthWithOffset); });
assertThrows(() => { reverseHelper(lengthTrackingWithOffset); });
} else {
reverseHelper(fixedLength);
assertEquals([0], ToNumbers(wholeArrayView));
reverseHelper(fixedLengthWithOffset);
assertEquals([0], ToNumbers(wholeArrayView));
reverseHelper(lengthTrackingWithOffset);
assertEquals([0], ToNumbers(wholeArrayView));
}
lengthTracking.reverse();
reverseHelper(lengthTracking);
assertEquals([0], ToNumbers(wholeArrayView));
// Shrink to zero.
rab.resize(0);
assertThrows(() => { fixedLength.reverse(); });
assertThrows(() => { fixedLengthWithOffset.reverse(); });
assertThrows(() => { lengthTrackingWithOffset.reverse(); });
lengthTracking.reverse();
if (oobThrows) {
assertThrows(() => { reverseHelper(fixedLength); });
assertThrows(() => { reverseHelper(fixedLengthWithOffset); });
assertThrows(() => { reverseHelper(lengthTrackingWithOffset); });
} else {
reverseHelper(fixedLength);
assertEquals([], ToNumbers(wholeArrayView));
reverseHelper(fixedLengthWithOffset);
assertEquals([], ToNumbers(wholeArrayView));
reverseHelper(lengthTrackingWithOffset);
assertEquals([], ToNumbers(wholeArrayView));
}
reverseHelper(lengthTracking);
assertEquals([], ToNumbers(wholeArrayView));
// Grow so that all TAs are back in-bounds.
......@@ -5647,16 +5671,18 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
// [0, 2, 4, 6, 8, 10, ...] << lengthTracking
// [4, 6, 8, 10, ...] << lengthTrackingWithOffset
fixedLength.reverse();
reverseHelper(fixedLength);
assertEquals([6, 4, 2, 0, 8, 10], ToNumbers(wholeArrayView));
fixedLengthWithOffset.reverse();
reverseHelper(fixedLengthWithOffset);
assertEquals([6, 4, 0, 2, 8, 10], ToNumbers(wholeArrayView));
lengthTracking.reverse();
reverseHelper(lengthTracking);
assertEquals([10, 8, 2, 0, 4, 6], ToNumbers(wholeArrayView));
lengthTrackingWithOffset.reverse();
reverseHelper(lengthTrackingWithOffset);
assertEquals([10, 8, 6, 4, 0, 2], ToNumbers(wholeArrayView));
}
})();
}
Reverse(TypedArrayReverseHelper, true);
Reverse(ArrayReverseHelper, false);
(function SetWithResizableTarget() {
for (let ctor of ctors) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment