mirror of https://github.com/tc39/test262.git
RAB: Integrate staging tests for the .keys method (#4138)
* 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 redundant documentation * Address review comments.
This commit is contained in:
parent
5e602555d0
commit
97cf4fd6e9
|
@ -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.keys
|
||||||
|
description: >
|
||||||
|
Array.p.keys behaves correctly when receiver is backed by a resizable
|
||||||
|
buffer and is grown 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.keys.call(fixedLength), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
], 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.keys.call(fixedLengthWithOffset), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
], 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.keys.call(lengthTracking), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5
|
||||||
|
], 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.keys.call(lengthTrackingWithOffset), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
53
test/built-ins/Array/prototype/keys/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
53
test/built-ins/Array/prototype/keys/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
// 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.keys
|
||||||
|
description: >
|
||||||
|
Array.p.keys behaves correctly when receiver is backed by resizable
|
||||||
|
buffer that is 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.keys.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);
|
||||||
|
|
||||||
|
// The fixed length array goes out of bounds when the RAB is resized.
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
TestIterationAndResize(Array.prototype.keys.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.keys.call(lengthTracking), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
], 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(Array.prototype.keys.call(lengthTrackingWithOffset), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
|
@ -0,0 +1,142 @@
|
||||||
|
// 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.keys
|
||||||
|
description: >
|
||||||
|
Array.p.keys behaves correctly when receiver is backed by resizable
|
||||||
|
buffer
|
||||||
|
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, 2 * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(fixedLength)), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(fixedLengthWithOffset)), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(lengthTracking)), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(lengthTrackingWithOffset)), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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.keys.call(fixedLength);
|
||||||
|
Array.prototype.keys.call(fixedLengthWithOffset);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.keys.call(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.keys.call(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(lengthTracking)), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(lengthTrackingWithOffset)), [0]);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
Array.prototype.keys.call(fixedLength);
|
||||||
|
Array.prototype.keys.call(fixedLengthWithOffset);
|
||||||
|
Array.prototype.keys.call(lengthTrackingWithOffset);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.keys.call(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.keys.call(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.keys.call(lengthTrackingWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(lengthTracking)), [0]);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
Array.prototype.keys.call(fixedLength);
|
||||||
|
Array.prototype.keys.call(fixedLengthWithOffset);
|
||||||
|
Array.prototype.keys.call(lengthTrackingWithOffset);
|
||||||
|
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.keys.call(fixedLength));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.keys.call(fixedLengthWithOffset));
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
Array.from(Array.prototype.keys.call(lengthTrackingWithOffset));
|
||||||
|
});
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.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(Array.from(Array.prototype.keys.call(fixedLength)), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(fixedLengthWithOffset)), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(lengthTracking)), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(Array.prototype.keys.call(lengthTrackingWithOffset)), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
}
|
60
test/built-ins/TypedArray/prototype/keys/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
60
test/built-ins/TypedArray/prototype/keys/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.keys
|
||||||
|
description: >
|
||||||
|
TypedArray.p.keys behaves correctly when receiver is backed by a resizable
|
||||||
|
buffer and is grown 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.keys(), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
], 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.keys(), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
||||||
|
for (let ctor of ctors) {
|
||||||
|
const rab = CreateRabForTest(ctor);
|
||||||
|
const lengthTracking = new ctor(rab, 0);
|
||||||
|
TestIterationAndResize(lengthTracking.keys(), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5
|
||||||
|
], 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.keys(), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
], rab, 2, 6 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
53
test/built-ins/TypedArray/prototype/keys/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
53
test/built-ins/TypedArray/prototype/keys/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
// 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.keys
|
||||||
|
description: >
|
||||||
|
TypedArray.p.keys behaves correctly when receiver is backed by resizable
|
||||||
|
buffer that is 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.keys(), 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.keys(), 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.keys(), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
], 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.keys(), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
], rab, 2, 3 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
}
|
|
@ -0,0 +1,141 @@
|
||||||
|
// 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.keys
|
||||||
|
description: >
|
||||||
|
TypedArray.p.keys behaves correctly when receiver is backed by resizable
|
||||||
|
buffer
|
||||||
|
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, 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(Array.from(fixedLength.keys()), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(fixedLengthWithOffset.keys()), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(lengthTracking.keys()), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(lengthTrackingWithOffset.keys()), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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.keys();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.keys();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.compareArray(Array.from(lengthTracking.keys()), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(lengthTrackingWithOffset.keys()), [0]);
|
||||||
|
|
||||||
|
// Shrink so that the TAs with offset go out of bounds.
|
||||||
|
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.keys();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.keys();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.keys();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.compareArray(Array.from(lengthTracking.keys()), [0]);
|
||||||
|
|
||||||
|
// Shrink to zero.
|
||||||
|
rab.resize(0);
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLength.keys();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
fixedLengthWithOffset.keys();
|
||||||
|
});
|
||||||
|
assert.throws(TypeError, () => {
|
||||||
|
lengthTrackingWithOffset.keys();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.compareArray(Array.from(lengthTracking.keys()), []);
|
||||||
|
|
||||||
|
// 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(Array.from(fixedLength.keys()), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(fixedLengthWithOffset.keys()), [
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(lengthTracking.keys()), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5
|
||||||
|
]);
|
||||||
|
assert.compareArray(Array.from(lengthTrackingWithOffset.keys()), [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
]);
|
||||||
|
}
|
Loading…
Reference in New Issue