mirror of
https://github.com/tc39/test262.git
synced 2025-05-30 11:40:30 +02:00
RAB: Integrate staging tests for the .findLast method (#4128)
* 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.
This commit is contained in:
parent
105906a49c
commit
6f2eeebdcc
83
test/built-ins/Array/prototype/findLast/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
83
test/built-ins/Array/prototype/findLast/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
@ -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.findlast
|
||||||
|
description: >
|
||||||
|
Array.p.findLast behaves correctly when receiver is backed by resizable
|
||||||
|
buffer that is grown 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.sameValue(Array.prototype.findLast.call(fixedLength, ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
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.sameValue(Array.prototype.findLast.call(fixedLengthWithOffset, ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
values = [];
|
||||||
|
resizeAfter = 2;
|
||||||
|
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(lengthTracking, ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
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.sameValue(Array.prototype.findLast.call(lengthTrackingWithOffset, ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
}
|
84
test/built-ins/Array/prototype/findLast/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
84
test/built-ins/Array/prototype/findLast/resizable-buffer-shrink-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-array.prototype.findlast
|
||||||
|
description: >
|
||||||
|
Array.p.findLast 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.sameValue(Array.prototype.findLast.call(fixedLength, ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
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.sameValue(Array.prototype.findLast.call(fixedLengthWithOffset, ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
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.sameValue(Array.prototype.findLast.call(lengthTracking, ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
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.sameValue(Array.prototype.findLast.call(lengthTrackingWithOffset, ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
}
|
87
test/built-ins/Array/prototype/findLast/resizable-buffer.js
vendored
Normal file
87
test/built-ins/Array/prototype/findLast/resizable-buffer.js
vendored
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
// 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.findLast
|
||||||
|
description: >
|
||||||
|
Array.p.findLast behaves correctly when receiver is backed by resizable
|
||||||
|
buffer
|
||||||
|
includes: [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, 2 * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4, 6]
|
||||||
|
// [0, 2, 4, 6] << fixedLength
|
||||||
|
// [4, 6] << fixedLengthWithOffset
|
||||||
|
// [0, 2, 4, 6, ...] << lengthTracking
|
||||||
|
// [4, 6, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
function isTwoOrFour(n) {
|
||||||
|
return n == 2 || n == 4;
|
||||||
|
}
|
||||||
|
assert.sameValue(Number(Array.prototype.findLast.call(fixedLength, isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(Array.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(Array.prototype.findLast.call(lengthTracking, isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(Array.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour)), 4);
|
||||||
|
|
||||||
|
// Shrink so that fixed length TAs go out of bounds.
|
||||||
|
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4]
|
||||||
|
// [0, 2, 4, ...] << lengthTracking
|
||||||
|
// [4, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(fixedLength, isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour), undefined);
|
||||||
|
|
||||||
|
assert.sameValue(Number(Array.prototype.findLast.call(lengthTracking, isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(Array.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour)), 4);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(fixedLength, isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour), undefined);
|
||||||
|
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(lengthTracking, isTwoOrFour), undefined);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(fixedLength, isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour), undefined);
|
||||||
|
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(lengthTracking, isTwoOrFour), undefined);
|
||||||
|
|
||||||
|
// Grow so that all TAs are back in-bounds.
|
||||||
|
rab.resize(6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, 0);
|
||||||
|
}
|
||||||
|
WriteToTypedArray(taWrite, 4, 2);
|
||||||
|
WriteToTypedArray(taWrite, 5, 4);
|
||||||
|
|
||||||
|
// Orig. array: [0, 0, 0, 0, 2, 4]
|
||||||
|
// [0, 0, 0, 0] << fixedLength
|
||||||
|
// [0, 0] << fixedLengthWithOffset
|
||||||
|
// [0, 0, 0, 0, 2, 4, ...] << lengthTracking
|
||||||
|
// [0, 0, 2, 4, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(fixedLength, isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(Array.prototype.findLast.call(fixedLengthWithOffset, isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(Number(Array.prototype.findLast.call(lengthTracking, isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(Array.prototype.findLast.call(lengthTrackingWithOffset, isTwoOrFour)), 4);
|
||||||
|
}
|
83
test/built-ins/TypedArray/prototype/findLast/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
83
test/built-ins/TypedArray/prototype/findLast/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
@ -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-%typedarray%.prototype.findlast
|
||||||
|
description: >
|
||||||
|
TypedArray.p.findLast behaves correctly when receiver is backed by resizable
|
||||||
|
buffer that is grown 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.sameValue(fixedLength.findLast(ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
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.sameValue(fixedLengthWithOffset.findLast(ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
values = [];
|
||||||
|
resizeAfter = 2;
|
||||||
|
resizeTo = 5 * ctor.BYTES_PER_ELEMENT;
|
||||||
|
assert.sameValue(lengthTracking.findLast(ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
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.sameValue(lengthTrackingWithOffset.findLast(ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
}
|
84
test/built-ins/TypedArray/prototype/findLast/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
84
test/built-ins/TypedArray/prototype/findLast/resizable-buffer-shrink-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.findlast
|
||||||
|
description: >
|
||||||
|
TypedArray.p.findLast 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.sameValue(fixedLength.findLast(ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
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.sameValue(fixedLengthWithOffset.findLast(ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
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.sameValue(lengthTracking.findLast(ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
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.sameValue(lengthTrackingWithOffset.findLast(ResizeBufferMidIteration), undefined);
|
||||||
|
assert.compareArray(values, [
|
||||||
|
6,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
}
|
103
test/built-ins/TypedArray/prototype/findLast/resizable-buffer.js
vendored
Normal file
103
test/built-ins/TypedArray/prototype/findLast/resizable-buffer.js
vendored
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
// 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.findlast
|
||||||
|
description: >
|
||||||
|
TypedArray.p.findLast behaves correctly when receiver is backed by resizable
|
||||||
|
buffer
|
||||||
|
includes: [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, 2 * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4, 6]
|
||||||
|
// [0, 2, 4, 6] << fixedLength
|
||||||
|
// [4, 6] << fixedLengthWithOffset
|
||||||
|
// [0, 2, 4, 6, ...] << lengthTracking
|
||||||
|
// [4, 6, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
function isTwoOrFour(n) {
|
||||||
|
return n == 2 || n == 4;
|
||||||
|
}
|
||||||
|
assert.sameValue(Number(fixedLength.findLast(isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(fixedLengthWithOffset.findLast(isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(lengthTracking.findLast(isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(lengthTrackingWithOffset.findLast(isTwoOrFour)), 4);
|
||||||
|
|
||||||
|
// Shrink so that fixed length TAs go out of bounds.
|
||||||
|
rab.resize(3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4]
|
||||||
|
// [0, 2, 4, ...] << lengthTracking
|
||||||
|
// [4, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.findLast(isTwoOrFour);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.findLast(isTwoOrFour);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(Number(lengthTracking.findLast(isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(lengthTrackingWithOffset.findLast(isTwoOrFour)), 4);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.findLast(isTwoOrFour);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.findLast(isTwoOrFour);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.findLast(isTwoOrFour);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(lengthTracking.findLast(isTwoOrFour), undefined);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.findLast(isTwoOrFour);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.findLast(isTwoOrFour);
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.findLast(isTwoOrFour);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(lengthTracking.findLast(isTwoOrFour), undefined);
|
||||||
|
|
||||||
|
// Grow so that all TAs are back in-bounds.
|
||||||
|
rab.resize(6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
for (let i = 0; i < 4; ++i) {
|
||||||
|
WriteToTypedArray(taWrite, i, 0);
|
||||||
|
}
|
||||||
|
WriteToTypedArray(taWrite, 4, 2);
|
||||||
|
WriteToTypedArray(taWrite, 5, 4);
|
||||||
|
|
||||||
|
// Orig. array: [0, 0, 0, 0, 2, 4]
|
||||||
|
// [0, 0, 0, 0] << fixedLength
|
||||||
|
// [0, 0] << fixedLengthWithOffset
|
||||||
|
// [0, 0, 0, 0, 2, 4, ...] << lengthTracking
|
||||||
|
// [0, 0, 2, 4, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
assert.sameValue(fixedLength.findLast(isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(fixedLengthWithOffset.findLast(isTwoOrFour), undefined);
|
||||||
|
assert.sameValue(Number(lengthTracking.findLast(isTwoOrFour)), 4);
|
||||||
|
assert.sameValue(Number(lengthTrackingWithOffset.findLast(isTwoOrFour)), 4);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user