forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import relevant files from tc39#3888
- Loading branch information
Showing
6 changed files
with
885 additions
and
0 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
test/built-ins/Array/prototype/some/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.some | ||
description: > | ||
Array.p.some behaves correctly when receiver is backed by a resizable | ||
buffer and is grown mid-iteration | ||
features: [resizable-arraybuffer] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
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; | ||
} | ||
} | ||
|
||
const ArraySomeHelper = (ta, ...rest) => { | ||
return Array.prototype.some.call(ta, ...rest); | ||
}; | ||
|
||
function SomeGrowMidIteration() { | ||
// 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(!ArraySomeHelper(fixedLength, CollectValuesAndResize)); | ||
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(!ArraySomeHelper(fixedLengthWithOffset, CollectValuesAndResize)); | ||
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(!ArraySomeHelper(lengthTracking, CollectValuesAndResize)); | ||
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 = []; | ||
rab = rab; | ||
resizeAfter = 1; | ||
resizeTo = 5 * ctor.BYTES_PER_ELEMENT; | ||
assert(!ArraySomeHelper(lengthTrackingWithOffset, CollectValuesAndResize)); | ||
assert.compareArray(values, [ | ||
4, | ||
6 | ||
]); | ||
} | ||
} | ||
|
||
SomeGrowMidIteration(); |
134 changes: 134 additions & 0 deletions
134
test/built-ins/Array/prototype/some/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,134 @@ | ||
// 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.some | ||
description: > | ||
Array.p.some behaves correctly when receiver is backed by a | ||
resizable buffer and is shrunk mid-iteration | ||
features: [resizable-arraybuffer] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
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; | ||
} | ||
} | ||
|
||
const ArraySomeHelper = (ta, ...rest) => { | ||
return Array.prototype.some.call(ta, ...rest); | ||
}; | ||
|
||
function SomeShrinkMidIteration() { | ||
// 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(!ArraySomeHelper(fixedLength, CollectValuesAndResize)); | ||
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(!ArraySomeHelper(fixedLengthWithOffset, CollectValuesAndResize)); | ||
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(!ArraySomeHelper(lengthTracking, CollectValuesAndResize)); | ||
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(!ArraySomeHelper(lengthTrackingWithOffset, CollectValuesAndResize)); | ||
assert.compareArray(values, [4]); | ||
} | ||
} | ||
|
||
SomeShrinkMidIteration(); |
Oops, something went wrong.