mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
First pass at helper sketch
This commit is contained in:
parent
79c4496559
commit
6ad7c115b9
@ -8,6 +8,7 @@ defines:
|
||||
- floatArrayConstructors
|
||||
- intArrayConstructors
|
||||
- TypedArray
|
||||
- createTypedArrayVariations
|
||||
- testWithTypedArrayConstructors
|
||||
- testWithAtomicsFriendlyTypedArrayConstructors
|
||||
- testWithNonAtomicsFriendlyTypedArrayConstructors
|
||||
@ -120,3 +121,27 @@ function testTypedArrayConversions(byteConversionValues, fn) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function createTypedArrayVariations(TA, values) {
|
||||
const rab = new ArrayBuffer(4 * TA.BYTES_PER_ELEMENT, { maxByteLength: 8 * TA.BYTES_PER_ELEMENT });
|
||||
|
||||
let nonresizable = new TA(values);
|
||||
let fixedLength = new TA(rab, 0, values.length);
|
||||
let lengthTracking = new TA(rab, 0);
|
||||
let fixedLengthWithOffset = new TA(rab, 2 * TA.BYTES_PER_ELEMENT, (values.length / 2));
|
||||
let lengthTrackingWithOffset = new TA(rab, 2 * TA.BYTES_PER_ELEMENT);
|
||||
|
||||
// Writes data to the buffer backing all the arrays
|
||||
let ta_write = new TA(rab);
|
||||
for (let i = 0; i < values.length; ++i) {
|
||||
ta_write[i] = values[i];
|
||||
}
|
||||
|
||||
return {
|
||||
nonresizable,
|
||||
fixedLength,
|
||||
lengthTracking,
|
||||
fixedLengthWithOffset,
|
||||
lengthTrackingWithOffset,
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,32 @@ assert.sameValue(
|
||||
|
||||
testWithTypedArrayConstructors(TA => {
|
||||
assert.sameValue(typeof TA.prototype.at, 'function', 'The value of `typeof TA.prototype.at` is "function"');
|
||||
let a = new TA([1, 2, 3, 4]);
|
||||
|
||||
assert.sameValue(a.at(0), 1, 'a.at(0) must return 1');
|
||||
assert.sameValue(a.at(1), 2, 'a.at(1) must return 2');
|
||||
assert.sameValue(a.at(2), 3, 'a.at(2) must return 3');
|
||||
assert.sameValue(a.at(3), 4, 'a.at(3) must return 4');
|
||||
const {
|
||||
nonresizable,
|
||||
fixedLength,
|
||||
lengthTracking,
|
||||
fixedLengthWithOffset,
|
||||
lengthTrackingWithOffset
|
||||
} = createTypedArrayVariations(TA, [1, 2, 3, 4]);
|
||||
|
||||
[
|
||||
nonresizable,
|
||||
fixedLength,
|
||||
lengthTracking,
|
||||
].forEach((a) => {
|
||||
assert.sameValue(a.at(0), 1, 'a.at(0) must return 1')
|
||||
assert.sameValue(a.at(1), 2, 'a.at(1) must return 2')
|
||||
assert.sameValue(a.at(2), 3, 'a.at(2) must return 3')
|
||||
assert.sameValue(a.at(3), 4, 'a.at(3) must return 4')
|
||||
});
|
||||
|
||||
[
|
||||
fixedLengthWithOffset,
|
||||
lengthTrackingWithOffset
|
||||
].forEach((a) => {
|
||||
assert.sameValue(a.at(0), 3, 'a.at(2) must return 3')
|
||||
assert.sameValue(a.at(1), 4, 'a.at(3) must return 4')
|
||||
})
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user