Commit 1e7e8530 authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

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

In this part: join, toLocaleString

Bug: v8:11111
Change-Id: I66ba85c33aae61a86e162352adb2d4bcf0dbac12
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3757333Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Auto-Submit: Marja Hölttä <marja@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81679}
parent 0c75b813
......@@ -2615,7 +2615,7 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
}
})();
(function JoinToLocaleString() {
function JoinToLocaleString(joinHelper, toLocaleStringHelper) {
for (let ctor of ctors) {
const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
......@@ -2636,14 +2636,14 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
assertEquals('0,2,4,6', fixedLength.join());
assertEquals('0,2,4,6', fixedLength.toLocaleString());
assertEquals('4,6', fixedLengthWithOffset.join());
assertEquals('4,6', fixedLengthWithOffset.toLocaleString());
assertEquals('0,2,4,6', lengthTracking.join());
assertEquals('0,2,4,6', lengthTracking.toLocaleString());
assertEquals('4,6', lengthTrackingWithOffset.join());
assertEquals('4,6', lengthTrackingWithOffset.toLocaleString());
assertEquals('0,2,4,6', joinHelper(fixedLength));
assertEquals('0,2,4,6', toLocaleStringHelper(fixedLength));
assertEquals('4,6', joinHelper(fixedLengthWithOffset));
assertEquals('4,6', toLocaleStringHelper(fixedLengthWithOffset));
assertEquals('0,2,4,6', joinHelper(lengthTracking));
assertEquals('0,2,4,6', toLocaleStringHelper(lengthTracking));
assertEquals('4,6', joinHelper(lengthTrackingWithOffset));
assertEquals('4,6', toLocaleStringHelper(lengthTrackingWithOffset));
// Grow.
gsab.grow(6 * ctor.BYTES_PER_ELEMENT);
......@@ -2657,18 +2657,20 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
// [0, 2, 4, 6, 8, 10, ...] << lengthTracking
// [4, 6, 8, 10, ...] << lengthTrackingWithOffset
assertEquals('0,2,4,6', fixedLength.join());
assertEquals('0,2,4,6', fixedLength.toLocaleString());
assertEquals('4,6', fixedLengthWithOffset.join());
assertEquals('4,6', fixedLengthWithOffset.toLocaleString());
assertEquals('0,2,4,6,8,10', lengthTracking.join());
assertEquals('0,2,4,6,8,10', lengthTracking.toLocaleString());
assertEquals('4,6,8,10', lengthTrackingWithOffset.join());
assertEquals('4,6,8,10', lengthTrackingWithOffset.toLocaleString());
assertEquals('0,2,4,6', joinHelper(fixedLength));
assertEquals('0,2,4,6', toLocaleStringHelper(fixedLength));
assertEquals('4,6', joinHelper(fixedLengthWithOffset));
assertEquals('4,6', toLocaleStringHelper(fixedLengthWithOffset));
assertEquals('0,2,4,6,8,10', joinHelper(lengthTracking));
assertEquals('0,2,4,6,8,10', toLocaleStringHelper(lengthTracking));
assertEquals('4,6,8,10', joinHelper(lengthTrackingWithOffset));
assertEquals('4,6,8,10', toLocaleStringHelper(lengthTrackingWithOffset));
}
})();
}
JoinToLocaleString(TypedArrayJoinHelper, TypedArrayToLocaleStringHelper);
JoinToLocaleString(ArrayJoinHelper, ArrayToLocaleStringHelper);
(function JoinParameterConversionGrows() {
function JoinParameterConversionGrows(joinHelper) {
// Growing + fixed-length TA.
for (let ctor of ctors) {
const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
......@@ -2679,7 +2681,7 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
gsab.grow(6 * ctor.BYTES_PER_ELEMENT);
return '.';
}};
assertEquals('0.0.0.0', fixedLength.join(evil));
assertEquals('0.0.0.0', joinHelper(fixedLength, evil));
}
// Growing + length-tracking TA.
......@@ -2693,11 +2695,13 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
return '.';
}};
// We iterate 4 elements, since it was the starting length.
assertEquals('0.0.0.0', lengthTracking.join(evil));
assertEquals('0.0.0.0', joinHelper(lengthTracking, evil));
}
})();
}
JoinParameterConversionGrows(TypedArrayJoinHelper);
(function ToLocaleStringNumberPrototypeToLocaleStringGrows() {
function ToLocaleStringNumberPrototypeToLocaleStringGrows(
toLocaleStringHelper) {
const oldNumberPrototypeToLocaleString = Number.prototype.toLocaleString;
const oldBigIntPrototypeToLocaleString = BigInt.prototype.toLocaleString;
......@@ -2725,7 +2729,7 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
// We iterate 4 elements since it was the starting length. Resizing doesn't
// affect the TA.
assertEquals('0,0,0,0', fixedLength.toLocaleString());
assertEquals('0,0,0,0', toLocaleStringHelper(fixedLength));
}
// Growing + length-tracking TA.
......@@ -2751,12 +2755,15 @@ LastIndexOfParameterConversionGrows(ArrayLastIndexOfHelper);
}
// We iterate 4 elements since it was the starting length.
assertEquals('0,0,0,0', lengthTracking.toLocaleString());
assertEquals('0,0,0,0', toLocaleStringHelper(lengthTracking));
}
Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString;
BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString;
})();
}
ToLocaleStringNumberPrototypeToLocaleStringGrows(
TypedArrayToLocaleStringHelper);
ToLocaleStringNumberPrototypeToLocaleStringGrows(ArrayToLocaleStringHelper);
(function TestMap() {
for (let ctor of ctors) {
......
......@@ -452,3 +452,12 @@ const ArrayFlatHelper = (ta, ...rest) => {
return Array.prototype.flat.call(ta, ...rest); };
const ArrayFlatMapHelper = (ta, ...rest) => {
return Array.prototype.flatMap.call(ta, ...rest); };
const TypedArrayJoinHelper = (ta, ...rest) => { return ta.join(...rest); }
const ArrayJoinHelper = (ta, ...rest) => {
return Array.prototype.join.call(ta, ...rest); };
const TypedArrayToLocaleStringHelper = (ta, ...rest) => {
return ta.toLocaleString(...rest); }
const ArrayToLocaleStringHelper = (ta, ...rest) => {
return Array.prototype.toLocaleString.call(ta, ...rest); };
......@@ -995,7 +995,29 @@ LastIndexOfParameterConversionDetaches(ArrayLastIndexOfHelper);
}
})();
(function JoinParameterConversionDetaches() {
(function ArrayJoinToLocaleString() {
for (let ctor of ctors) {
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
const fixedLength = new ctor(rab, 0, 4);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
const lengthTracking = new ctor(rab, 0);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
%ArrayBufferDetach(rab);
assertEquals('', ArrayJoinHelper(fixedLength));
assertEquals('', ArrayToLocaleStringHelper(fixedLength));
assertEquals('', ArrayJoinHelper(fixedLengthWithOffset));
assertEquals('', ArrayToLocaleStringHelper(fixedLengthWithOffset));
assertEquals('', ArrayJoinHelper(lengthTracking));
assertEquals('', ArrayToLocaleStringHelper(lengthTracking));
assertEquals('', ArrayJoinHelper(lengthTrackingWithOffset));
assertEquals('', ArrayToLocaleStringHelper(lengthTrackingWithOffset));
}
})();
function JoinParameterConversionDetaches(joinHelper) {
// Detaching + fixed-length TA.
for (let ctor of ctors) {
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
......@@ -1009,7 +1031,7 @@ LastIndexOfParameterConversionDetaches(ArrayLastIndexOfHelper);
// We iterate 4 elements, since it was the starting length, but the TA is
// OOB right after parameter conversion, so all elements are converted to
// the empty string.
assertEquals('...', fixedLength.join(evil));
assertEquals('...', joinHelper(fixedLength, evil));
}
// Detaching + length-tracking TA.
......@@ -1025,11 +1047,14 @@ LastIndexOfParameterConversionDetaches(ArrayLastIndexOfHelper);
// We iterate 4 elements, since it was the starting length, but the TA is
// OOB right after parameter conversion, so all elements are converted to
// the empty string.
assertEquals('...', lengthTracking.join(evil));
assertEquals('...', joinHelper(lengthTracking, evil));
}
})();
}
JoinParameterConversionDetaches(TypedArrayJoinHelper);
JoinParameterConversionDetaches(ArrayJoinHelper);
(function ToLocaleStringNumberPrototypeToLocaleStringDetaches() {
function ToLocaleStringNumberPrototypeToLocaleStringDetaches(
toLocaleStringHelper) {
const oldNumberPrototypeToLocaleString = Number.prototype.toLocaleString;
const oldBigIntPrototypeToLocaleString = BigInt.prototype.toLocaleString;
......@@ -1057,7 +1082,7 @@ LastIndexOfParameterConversionDetaches(ArrayLastIndexOfHelper);
// We iterate 4 elements, since it was the starting length. The TA goes
// OOB after 2 elements.
assertEquals('0,0,,', fixedLength.toLocaleString());
assertEquals('0,0,,', toLocaleStringHelper(fixedLength));
}
// Detaching + length-tracking TA.
......@@ -1084,12 +1109,15 @@ LastIndexOfParameterConversionDetaches(ArrayLastIndexOfHelper);
// We iterate 4 elements, since it was the starting length. The TA goes
// OOB after 2 elements.
assertEquals('0,0,,', lengthTracking.toLocaleString());
assertEquals('0,0,,', toLocaleStringHelper(lengthTracking));
}
Number.prototype.toLocaleString = oldNumberPrototypeToLocaleString;
BigInt.prototype.toLocaleString = oldBigIntPrototypeToLocaleString;
})();
}
ToLocaleStringNumberPrototypeToLocaleStringDetaches(
TypedArrayToLocaleStringHelper);
ToLocaleStringNumberPrototypeToLocaleStringDetaches(ArrayToLocaleStringHelper);
(function MapDetachMidIteration() {
// Orig. array: [0, 2, 4, 6]
......
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