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

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

In this part: every, some

Bug: v8:11111
Change-Id: I2fbaf352606a47b7e6b0708589775656b83366c0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3762572
Commit-Queue: Marja Hölttä <marja@chromium.org>
Auto-Submit: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81740}
parent e501a2b1
......@@ -1263,7 +1263,7 @@ EntriesKeysValuesGrowMidIteration(
EntriesKeysValuesGrowMidIteration(
ArrayEntriesHelper, ArrayKeysHelper, ArrayValuesHelper);
(function EverySome() {
function EverySome(everyHelper, someHelper) {
for (let ctor of ctors) {
const gsab = CreateGrowableSharedArrayBuffer(4 * ctor.BYTES_PER_ELEMENT,
8 * ctor.BYTES_PER_ELEMENT);
......@@ -1296,25 +1296,25 @@ EntriesKeysValuesGrowMidIteration(
return Number(n) > 10;
}
assertFalse(fixedLength.every(div3));
assertTrue(fixedLength.every(even));
assertTrue(fixedLength.some(div3));
assertFalse(fixedLength.some(over10));
assertFalse(everyHelper(fixedLength, div3));
assertTrue(everyHelper(fixedLength, even));
assertTrue(someHelper(fixedLength, div3));
assertFalse(someHelper(fixedLength, over10));
assertFalse(fixedLengthWithOffset.every(div3));
assertTrue(fixedLengthWithOffset.every(even));
assertTrue(fixedLengthWithOffset.some(div3));
assertFalse(fixedLengthWithOffset.some(over10));
assertFalse(everyHelper(fixedLengthWithOffset, div3));
assertTrue(everyHelper(fixedLengthWithOffset, even));
assertTrue(someHelper(fixedLengthWithOffset, div3));
assertFalse(someHelper(fixedLengthWithOffset, over10));
assertFalse(lengthTracking.every(div3));
assertTrue(lengthTracking.every(even));
assertTrue(lengthTracking.some(div3));
assertFalse(lengthTracking.some(over10));
assertFalse(everyHelper(lengthTracking, div3));
assertTrue(everyHelper(lengthTracking, even));
assertTrue(someHelper(lengthTracking, div3));
assertFalse(someHelper(lengthTracking, over10));
assertFalse(lengthTrackingWithOffset.every(div3));
assertTrue(lengthTrackingWithOffset.every(even));
assertTrue(lengthTrackingWithOffset.some(div3));
assertFalse(lengthTrackingWithOffset.some(over10));
assertFalse(everyHelper(lengthTrackingWithOffset, div3));
assertTrue(everyHelper(lengthTrackingWithOffset, even));
assertTrue(someHelper(lengthTrackingWithOffset, div3));
assertFalse(someHelper(lengthTrackingWithOffset, over10));
// Grow.
gsab.grow(6 * ctor.BYTES_PER_ELEMENT);
......@@ -1328,29 +1328,31 @@ EntriesKeysValuesGrowMidIteration(
// [0, 2, 4, 6, 8, 10, ...] << lengthTracking
// [4, 6, 8, 10, ...] << lengthTrackingWithOffset
assertFalse(fixedLength.every(div3));
assertTrue(fixedLength.every(even));
assertTrue(fixedLength.some(div3));
assertFalse(fixedLength.some(over10));
assertFalse(everyHelper(fixedLength, div3));
assertTrue(everyHelper(fixedLength, even));
assertTrue(someHelper(fixedLength, div3));
assertFalse(someHelper(fixedLength, over10));
assertFalse(fixedLengthWithOffset.every(div3));
assertTrue(fixedLengthWithOffset.every(even));
assertTrue(fixedLengthWithOffset.some(div3));
assertFalse(fixedLengthWithOffset.some(over10));
assertFalse(everyHelper(fixedLengthWithOffset, div3));
assertTrue(everyHelper(fixedLengthWithOffset, even));
assertTrue(someHelper(fixedLengthWithOffset, div3));
assertFalse(someHelper(fixedLengthWithOffset, over10));
assertFalse(lengthTracking.every(div3));
assertTrue(lengthTracking.every(even));
assertTrue(lengthTracking.some(div3));
assertFalse(lengthTracking.some(over10));
assertFalse(everyHelper(lengthTracking, div3));
assertTrue(everyHelper(lengthTracking, even));
assertTrue(someHelper(lengthTracking, div3));
assertFalse(someHelper(lengthTracking, over10));
assertFalse(lengthTrackingWithOffset.every(div3));
assertTrue(lengthTrackingWithOffset.every(even));
assertTrue(lengthTrackingWithOffset.some(div3));
assertFalse(lengthTrackingWithOffset.some(over10));
assertFalse(everyHelper(lengthTrackingWithOffset, div3));
assertTrue(everyHelper(lengthTrackingWithOffset, even));
assertTrue(someHelper(lengthTrackingWithOffset, div3));
assertFalse(someHelper(lengthTrackingWithOffset, over10));
}
})();
}
EverySome(TypedArrayEveryHelper, TypedArraySomeHelper);
EverySome(ArrayEveryHelper, ArraySomeHelper);
(function EveryGrowMidIteration() {
function EveryGrowMidIteration(everyHelper) {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
......@@ -1389,7 +1391,7 @@ EntriesKeysValuesGrowMidIteration(
values = [];
growAfter = 2;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertTrue(fixedLength.every(CollectValuesAndGrow));
assertTrue(everyHelper(fixedLength, CollectValuesAndGrow));
assertEquals([0, 2, 4, 6], values);
}
......@@ -1399,7 +1401,7 @@ EntriesKeysValuesGrowMidIteration(
values = [];
growAfter = 1;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertTrue(fixedLengthWithOffset.every(CollectValuesAndGrow));
assertTrue(everyHelper(fixedLengthWithOffset, CollectValuesAndGrow));
assertEquals([4, 6], values);
}
......@@ -1409,7 +1411,7 @@ EntriesKeysValuesGrowMidIteration(
values = [];
growAfter = 2;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertTrue(lengthTracking.every(CollectValuesAndGrow));
assertTrue(everyHelper(lengthTracking, CollectValuesAndGrow));
assertEquals([0, 2, 4, 6], values);
}
......@@ -1419,12 +1421,14 @@ EntriesKeysValuesGrowMidIteration(
values = [];
growAfter = 1;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertTrue(lengthTrackingWithOffset.every(CollectValuesAndGrow));
assertTrue(everyHelper(lengthTrackingWithOffset, CollectValuesAndGrow));
assertEquals([4, 6], values);
}
})();
}
EveryGrowMidIteration(TypedArrayEveryHelper);
EveryGrowMidIteration(ArrayEveryHelper);
(function SomeGrowMidIteration() {
function SomeGrowMidIteration(someHelper) {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
......@@ -1463,7 +1467,7 @@ EntriesKeysValuesGrowMidIteration(
values = [];
growAfter = 2;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertFalse(fixedLength.some(CollectValuesAndGrow));
assertFalse(someHelper(fixedLength, CollectValuesAndGrow));
assertEquals([0, 2, 4, 6], values);
}
......@@ -1474,7 +1478,7 @@ EntriesKeysValuesGrowMidIteration(
gsab = gsab;
growAfter = 1;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertFalse(fixedLengthWithOffset.some(CollectValuesAndGrow));
assertFalse(someHelper(fixedLengthWithOffset, CollectValuesAndGrow));
assertEquals([4, 6], values);
}
......@@ -1484,7 +1488,7 @@ EntriesKeysValuesGrowMidIteration(
values = [];
growAfter = 2;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertFalse(lengthTracking.some(CollectValuesAndGrow));
assertFalse(someHelper(lengthTracking, CollectValuesAndGrow));
assertEquals([0, 2, 4, 6], values);
}
......@@ -1494,10 +1498,12 @@ EntriesKeysValuesGrowMidIteration(
values = [];
growAfter = 1;
growTo = 5 * ctor.BYTES_PER_ELEMENT;
assertFalse(lengthTrackingWithOffset.some(CollectValuesAndGrow));
assertFalse(someHelper(lengthTrackingWithOffset, CollectValuesAndGrow));
assertEquals([4, 6], values);
}
})();
}
SomeGrowMidIteration(TypedArraySomeHelper);
SomeGrowMidIteration(ArraySomeHelper);
function FindFindIndexFindLastFindLastIndex(
findHelper, findIndexHelper, findLastHelper, findLastIndexHelper) {
......
......@@ -486,3 +486,13 @@ const TypedArrayMapHelper = (ta, ...rest) => {
return ta.map(...rest); };
const ArrayMapHelper = (ta, ...rest) => {
return Array.prototype.map.call(ta, ...rest); };
const TypedArrayEveryHelper = (ta, ...rest) => {
return ta.every(...rest); };
const ArrayEveryHelper = (ta, ...rest) => {
return Array.prototype.every.call(ta, ...rest); };
const TypedArraySomeHelper = (ta, ...rest) => {
return ta.some(...rest); };
const ArraySomeHelper = (ta, ...rest) => {
return Array.prototype.some.call(ta, ...rest); };
......@@ -235,7 +235,7 @@ EntriesKeysValues(
EntriesKeysValues(
ArrayEntriesHelper, ArrayKeysHelper, ArrayValuesHelper, false);
(function EveryDetachMidIteration() {
function EveryDetachMidIteration(everyHelper, hasUndefined) {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
......@@ -272,8 +272,12 @@ EntriesKeysValues(
const fixedLength = new ctor(rab, 0, 4);
values = [];
detachAfter = 2;
assertTrue(fixedLength.every(CollectValuesAndDetach));
assertEquals([0, 2, undefined, undefined], values);
assertTrue(everyHelper(fixedLength, CollectValuesAndDetach));
if (hasUndefined) {
assertEquals([0, 2, undefined, undefined], values);
} else {
assertEquals([0, 2], values);
}
}
for (let ctor of ctors) {
......@@ -281,8 +285,12 @@ EntriesKeysValues(
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
values = [];
detachAfter = 1;
assertTrue(fixedLengthWithOffset.every(CollectValuesAndDetach));
assertEquals([4, undefined], values);
assertTrue(everyHelper(fixedLengthWithOffset, CollectValuesAndDetach));
if (hasUndefined) {
assertEquals([4, undefined], values);
} else {
assertEquals([4], values);
}
}
for (let ctor of ctors) {
......@@ -290,8 +298,12 @@ EntriesKeysValues(
const lengthTracking = new ctor(rab, 0);
values = [];
detachAfter = 2;
assertTrue(lengthTracking.every(CollectValuesAndDetach));
assertEquals([0, 2, undefined, undefined], values);
assertTrue(everyHelper(lengthTracking, CollectValuesAndDetach));
if (hasUndefined) {
assertEquals([0, 2, undefined, undefined], values);
} else {
assertEquals([0, 2], values);
}
}
for (let ctor of ctors) {
......@@ -299,12 +311,18 @@ EntriesKeysValues(
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
values = [];
detachAfter = 1;
assertTrue(lengthTrackingWithOffset.every(CollectValuesAndDetach));
assertEquals([4, undefined], values);
assertTrue(everyHelper(lengthTrackingWithOffset, CollectValuesAndDetach));
if (hasUndefined) {
assertEquals([4, undefined], values);
} else {
assertEquals([4], values);
}
}
})();
}
EveryDetachMidIteration(TypedArrayEveryHelper, true);
EveryDetachMidIteration(ArrayEveryHelper, false);
(function SomeDetachMidIteration() {
function SomeDetachMidIteration(someHelper, hasUndefined) {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
......@@ -341,8 +359,12 @@ EntriesKeysValues(
const fixedLength = new ctor(rab, 0, 4);
values = [];
detachAfter = 2;
assertFalse(fixedLength.some(CollectValuesAndDetach));
assertEquals([0, 2, undefined, undefined], values);
assertFalse(someHelper(fixedLength, CollectValuesAndDetach));
if (hasUndefined) {
assertEquals([0, 2, undefined, undefined], values);
} else {
assertEquals([0, 2], values);
}
}
for (let ctor of ctors) {
......@@ -350,8 +372,12 @@ EntriesKeysValues(
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
values = [];
detachAfter = 1;
assertFalse(fixedLengthWithOffset.some(CollectValuesAndDetach));
assertEquals([4, undefined], values);
assertFalse(someHelper(fixedLengthWithOffset, CollectValuesAndDetach));
if (hasUndefined) {
assertEquals([4, undefined], values);
} else {
assertEquals([4], values);
}
}
for (let ctor of ctors) {
......@@ -359,8 +385,12 @@ EntriesKeysValues(
const lengthTracking = new ctor(rab, 0);
values = [];
detachAfter = 2;
assertFalse(lengthTracking.some(CollectValuesAndDetach));
assertEquals([0, 2, undefined, undefined], values);
assertFalse(someHelper(lengthTracking, CollectValuesAndDetach));
if (hasUndefined) {
assertEquals([0, 2, undefined, undefined], values);
} else {
assertEquals([0, 2], values);
}
}
for (let ctor of ctors) {
......@@ -368,10 +398,16 @@ EntriesKeysValues(
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
values = [];
detachAfter = 1;
assertFalse(lengthTrackingWithOffset.some(CollectValuesAndDetach));
assertEquals([4, undefined], values);
assertFalse(someHelper(lengthTrackingWithOffset, CollectValuesAndDetach));
if (hasUndefined) {
assertEquals([4, undefined], values);
} else {
assertEquals([4], values);
}
}
})();
}
SomeDetachMidIteration(TypedArraySomeHelper, true);
SomeDetachMidIteration(ArraySomeHelper, false);
function FindDetachMidIteration(findHelper) {
// 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