mirror of https://github.com/tc39/test262.git
RAB: Integrate staging tests for the .every method (#4074)
* RAB: Integrate staging tests for the .every 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 * Added missing includes * Removed unnecessary function call. * Apply suggestions from code review * Applied review suggestion to the rest of the files * Addressed forgotten review comment noting some files are missing. https://github.com/tc39/test262/pull/4074#pullrequestreview-2046589557 Adds forgotten tests from #3888 * Addresses review comment. * Fixed forgotten rename * Simplify the tests and add documentation. New approach replaces ...Helper with CollectResize to make the tests easier to understand. In particular: - Replaced the need for '...Helper' abstractions with a more descriptive function 'ResizeBufferMidIteration', which the .every method can call directly. - Moved 'let values' back outside of the loops, together with a function definition 'ResizeBufferMidIteration' to persist the side effects that 'CollectValuesAndResize' has on 'values' but without having to define this inside every loop. + So this reverts commit d9a2bac41f87f0964a43d34c6f349b6d78401633 and + this reverts commit 0bc2d66335671cac56912981b73c7900bf309cee. - Added documentation. * Documentation style change and remove accidental additions.
This commit is contained in:
parent
03852c962b
commit
d2596e2651
|
@ -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.every
|
||||
description: >
|
||||
Array.p.every 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) {
|
||||
// Returns true by default.
|
||||
return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo);
|
||||
}
|
||||
|
||||
// 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(Array.prototype.every.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(Array.prototype.every.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(Array.prototype.every.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(Array.prototype.every.call(lengthTrackingWithOffset, ResizeBufferMidIteration));
|
||||
assert.compareArray(values, [
|
||||
4,
|
||||
6
|
||||
]);
|
||||
}
|
74
test/built-ins/Array/prototype/every/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
74
test/built-ins/Array/prototype/every/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
// 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.every
|
||||
description: >
|
||||
Array.p.every 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) {
|
||||
// Returns true by default.
|
||||
return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo);
|
||||
}
|
||||
|
||||
// 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(Array.prototype.every.call(fixedLength, ResizeBufferMidIteration));
|
||||
assert.compareArray(values, [
|
||||
0,
|
||||
2
|
||||
]);
|
||||
}
|
||||
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(Array.prototype.every.call(fixedLengthWithOffset, ResizeBufferMidIteration));
|
||||
assert.compareArray(values, [4]);
|
||||
}
|
||||
for (let ctor of ctors) {
|
||||
rab = CreateRabForTest(ctor);
|
||||
const lengthTracking = new ctor(rab, 0);
|
||||
values = [];
|
||||
resizeAfter = 2;
|
||||
resizeTo = 3 * ctor.BYTES_PER_ELEMENT;
|
||||
assert(Array.prototype.every.call(lengthTracking, ResizeBufferMidIteration));
|
||||
assert.compareArray(values, [
|
||||
0,
|
||||
2,
|
||||
4
|
||||
]);
|
||||
}
|
||||
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(Array.prototype.every.call(lengthTrackingWithOffset, ResizeBufferMidIteration));
|
||||
assert.compareArray(values, [4]);
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
// 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.every
|
||||
description: >
|
||||
Array.p.every behaves correctly when the 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 div3(n) {
|
||||
return Number(n) % 3 == 0;
|
||||
}
|
||||
function even(n) {
|
||||
return Number(n) % 2 == 0;
|
||||
}
|
||||
function over10(n) {
|
||||
return Number(n) > 10;
|
||||
}
|
||||
assert(!Array.prototype.every.call(fixedLength, div3));
|
||||
assert(Array.prototype.every.call(fixedLength, even));
|
||||
assert(!Array.prototype.every.call(fixedLengthWithOffset, div3));
|
||||
assert(Array.prototype.every.call(fixedLengthWithOffset, even));
|
||||
assert(!Array.prototype.every.call(lengthTracking, div3));
|
||||
assert(Array.prototype.every.call(lengthTracking, even));
|
||||
assert(!Array.prototype.every.call(lengthTrackingWithOffset, div3));
|
||||
assert(Array.prototype.every.call(lengthTrackingWithOffset, even));
|
||||
|
||||
// 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
|
||||
|
||||
// Calling .every on an out of bounds TA doesn't throw.
|
||||
assert(Array.prototype.every.call(fixedLength, div3));
|
||||
assert(Array.prototype.every.call(fixedLengthWithOffset, div3));
|
||||
|
||||
assert(!Array.prototype.every.call(lengthTracking, div3));
|
||||
assert(Array.prototype.every.call(lengthTracking, even));
|
||||
assert(!Array.prototype.every.call(lengthTrackingWithOffset, div3));
|
||||
assert(Array.prototype.every.call(lengthTrackingWithOffset, even));
|
||||
|
||||
// Shrink so that the TAs with offset go out of bounds.
|
||||
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||
// Calling .every on an out of bounds TA doesn't throw.
|
||||
assert(Array.prototype.every.call(fixedLength, div3));
|
||||
assert(Array.prototype.every.call(fixedLengthWithOffset, div3));
|
||||
assert(Array.prototype.every.call(lengthTrackingWithOffset, div3));
|
||||
|
||||
assert(Array.prototype.every.call(lengthTracking, div3));
|
||||
assert(Array.prototype.every.call(lengthTracking, even));
|
||||
|
||||
// Shrink to zero.
|
||||
rab.resize(0);
|
||||
// Calling .every on an out of bounds TA doesn't throw.
|
||||
assert(Array.prototype.every.call(fixedLength, div3));
|
||||
assert(Array.prototype.every.call(fixedLengthWithOffset, div3));
|
||||
assert(Array.prototype.every.call(lengthTrackingWithOffset, div3));
|
||||
|
||||
assert(Array.prototype.every.call(lengthTracking, div3));
|
||||
assert(Array.prototype.every.call(lengthTracking, even));
|
||||
|
||||
// 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(!Array.prototype.every.call(fixedLength, div3));
|
||||
assert(Array.prototype.every.call(fixedLength, even));
|
||||
assert(!Array.prototype.every.call(fixedLengthWithOffset, div3));
|
||||
assert(Array.prototype.every.call(fixedLengthWithOffset, even));
|
||||
assert(!Array.prototype.every.call(lengthTracking, div3));
|
||||
assert(Array.prototype.every.call(lengthTracking, even));
|
||||
assert(!Array.prototype.every.call(lengthTrackingWithOffset, div3));
|
||||
assert(Array.prototype.every.call(lengthTrackingWithOffset, even));
|
||||
}
|
83
test/built-ins/TypedArray/prototype/every/resizable-buffer-grow-mid-iteration.js
vendored
Normal file
83
test/built-ins/TypedArray/prototype/every/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.every
|
||||
description: >
|
||||
TypedArray.p.every 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) {
|
||||
// Returns true by default.
|
||||
return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo);
|
||||
}
|
||||
|
||||
// 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(fixedLength.every(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(fixedLengthWithOffset.every(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(lengthTracking.every(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(lengthTrackingWithOffset.every(ResizeBufferMidIteration));
|
||||
assert.compareArray(values, [
|
||||
4,
|
||||
6
|
||||
]);
|
||||
}
|
83
test/built-ins/TypedArray/prototype/every/resizable-buffer-shrink-mid-iteration.js
vendored
Normal file
83
test/built-ins/TypedArray/prototype/every/resizable-buffer-shrink-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.every
|
||||
description: >
|
||||
TypedArray.p.every 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) {
|
||||
// Returns true by default.
|
||||
return CollectValuesAndResize(n, values, rab, resizeAfter, resizeTo);
|
||||
}
|
||||
|
||||
// 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(fixedLength.every(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(fixedLengthWithOffset.every(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(lengthTracking.every(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(lengthTrackingWithOffset.every(ResizeBufferMidIteration));
|
||||
assert.compareArray(values, [
|
||||
4,
|
||||
undefined
|
||||
]);
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
// 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.every
|
||||
description: >
|
||||
TypedArray.p.every behaves correctly when the 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 div3(n) {
|
||||
return Number(n) % 3 == 0;
|
||||
}
|
||||
function even(n) {
|
||||
return Number(n) % 2 == 0;
|
||||
}
|
||||
function over10(n) {
|
||||
return Number(n) > 10;
|
||||
}
|
||||
assert(!fixedLength.every(div3));
|
||||
assert(fixedLength.every(even));
|
||||
assert(!fixedLengthWithOffset.every(div3));
|
||||
assert(fixedLengthWithOffset.every(even));
|
||||
assert(!lengthTracking.every(div3));
|
||||
assert(lengthTracking.every(even));
|
||||
assert(!lengthTrackingWithOffset.every(div3));
|
||||
assert(lengthTrackingWithOffset.every(even));
|
||||
|
||||
// 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
|
||||
|
||||
// Calling .every on an out of bounds TA throws.
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLength.every(div3);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLengthWithOffset.every(div3);
|
||||
});
|
||||
|
||||
assert(!lengthTracking.every(div3));
|
||||
assert(lengthTracking.every(even));
|
||||
assert(!lengthTrackingWithOffset.every(div3));
|
||||
assert(lengthTrackingWithOffset.every(even));
|
||||
|
||||
// Shrink so that the TAs with offset go out of bounds.
|
||||
rab.resize(1 * ctor.BYTES_PER_ELEMENT);
|
||||
// Calling .every on an out of bounds TA throws.
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLength.every(div3);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLengthWithOffset.every(div3);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
lengthTrackingWithOffset.every(div3);
|
||||
});
|
||||
|
||||
assert(lengthTracking.every(div3));
|
||||
assert(lengthTracking.every(even));
|
||||
|
||||
// Shrink to zero.
|
||||
rab.resize(0);
|
||||
// Calling .every on an out of bounds TA throws.
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLength.every(div3);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
fixedLengthWithOffset.every(div3);
|
||||
});
|
||||
assert.throws(TypeError, () => {
|
||||
lengthTrackingWithOffset.every(div3);
|
||||
});
|
||||
|
||||
assert(lengthTracking.every(div3));
|
||||
assert(lengthTracking.every(even));
|
||||
|
||||
// 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(!fixedLength.every(div3));
|
||||
assert(fixedLength.every(even));
|
||||
assert(!fixedLengthWithOffset.every(div3));
|
||||
assert(fixedLengthWithOffset.every(even));
|
||||
assert(!lengthTracking.every(div3));
|
||||
assert(lengthTracking.every(even));
|
||||
assert(!lengthTrackingWithOffset.every(div3));
|
||||
assert(lengthTrackingWithOffset.every(even));
|
||||
}
|
Loading…
Reference in New Issue