mirror of https://github.com/tc39/test262.git
RAB: Integrate staging tests for the .entries method (#4073)
RAB: Integrate staging tests for the .entries method of Array.prototype and TypedArray.prototype This is part of PR #3888 to make reviewing easier. Includes changes to use the helper ./harness/resizableArrayBufferUtils.js
This commit is contained in:
parent
d7b2f4acfc
commit
cbdff1ca5f
113
test/built-ins/Array/prototype/entries/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
113
test/built-ins/Array/prototype/entries/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
// 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.entries
|
||||||
|
description: >
|
||||||
|
Array.p.entries behaves correctly when receiver is backed by a resizable
|
||||||
|
buffer and resized mid-iteration
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function ArrayEntriesHelper(ta) {
|
||||||
|
return Array.prototype.entries.call(ta);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4, 6]
|
||||||
|
// [0, 2, 4, 6] << fixedLength
|
||||||
|
// [4, 6] << fixedLengthWithOffset
|
||||||
|
// [0, 2, 4, 6, ...] << lengthTracking
|
||||||
|
// [4, 6, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
// Iterating with entries() (the 4 loops below).
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
// The fixed length array is not affected by resizing.
|
||||||
|
TestIterationAndResize(ArrayEntriesHelper(fixedLength), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
6
|
||||||
|
]
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
|
||||||
|
// The fixed length array is not affected by resizing.
|
||||||
|
TestIterationAndResize(ArrayEntriesHelper(fixedLengthWithOffset), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
6
|
||||||
|
]
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
TestIterationAndResize(ArrayEntriesHelper(lengthTracking), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
6
|
||||||
|
],
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
5,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
TestIterationAndResize(ArrayEntriesHelper(lengthTrackingWithOffset), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
6
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
72
test/built-ins/Array/prototype/entries/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
72
test/built-ins/Array/prototype/entries/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
// 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.entries
|
||||||
|
description: >
|
||||||
|
Array.p.entries behaves correctly when receiver is backed by resizable
|
||||||
|
buffer that is shrunk mid-iteration
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function ArrayEntriesHelper(ta) {
|
||||||
|
return Array.prototype.entries.call(ta);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4, 6]
|
||||||
|
// [0, 2, 4, 6] << fixedLength
|
||||||
|
// [4, 6] << fixedLengthWithOffset
|
||||||
|
// [0, 2, 4, 6, ...] << lengthTracking
|
||||||
|
// [4, 6, ...] << lengthTrackingWithOffset
|
||||||
|
// Iterating with entries() (the 4 loops below).
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
|
||||||
|
// The fixed length array goes out of bounds when the RAB is resized.
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
TestIterationAndResize(ArrayEntriesHelper(fixedLength), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
|
||||||
|
|
||||||
|
// The fixed length array goes out of bounds when the RAB is resized.
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
TestIterationAndResize(ArrayEntriesHelper(fixedLengthWithOffset), null, rab, 1, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
TestIterationAndResize(ArrayEntriesHelper(lengthTracking), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
]
|
||||||
|
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
TestIterationAndResize(ArrayEntriesHelper(lengthTrackingWithOffset), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
6
|
||||||
|
]
|
||||||
|
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
|
@ -0,0 +1,164 @@
|
||||||
|
// 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.entries
|
||||||
|
description: >
|
||||||
|
Array.p.entries behaves correctly when receiver is backed by resizable
|
||||||
|
buffer
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function ArrayEntriesHelper(ta) {
|
||||||
|
return Array.prototype.entries.call(ta);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ValuesFromArrayEntries(ta) {
|
||||||
|
let result = [];
|
||||||
|
let expectedKey = 0;
|
||||||
|
for (let [key, value] of Array.prototype.entries.call(ta)) {
|
||||||
|
assert.sameValue(key, expectedKey, 'TypedArray method .entries should return `expectedKey`.');
|
||||||
|
++expectedKey;
|
||||||
|
result.push(Number(value));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(fixedLength), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(fixedLengthWithOffset), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(lengthTracking), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(lengthTrackingWithOffset), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// TypedArray.prototype.{entries, keys, values} throw right away when
|
||||||
|
// called. Array.prototype.{entries, keys, values} don't throw, but when
|
||||||
|
// we try to iterate the returned ArrayIterator, that throws.
|
||||||
|
ArrayEntriesHelper(fixedLength);
|
||||||
|
ArrayEntriesHelper(fixedLengthWithOffset);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(ArrayEntriesHelper(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(ArrayEntriesHelper(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(lengthTracking), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(lengthTrackingWithOffset), [4]);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
ArrayEntriesHelper(fixedLength);
|
||||||
|
ArrayEntriesHelper(fixedLengthWithOffset);
|
||||||
|
ArrayEntriesHelper(lengthTrackingWithOffset);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(ArrayEntriesHelper(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(ArrayEntriesHelper(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(ArrayEntriesHelper(lengthTrackingWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(lengthTracking), [0]);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
ArrayEntriesHelper(fixedLength);
|
||||||
|
ArrayEntriesHelper(fixedLengthWithOffset);
|
||||||
|
ArrayEntriesHelper(lengthTrackingWithOffset);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(ArrayEntriesHelper(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(ArrayEntriesHelper(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(ArrayEntriesHelper(lengthTrackingWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(lengthTracking), []);
|
||||||
|
|
||||||
|
// 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, 2 * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4, 6, 8, 10]
|
||||||
|
// [0, 2, 4, 6] << fixedLength
|
||||||
|
// [4, 6] << fixedLengthWithOffset
|
||||||
|
// [0, 2, 4, 6, 8, 10, ...] << lengthTracking
|
||||||
|
// [4, 6, 8, 10, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(fixedLength), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(fixedLengthWithOffset), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(lengthTracking), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromArrayEntries(lengthTrackingWithOffset), [
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10
|
||||||
|
]);
|
||||||
|
}
|
109
test/built-ins/TypedArray/prototype/entries/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
109
test/built-ins/TypedArray/prototype/entries/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
// 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.entries
|
||||||
|
description: >
|
||||||
|
TypedArray.p.entries behaves correctly when receiver is backed by a resizable
|
||||||
|
buffer and resized mid-iteration
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4, 6]
|
||||||
|
// [0, 2, 4, 6] << fixedLength
|
||||||
|
// [4, 6] << fixedLengthWithOffset
|
||||||
|
// [0, 2, 4, 6, ...] << lengthTracking
|
||||||
|
// [4, 6, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
// Iterating with entries() (the 4 loops below).
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
// The fixed length array is not affected by resizing.
|
||||||
|
TestIterationAndResize(fixedLength.entries(), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
6
|
||||||
|
]
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
|
||||||
|
// The fixed length array is not affected by resizing.
|
||||||
|
TestIterationAndResize(fixedLengthWithOffset.entries(), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
6
|
||||||
|
]
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
TestIterationAndResize(lengthTracking.entries(), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
6
|
||||||
|
],
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
5,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
TestIterationAndResize(lengthTrackingWithOffset.entries(), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
6
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
3,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
68
test/built-ins/TypedArray/prototype/entries/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
68
test/built-ins/TypedArray/prototype/entries/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
// 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.entries
|
||||||
|
description: >
|
||||||
|
TypedArray.p.entries behaves correctly when receiver is backed by resizable
|
||||||
|
buffer that is shrunk mid-iteration
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4, 6]
|
||||||
|
// [0, 2, 4, 6] << fixedLength
|
||||||
|
// [4, 6] << fixedLengthWithOffset
|
||||||
|
// [0, 2, 4, 6, ...] << lengthTracking
|
||||||
|
// [4, 6, ...] << lengthTrackingWithOffset
|
||||||
|
// Iterating with entries() (the 4 loops below).
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
|
||||||
|
// The fixed length array goes out of bounds when the RAB is resized.
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
TestIterationAndResize(fixedLength.entries(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLengthWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT, 2);
|
||||||
|
|
||||||
|
// The fixed length array goes out of bounds when the RAB is resized.
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
TestIterationAndResize(fixedLengthWithOffset.entries(), null, rab, 1, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
TestIterationAndResize(lengthTracking.entries(), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
]
|
||||||
|
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTrackingWithOffset = new ctor(rab, 2 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
TestIterationAndResize(lengthTrackingWithOffset.entries(), [
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
6
|
||||||
|
]
|
||||||
|
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
|
@ -0,0 +1,176 @@
|
||||||
|
// 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.values
|
||||||
|
description: >
|
||||||
|
TypedArray.p.values behaves correctly when receiver is backed by resizable
|
||||||
|
buffer
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function ValuesFromTypedArrayEntries(ta) {
|
||||||
|
let result = [];
|
||||||
|
let expectedKey = 0;
|
||||||
|
for (let [key, value] of ta.entries()) {
|
||||||
|
assert.sameValue(key, expectedKey, 'TypedArray method .entries should return `expectedKey`.');
|
||||||
|
++expectedKey;
|
||||||
|
result.push(Number(value));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(fixedLength), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(fixedLengthWithOffset), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(lengthTracking), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(lengthTrackingWithOffset), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// TypedArray.prototype.{entries, keys, values} throw right away when
|
||||||
|
// called. Array.prototype.{entries, keys, values} don't throw, but when
|
||||||
|
// we try to iterate the returned ArrayIterator, that throws.
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.entries();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.entries();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(fixedLength.entries());
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(fixedLengthWithOffset.entries());
|
||||||
|
});
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(lengthTracking), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(lengthTrackingWithOffset), [4]);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.entries();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.entries();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.entries();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(fixedLength.entries());
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(fixedLengthWithOffset.entries());
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(lengthTrackingWithOffset.entries());
|
||||||
|
});
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(lengthTracking), [0]);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.entries();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.entries();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.entries();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(fixedLength.entries());
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(fixedLengthWithOffset.entries());
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(lengthTrackingWithOffset.entries());
|
||||||
|
});
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(lengthTracking), []);
|
||||||
|
|
||||||
|
// 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, 2 * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orig. array: [0, 2, 4, 6, 8, 10]
|
||||||
|
// [0, 2, 4, 6] << fixedLength
|
||||||
|
// [4, 6] << fixedLengthWithOffset
|
||||||
|
// [0, 2, 4, 6, 8, 10, ...] << lengthTracking
|
||||||
|
// [4, 6, 8, 10, ...] << lengthTrackingWithOffset
|
||||||
|
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(fixedLength), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(fixedLengthWithOffset), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(lengthTracking), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10
|
||||||
|
]);
|
||||||
|
assert.compareArray(ValuesFromTypedArrayEntries(lengthTrackingWithOffset), [
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10
|
||||||
|
]);
|
||||||
|
}
|
Loading…
Reference in New Issue