Skip to content

Commit

Permalink
RAB: Integrate staging tests for the .every method
Browse files Browse the repository at this point in the history
of Array.prototype and TypedArray.prototype

This is part of PR tc39#3888 to make reviewing easier.
Includes changes to use the helper ./harness/resizableArrayBufferUtils.js
  • Loading branch information
ioannad committed May 3, 2024
1 parent c95cc68 commit 58af441
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-array.prototype.every
description: >
Array.p.every behaves correctly when receiver is backed by resizable
buffer that is grown mid-iteration
includes: [compareArray.js]
features: [resizable-arraybuffer]
---*/

const ArrayEveryHelper = (ta, values, rab, resizeAfter, resizeTo) => {
return Array.prototype.every.call(
ta,
(n) => CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo));
};

function EveryGrowMidIteration() {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
let values;
let rab;
let resizeAfter;
let resizeTo;
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLength = new ctor(rab, 0, 4);
values = [];
resizeAfter = 2;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assert(ArrayEveryHelper(fixedLength, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
0,
2,
4,
6
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
values = [];
resizeAfter = 1;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assert(ArrayEveryHelper(fixedLengthWithOffset, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
4,
6
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTracking = new ctor(rab, 0);
values = [];
resizeAfter = 2;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assert(ArrayEveryHelper(lengthTracking, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
0,
2,
4,
6
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
values = [];
resizeAfter = 1;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assert(ArrayEveryHelper(lengthTrackingWithOffset, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
4,
6
]);
}
}

EveryGrowMidIteration();
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-array.prototype.every
description: >
Array.p.every behaves correctly when receiver is backed by resizable
buffer that is shrunk mid-iteration
includes: [compareArray.js]
features: [resizable-arraybuffer]
---*/

const ArrayEveryHelper = (ta, values, rab, resizeAfter, resizeTo) => {
return Array.prototype.every.call(
ta,
(n) => CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo));
};

function EveryShrinkMidIteration() {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
let values;
let rab;
let resizeAfter;
let resizeTo;
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLength = new ctor(rab, 0, 4);
values = [];
resizeAfter = 2;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assert(ArrayEveryHelper(fixedLength, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
0,
2
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
values = [];
resizeAfter = 1;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assert(ArrayEveryHelper(fixedLengthWithOffset, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [4]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTracking = new ctor(rab, 0);
values = [];
resizeAfter = 2;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assert(ArrayEveryHelper(lengthTracking, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
0,
2,
4
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
values = [];
resizeAfter = 1;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assert(ArrayEveryHelper(lengthTrackingWithOffset, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [4]);
}
}

EveryShrinkMidIteration();
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-%typedarray%.prototype.every
description: >
TypedArray.p.every behaves correctly when receiver is backed by resizable
buffer that is grown mid-iteration
includes: [compareArray.js]
features: [resizable-arraybuffer]
---*/

const TypedArrayEveryHelper = (ta, values, rab, resizeAfter, resizeTo) => {
return ta.every(
(n) => CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo));
};

function EveryGrowMidIteration() {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
let values;
let rab;
let resizeAfter;
let resizeTo;
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLength = new ctor(rab, 0, 4);
values = [];
resizeAfter = 2;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assert(TypedArrayEveryHelper(fixedLength, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
0,
2,
4,
6
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
values = [];
resizeAfter = 1;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assert(TypedArrayEveryHelper(fixedLengthWithOffset, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
4,
6
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTracking = new ctor(rab, 0);
values = [];
resizeAfter = 2;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assert(TypedArrayEveryHelper(lengthTracking, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
0,
2,
4,
6
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
values = [];
resizeAfter = 1;
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
assert(TypedArrayEveryHelper(lengthTrackingWithOffset, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
4,
6
]);
}
}

EveryGrowMidIteration();
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-%typedarray%.prototype.every
description: >
TypedArray.p.every behaves correctly when receiver is backed by resizable
buffer that is shrunk mid-iteration
includes: [compareArray.js]
features: [resizable-arraybuffer]
---*/

const TypedArrayEveryHelper = (ta, values, rab, resizeAfter, resizeTo) => {
return ta.every(
(n) => CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo));
};

function EveryShrinkMidIteration() {
// Orig. array: [0, 2, 4, 6]
// [0, 2, 4, 6] << fixedLength
// [4, 6] << fixedLengthWithOffset
// [0, 2, 4, 6, ...] << lengthTracking
// [4, 6, ...] << lengthTrackingWithOffset
let values;
let rab;
let resizeAfter;
let resizeTo;
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLength = new ctor(rab, 0, 4);
values = [];
resizeAfter = 2;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assert(TypedArrayEveryHelper(fixedLength, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
0,
2,
undefined,
undefined
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
values = [];
resizeAfter = 1;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assert(TypedArrayEveryHelper(fixedLengthWithOffset, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
4,
undefined
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTracking = new ctor(rab, 0);
values = [];
resizeAfter = 2;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assert(TypedArrayEveryHelper(lengthTracking, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
0,
2,
4,
undefined
]);
}
for (let ctor of ctors) {
rab = CreateRabForTest(ctor);
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
values = [];
resizeAfter = 1;
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
assert(TypedArrayEveryHelper(lengthTrackingWithOffset, values, rab, resizeAfter, resizeTo));
assert.compareArray(values, [
4,
undefined
]);
}
}

EveryShrinkMidIteration();

0 comments on commit 58af441

Please sign in to comment.