-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
860 additions
and
0 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
test/built-ins/Array/prototype/findIndex/resizable-buffer-grow-mid-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// 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.findindex | ||
description: > | ||
Array.p.findIndex behaves correctly when receiver is backed by resizable | ||
buffer that is grown mid-iteration | ||
includes: [compareArray.js] | ||
features: [resizable-arraybuffer] | ||
---*/ | ||
|
||
class MyUint8Array extends Uint8Array { | ||
} | ||
|
||
class MyFloat32Array extends Float32Array { | ||
} | ||
|
||
class MyBigInt64Array extends BigInt64Array { | ||
} | ||
|
||
const builtinCtors = [ | ||
Uint8Array, | ||
Int8Array, | ||
Uint16Array, | ||
Int16Array, | ||
Uint32Array, | ||
Int32Array, | ||
Float32Array, | ||
Float64Array, | ||
Uint8ClampedArray, | ||
BigUint64Array, | ||
BigInt64Array | ||
]; | ||
|
||
const ctors = [ | ||
...builtinCtors, | ||
MyUint8Array, | ||
MyFloat32Array, | ||
MyBigInt64Array | ||
]; | ||
|
||
function CreateResizableArrayBuffer(byteLength, maxByteLength) { | ||
return new ArrayBuffer(byteLength, { maxByteLength: maxByteLength }); | ||
} | ||
|
||
function WriteToTypedArray(array, index, value) { | ||
if (array instanceof BigInt64Array || array instanceof BigUint64Array) { | ||
array[index] = BigInt(value); | ||
} else { | ||
array[index] = value; | ||
} | ||
} | ||
|
||
function ArrayFindIndexHelper(ta, p) { | ||
return Array.prototype.findIndex.call(ta, p); | ||
} | ||
|
||
function FindIndexGrowMidIteration() { | ||
// Orig. array: [0, 2, 4, 6] | ||
// [0, 2, 4, 6] << fixedLength | ||
// [4, 6] << fixedLengthWithOffset | ||
// [0, 2, 4, 6, ...] << lengthTracking | ||
// [4, 6, ...] << lengthTrackingWithOffset | ||
function CreateRabForTest(ctor) { | ||
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * 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); | ||
} | ||
return rab; | ||
} | ||
let values; | ||
let rab; | ||
let resizeAfter; | ||
let resizeTo; | ||
function CollectValuesAndResize(n) { | ||
if (typeof n == 'bigint') { | ||
values.push(Number(n)); | ||
} else { | ||
values.push(n); | ||
} | ||
if (values.length == resizeAfter) { | ||
rab.resize(resizeTo); | ||
} | ||
return false; | ||
} | ||
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(ArrayFindIndexHelper(fixedLength, CollectValuesAndResize), -1); | ||
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.sameValue(ArrayFindIndexHelper(fixedLengthWithOffset, CollectValuesAndResize), -1); | ||
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.sameValue(ArrayFindIndexHelper(lengthTracking, CollectValuesAndResize), -1); | ||
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.sameValue(ArrayFindIndexHelper(lengthTrackingWithOffset, CollectValuesAndResize), -1); | ||
assert.compareArray(values, [ | ||
4, | ||
6 | ||
]); | ||
} | ||
} | ||
|
||
FindIndexGrowMidIteration(); | ||
|
143 changes: 143 additions & 0 deletions
143
test/built-ins/Array/prototype/findIndex/resizable-buffer-shrink-mid-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// 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.findindex | ||
description: > | ||
Array.p.findIndex behaves correctly when receiver is backed by resizable | ||
buffer that is shrunk mid-iteration | ||
includes: [compareArray.js] | ||
features: [resizable-arraybuffer] | ||
---*/ | ||
|
||
class MyUint8Array extends Uint8Array { | ||
} | ||
|
||
class MyFloat32Array extends Float32Array { | ||
} | ||
|
||
class MyBigInt64Array extends BigInt64Array { | ||
} | ||
|
||
const builtinCtors = [ | ||
Uint8Array, | ||
Int8Array, | ||
Uint16Array, | ||
Int16Array, | ||
Uint32Array, | ||
Int32Array, | ||
Float32Array, | ||
Float64Array, | ||
Uint8ClampedArray, | ||
BigUint64Array, | ||
BigInt64Array | ||
]; | ||
|
||
const ctors = [ | ||
...builtinCtors, | ||
MyUint8Array, | ||
MyFloat32Array, | ||
MyBigInt64Array | ||
]; | ||
|
||
function CreateResizableArrayBuffer(byteLength, maxByteLength) { | ||
return new ArrayBuffer(byteLength, { maxByteLength: maxByteLength }); | ||
} | ||
|
||
function WriteToTypedArray(array, index, value) { | ||
if (array instanceof BigInt64Array || array instanceof BigUint64Array) { | ||
array[index] = BigInt(value); | ||
} else { | ||
array[index] = value; | ||
} | ||
} | ||
|
||
function ArrayFindIndexHelper(ta, p) { | ||
return Array.prototype.findIndex.call(ta, p); | ||
} | ||
|
||
function FindIndexShrinkMidIteration() { | ||
// Orig. array: [0, 2, 4, 6] | ||
// [0, 2, 4, 6] << fixedLength | ||
// [4, 6] << fixedLengthWithOffset | ||
// [0, 2, 4, 6, ...] << lengthTracking | ||
// [4, 6, ...] << lengthTrackingWithOffset | ||
function CreateRabForTest(ctor) { | ||
const rab = CreateResizableArrayBuffer(4 * ctor.BYTES_PER_ELEMENT, 8 * 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); | ||
} | ||
return rab; | ||
} | ||
let values; | ||
let rab; | ||
let resizeAfter; | ||
let resizeTo; | ||
function CollectValuesAndResize(n) { | ||
if (typeof n == 'bigint') { | ||
values.push(Number(n)); | ||
} else { | ||
values.push(n); | ||
} | ||
if (values.length == resizeAfter) { | ||
rab.resize(resizeTo); | ||
} | ||
return false; | ||
} | ||
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(ArrayFindIndexHelper(fixedLength, CollectValuesAndResize), -1); | ||
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.sameValue(ArrayFindIndexHelper(fixedLengthWithOffset, CollectValuesAndResize), -1); | ||
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.sameValue(ArrayFindIndexHelper(lengthTracking, CollectValuesAndResize), -1); | ||
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.sameValue(ArrayFindIndexHelper(lengthTrackingWithOffset, CollectValuesAndResize), -1); | ||
assert.compareArray(values, [ | ||
4, | ||
undefined | ||
]); | ||
} | ||
} | ||
|
||
FindIndexShrinkMidIteration(); |
Oops, something went wrong.