mirror of https://github.com/tc39/test262.git
RAB: Integrate staging tests for the .values method (#4179)
* Import relevant files from #3888 * Removing parts in resizableArrayBufferUtils.js and adding it in includes, while applying review changes from PRs for previously tested methods. * Removes unnecessary .from calls, as suggested in previous PR review comment: https://github.com/tc39/test262/pull/4138#discussion_r1676183221
This commit is contained in:
parent
ef72bd1c44
commit
dc36c7eae9
60
test/built-ins/Array/prototype/values/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
60
test/built-ins/Array/prototype/values/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
// 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.values
|
||||||
|
description: >
|
||||||
|
Array.p.values behaves correctly on TypedArrays backed by resizable buffers and
|
||||||
|
resized mid-iteration.
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
// The fixed length array is not affected by resizing.
|
||||||
|
TestIterationAndResize(Array.prototype.values.call(fixedLength), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
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(Array.prototype.values.call(fixedLengthWithOffset), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
TestIterationAndResize(Array.prototype.values.call(lengthTracking), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
0,
|
||||||
|
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(Array.prototype.values.call(lengthTrackingWithOffset), [
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
52
test/built-ins/Array/prototype/values/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
52
test/built-ins/Array/prototype/values/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// 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.values
|
||||||
|
description: >
|
||||||
|
Array.p.values behaves correctly on TypedArrays backed by resizable buffers
|
||||||
|
that are shrunk mid-iteration.
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
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(Array.prototype.values.call(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);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
TestIterationAndResize(Array.prototype.values.call(fixedLengthWithOffset), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
TestIterationAndResize(Array.prototype.values.call(lengthTracking), [
|
||||||
|
0,
|
||||||
|
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);
|
||||||
|
|
||||||
|
// The fixed length array goes out of bounds when the RAB is resized.
|
||||||
|
TestIterationAndResize(Array.prototype.values.call(lengthTrackingWithOffset), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
|
@ -0,0 +1,156 @@
|
||||||
|
// 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.values
|
||||||
|
description: >
|
||||||
|
Array.p.values behaves correctly on TypedArrays backed by resizable buffers.
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function IteratorToNumbers(iterator) {
|
||||||
|
const result = [];
|
||||||
|
for (let value of iterator) {
|
||||||
|
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(IteratorToNumbers(Array.prototype.values.call(fixedLength)), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(fixedLengthWithOffset)), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTracking)), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(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.
|
||||||
|
Array.prototype.values.call(fixedLength);
|
||||||
|
Array.prototype.values.call(fixedLengthWithOffset);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.values.call(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.values.call(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTracking)), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTrackingWithOffset)), [4]);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
Array.prototype.values.call(fixedLength);
|
||||||
|
Array.prototype.values.call(fixedLengthWithOffset);
|
||||||
|
Array.prototype.values.call(lengthTrackingWithOffset);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.values.call(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.values.call(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.values.call(lengthTrackingWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTracking)), [0]);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
Array.prototype.values.call(fixedLength);
|
||||||
|
Array.prototype.values.call(fixedLengthWithOffset);
|
||||||
|
Array.prototype.values.call(lengthTrackingWithOffset);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.values.call(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.values.call(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.values.call(lengthTrackingWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(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(IteratorToNumbers(Array.prototype.values.call(fixedLength)), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(fixedLengthWithOffset)), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTracking)), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(Array.prototype.values.call(lengthTrackingWithOffset)), [
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10
|
||||||
|
]);
|
||||||
|
}
|
60
test/built-ins/TypedArray/prototype/values/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
60
test/built-ins/TypedArray/prototype/values/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
// 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 on TypedArrays backed by resizable
|
||||||
|
buffers and resized mid-iteration.
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const fixedLength = new ctor(rab, 0, 4);
|
||||||
|
// The fixed length array is not affected by resizing.
|
||||||
|
TestIterationAndResize(fixedLength.values(), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
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.values(), [
|
||||||
|
4,
|
||||||
|
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.values(), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
0,
|
||||||
|
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.values(), [
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
52
test/built-ins/TypedArray/prototype/values/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
52
test/built-ins/TypedArray/prototype/values/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// 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 on TypedArrays backed by resizable
|
||||||
|
buffers that are shrunk mid-iteration.
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
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.values(), 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);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
TestIterationAndResize(fixedLengthWithOffset.values(), null, rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
TestIterationAndResize(lengthTracking.values(), [
|
||||||
|
0,
|
||||||
|
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);
|
||||||
|
|
||||||
|
// The fixed length array goes out of bounds when the RAB is resized.
|
||||||
|
TestIterationAndResize(lengthTrackingWithOffset.values(), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
|
@ -0,0 +1,149 @@
|
||||||
|
// 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 on TypedArrays backed by resizable
|
||||||
|
buffers.
|
||||||
|
includes: [compareArray.js, resizableArrayBufferUtils.js]
|
||||||
|
features: [resizable-arraybuffer]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
function IteratorToNumbers(iterator) {
|
||||||
|
let result = [];
|
||||||
|
for (let value of iterator) {
|
||||||
|
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(IteratorToNumbers(fixedLength.values()), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(fixedLengthWithOffset.values()), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(lengthTracking.values()), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(lengthTrackingWithOffset.values()), [
|
||||||
|
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.values();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.values();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.compareArray(IteratorToNumbers(lengthTracking.values()), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(lengthTrackingWithOffset.values()), [4]);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.values();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.values();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.values();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.compareArray(IteratorToNumbers(lengthTracking.values()), [0]);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.values();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.values();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.values();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.compareArray(IteratorToNumbers(lengthTracking.values()), []);
|
||||||
|
|
||||||
|
// 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(IteratorToNumbers(fixedLength.values()), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(fixedLengthWithOffset.values()), [
|
||||||
|
4,
|
||||||
|
6
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(lengthTracking.values()), [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10
|
||||||
|
]);
|
||||||
|
assert.compareArray(IteratorToNumbers(lengthTrackingWithOffset.values()), [
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
10
|
||||||
|
]);
|
||||||
|
}
|
Loading…
Reference in New Issue