mirror of https://github.com/tc39/test262.git
RAB: Integrate staging tests for the .filter method (#4125)
* Import relevant files from #3888
* Removing parts in resizableArrayBufferUtils.js and adding it in includes,
while adjusting usage of CollectValuesAndResize and applying review changes
from PRs for previously tested methods.
* Addresses review comment removing forgoten onlyStrict flag
a62d978ca6 (r1663298683)
This commit is contained in:
parent
e4f4abdcb2
commit
a507aa01de
85
test/built-ins/Array/prototype/filter/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
85
test/built-ins/Array/prototype/filter/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
// 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.filter
|
||||
description: >
|
||||
Array.p.filter behaves correctly on receivers backed by resizable
|
||||
buffers that grow mid-iteration
|
||||
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
let values;
|
||||
let rab;
|
||||
let resizeAfter;
|
||||
let resizeTo;
|
||||
// Collects the view of the resizable array buffer rab into values, with an
|
||||
// iteration during which, after resizeAfter steps, rab is resized to length
|
||||
// resizeTo. To be called by a method of the view being collected.
|
||||
// Note that rab, values, resizeAfter, and resizeTo may need to be reset
|
||||
// before calling this.
|
||||
function ResizeBufferMidIteration(n) {
|
||||
CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Orig. array: [0, 2, 4, 6]
|
||||
// [0, 2, 4, 6] << fixedLength
|
||||
// [4, 6] << fixedLengthWithOffset
|
||||
// [0, 2, 4, 6, ...] << lengthTracking
|
||||
// [4, 6, ...] << lengthTrackingWithOffset
|
||||
|
||||
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.compareArray(ToNumbers(Array.prototype.filter.call(fixedLength, ResizeBufferMidIteration)), []);
|
||||
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.compareArray(ToNumbers(Array.prototype.filter.call(fixedLengthWithOffset, ResizeBufferMidIteration)), []);
|
||||
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.compareArray(ToNumbers(Array.prototype.filter.call(lengthTracking, ResizeBufferMidIteration)), []);
|
||||
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.compareArray(ToNumbers(Array.prototype.filter.call(lengthTrackingWithOffset, ResizeBufferMidIteration)), []);
|
||||
assert.compareArray(values, [
|
||||
4,
|
||||
6
|
||||
]);
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
// 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.filter
|
||||
description: >
|
||||
Array.p.filter behaves correctly on receivers backed by resizable
|
||||
buffers
|
||||
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
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);
|
||||
|
||||
// Write some data into the array.
|
||||
const taWrite = new ctor(rab);
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
WriteToTypedArray(taWrite, i, i);
|
||||
}
|
||||
|
||||
// Orig. array: [0, 1, 2, 3]
|
||||
// [0, 1, 2, 3] << fixedLength
|
||||
// [2, 3] << fixedLengthWithOffset
|
||||
// [0, 1, 2, 3, ...] << lengthTracking
|
||||
// [2, 3, ...] << lengthTrackingWithOffset
|
||||
|
||||
function isEven(n) {
|
||||
return n != undefined && Number(n) % 2 == 0;
|
||||
}
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(fixedLength, isEven)), [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(fixedLengthWithOffset, isEven)), [2]);
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(lengthTracking, isEven)), [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(lengthTrackingWithOffset, isEven)), [2]);
|
||||
|
||||
// Shrink so that fixed length TAs go out of bounds.
|
||||
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
|
||||
|
||||
// Orig. array: [0, 1, 2]
|
||||
// [0, 1, 2, ...] << lengthTracking
|
||||
// [2, ...] << lengthTrackingWithOffset
|
||||
|
||||
assert.compareArray(Array.prototype.filter.call(fixedLength, isEven), []);
|
||||
assert.compareArray(Array.prototype.filter.call(fixedLengthWithOffset, isEven), []);
|
||||
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(lengthTracking, isEven)), [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(lengthTrackingWithOffset, isEven)), [2]);
|
||||
|
||||
// Shrink so that the TAs with offset go out of bounds.
|
||||
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||
assert.compareArray(Array.prototype.filter.call(fixedLength, isEven), []);
|
||||
assert.compareArray(Array.prototype.filter.call(fixedLengthWithOffset, isEven), []);
|
||||
assert.compareArray(Array.prototype.filter.call(lengthTrackingWithOffset, isEven), []);
|
||||
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(lengthTracking, isEven)), [0]);
|
||||
|
||||
// Shrink to zero.
|
||||
rab.resize(0);
|
||||
assert.compareArray(Array.prototype.filter.call(fixedLength, isEven), []);
|
||||
assert.compareArray(Array.prototype.filter.call(fixedLengthWithOffset, isEven), []);
|
||||
assert.compareArray(Array.prototype.filter.call(lengthTrackingWithOffset, isEven), []);
|
||||
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(lengthTracking, isEven)), []);
|
||||
|
||||
// Grow so that all TAs are back in-bounds.
|
||||
rab.resize(6 * ctor.BYTES_PER_ELEMENT);
|
||||
for (let i = 0; i < 6; ++i) {
|
||||
WriteToTypedArray(taWrite, i, i);
|
||||
}
|
||||
|
||||
// Orig. array: [0, 1, 2, 3, 4, 5]
|
||||
// [0, 1, 2, 3] << fixedLength
|
||||
// [2, 3] << fixedLengthWithOffset
|
||||
// [0, 1, 2, 3, 4, 5, ...] << lengthTracking
|
||||
// [2, 3, 4, 5, ...] << lengthTrackingWithOffset
|
||||
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(fixedLength, isEven)), [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(fixedLengthWithOffset, isEven)), [2]);
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(lengthTracking, isEven)), [
|
||||
0,
|
||||
2,
|
||||
4
|
||||
]);
|
||||
assert.compareArray(ToNumbers(Array.prototype.filter.call(lengthTrackingWithOffset, isEven)), [
|
||||
2,
|
||||
4
|
||||
]);
|
||||
}
|
84
test/built-ins/TypedArray/prototype/filter/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
84
test/built-ins/TypedArray/prototype/filter/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
// 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.filter
|
||||
description: >
|
||||
TypedArray.p.filter behaves correctly on receivers backed by resizable
|
||||
buffers that grow mid-iteration
|
||||
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
let values;
|
||||
let rab;
|
||||
let resizeAfter;
|
||||
let resizeTo;
|
||||
// Collects the view of the resizable array buffer rab into values, with an
|
||||
// iteration during which, after resizeAfter steps, rab is resized to length
|
||||
// resizeTo. To be called by a method of the view being collected.
|
||||
// Note that rab, values, resizeAfter, and resizeTo may need to be reset
|
||||
// before calling this.
|
||||
function ResizeBufferMidIteration(n) {
|
||||
CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Orig. array: [0, 2, 4, 6]
|
||||
// [0, 2, 4, 6] << fixedLength
|
||||
// [4, 6] << fixedLengthWithOffset
|
||||
// [0, 2, 4, 6, ...] << lengthTracking
|
||||
// [4, 6, ...] << lengthTrackingWithOffset
|
||||
|
||||
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.compareArray(ToNumbers(fixedLength.filter(ResizeBufferMidIteration)), []);
|
||||
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.compareArray(ToNumbers(fixedLengthWithOffset.filter(ResizeBufferMidIteration)), []);
|
||||
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.compareArray(ToNumbers(lengthTracking.filter(ResizeBufferMidIteration)), []);
|
||||
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.compareArray(ToNumbers(lengthTrackingWithOffset.filter(ResizeBufferMidIteration)), []);
|
||||
assert.compareArray(values, [
|
||||
4,
|
||||
6
|
||||
]);
|
||||
}
|
85
test/built-ins/TypedArray/prototype/filter/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
85
test/built-ins/TypedArray/prototype/filter/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
// 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.filter
|
||||
description: >
|
||||
TypedArray.p.filter behaves correctly when receiver is backed by resizable
|
||||
buffer that is shrunk mid-iteration
|
||||
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
let values;
|
||||
let rab;
|
||||
let resizeAfter;
|
||||
let resizeTo;
|
||||
// Collects the view of the resizable array buffer rab into values, with an
|
||||
// iteration during which, after resizeAfter steps, rab is resized to length
|
||||
// resizeTo. To be called by a method of the view being collected.
|
||||
// Note that rab, values, resizeAfter, and resizeTo may need to be reset
|
||||
// before calling this.
|
||||
function ResizeBufferMidIteration(n) {
|
||||
CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Orig. array: [0, 2, 4, 6]
|
||||
// [0, 2, 4, 6] << fixedLength
|
||||
// [4, 6] << fixedLengthWithOffset
|
||||
// [0, 2, 4, 6, ...] << lengthTracking
|
||||
// [4, 6, ...] << lengthTrackingWithOffset
|
||||
|
||||
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.compareArray(ToNumbers(fixedLength.filter(ResizeBufferMidIteration)),[]);
|
||||
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.compareArray(ToNumbers(fixedLengthWithOffset.filter(ResizeBufferMidIteration)),[]);
|
||||
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.compareArray(ToNumbers(lengthTracking.filter(ResizeBufferMidIteration)),[]);
|
||||
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.compareArray(ToNumbers(lengthTrackingWithOffset.filter(ResizeBufferMidIteration)),[]);
|
||||
assert.compareArray(values, [
|
||||
4,
|
||||
undefined
|
||||
]);
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
// 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.filter
|
||||
description: >
|
||||
TypedArray.p.filter behaves correctly on receivers backed by resizable
|
||||
buffers
|
||||
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||
features: [resizable-arraybuffer]
|
||||
---*/
|
||||
|
||||
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);
|
||||
|
||||
// Write some data into the array.
|
||||
const taWrite = new ctor(rab);
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
WriteToTypedArray(taWrite, i, i);
|
||||
}
|
||||
|
||||
// Orig. array: [0, 1, 2, 3]
|
||||
// [0, 1, 2, 3] << fixedLength
|
||||
// [2, 3] << fixedLengthWithOffset
|
||||
// [0, 1, 2, 3, ...] << lengthTracking
|
||||
// [2, 3, ...] << lengthTrackingWithOffset
|
||||
|
||||
function isEven(n) {
|
||||
return n != undefined && Number(n) % 2 == 0;
|
||||
}
|
||||
assert.compareArray(ToNumbers(fixedLength.filter(isEven)), [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
assert.compareArray(ToNumbers(fixedLengthWithOffset.filter(isEven)), [2]);
|
||||
assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
assert.compareArray(ToNumbers(lengthTrackingWithOffset.filter(isEven)), [2]);
|
||||
|
||||
// Shrink so that fixed length TAs go out of bounds.
|
||||
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
|
||||
|
||||
// Orig. array: [0, 1, 2]
|
||||
// [0, 1, 2, ...] << lengthTracking
|
||||
// [2, ...] << lengthTrackingWithOffset
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLength.filter(isEven);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLengthWithOffset.filter(isEven);
|
||||
});
|
||||
|
||||
assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
assert.compareArray(ToNumbers(lengthTrackingWithOffset.filter(isEven)), [2]);
|
||||
|
||||
// Shrink so that the TAs with offset go out of bounds.
|
||||
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLength.filter(isEven);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLengthWithOffset.filter(isEven);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
lengthTrackingWithOffset.filter(isEven);
|
||||
});
|
||||
|
||||
assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), [0]);
|
||||
|
||||
// Shrink to zero.
|
||||
rab.resize(0);
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLength.filter(isEven);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLengthWithOffset.filter(isEven);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
lengthTrackingWithOffset.filter(isEven);
|
||||
});
|
||||
|
||||
assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), []);
|
||||
|
||||
// Grow so that all TAs are back in-bounds.
|
||||
rab.resize(6 * ctor.BYTES_PER_ELEMENT);
|
||||
for (let i = 0; i < 6; ++i) {
|
||||
WriteToTypedArray(taWrite, i, i);
|
||||
}
|
||||
|
||||
// Orig. array: [0, 1, 2, 3, 4, 5]
|
||||
// [0, 1, 2, 3] << fixedLength
|
||||
// [2, 3] << fixedLengthWithOffset
|
||||
// [0, 1, 2, 3, 4, 5, ...] << lengthTracking
|
||||
// [2, 3, 4, 5, ...] << lengthTrackingWithOffset
|
||||
|
||||
assert.compareArray(ToNumbers(fixedLength.filter(isEven)), [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
assert.compareArray(ToNumbers(fixedLengthWithOffset.filter(isEven)), [2]);
|
||||
assert.compareArray(ToNumbers(lengthTracking.filter(isEven)), [
|
||||
0,
|
||||
2,
|
||||
4
|
||||
]);
|
||||
assert.compareArray(ToNumbers(lengthTrackingWithOffset.filter(isEven)), [
|
||||
2,
|
||||
4
|
||||
]);
|
||||
}
|
Loading…
Reference in New Issue