Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0456694
Remove unused parameter from testWith*TypedArrayConstructors callbacks
gibson042 Jul 21, 2025
c1fb48f
Merge harness/testBigIntTypedArray.js into harness/testTypedArray.js
gibson042 Jul 21, 2025
1ac84ed
Replace includes of harness/testBigIntTypedArray.js
gibson042 Jul 21, 2025
57e0e2c
Generalize testWithTypedArrayConstructors to invoke its callback with…
gibson042 Jul 22, 2025
f9092a0
Make use of the argument factory provided by testWithTypedArrayConstr…
gibson042 Jul 21, 2025
e7c867b
Clean up tests broken by use of the TypedArray constructor argument f…
gibson042 Jul 22, 2025
5a7ad96
Remove unnecessary constructor argument factory restriction in TypedA…
gibson042 Jul 22, 2025
30624e4
Conditionally support bigint TypedArray constructors in harness/testT…
gibson042 Jul 23, 2025
a8eeab3
[immutable-arraybuffer] Include immutable ArrayBuffers in TypedArray …
gibson042 Jul 22, 2025
71a0ec0
Skip immutable ArrayBuffers in TypedArray.{from,of} tests
gibson042 Jul 21, 2025
dec4ca1
Remove unnecessary mutation in TypedArray method tests
gibson042 Jul 22, 2025
b488c98
Skip immutable ArrayBuffers in tests of TypedArray methods that mutat…
gibson042 Jul 21, 2025
0570e90
Skip immutable ArrayBuffers in more mutation-dependent tests
gibson042 Jul 22, 2025
4ef9bec
Skip immutable ArrayBuffers in TypedArray Set/DefineOwnProperty tests
gibson042 Jul 22, 2025
0bc9153
[immutable-arraybuffer] Cover existing read-only TypedArray methods b…
gibson042 Jul 23, 2025
4d92336
TA.filter Symbol.species returning an instance backed by an immutable…
gibson042 Jul 23, 2025
47aa1ca
TA.map Symbol.species returning an instance backed by an immutable bu…
gibson042 Jul 23, 2025
b283db3
TA.slice Symbol.species returning an instance backed by an immutable …
gibson042 Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion harness/features.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
atomicsHelper: [Atomics]
typeCoercion.js: [Symbol.toPrimitive, BigInt]
testAtomics.js: [ArrayBuffer, Atomics, DataView, SharedArrayBuffer, Symbol, TypedArray]
testBigIntTypedArray.js: [BigInt, TypedArray]
testTypedArray.js: [TypedArray]
isConstructor.js: [Reflect.construct]
40 changes: 0 additions & 40 deletions harness/testBigIntTypedArray.js

This file was deleted.

271 changes: 256 additions & 15 deletions harness/testTypedArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ defines:
- intArrayConstructors
- typedArrayConstructors
- TypedArray
- testWithAllTypedArrayConstructors
- testWithTypedArrayConstructors
- testWithBigIntTypedArrayConstructors
- nonAtomicsFriendlyTypedArrayConstructors
- testWithAtomicsFriendlyTypedArrayConstructors
- testWithNonAtomicsFriendlyTypedArrayConstructors
Expand All @@ -34,45 +36,284 @@ var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedAr

// Float16Array is a newer feature
// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it
if (typeof Float16Array !== 'undefined') {
if (typeof Float16Array !== "undefined") {
floatArrayConstructors.push(Float16Array);
}

var bigIntArrayConstructors = [];
if (typeof BigInt64Array !== "undefined") {
bigIntArrayConstructors.push(BigInt64Array);
}
if (typeof BigUint64Array !== "undefined") {
bigIntArrayConstructors.push(BigUint64Array);
}

/**
* Array containing every non-bigint typed array constructor.
*/

var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors);

/**
* Array containing every typed array constructor, including those with bigint values.
*/
var allTypedArrayConstructors = typedArrayConstructors.concat(bigIntArrayConstructors);

/**
* The %TypedArray% intrinsic constructor function.
*/
var TypedArray = Object.getPrototypeOf(Int8Array);

function isPrimitive(val) {
return !val || (typeof val !== "object" && typeof val !== "function");
}

function makePassthrough(TA, primitiveOrIterable) {
return primitiveOrIterable;
}

function makeArray(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable);
// Only values between 0 and 2**53 - 1 inclusive can get mapped into TA contents.
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return Array.from({ length: n }, function(){ return "0"; });
}
return Array.from(primitiveOrIterable);
}

function makeArrayLike(TA, primitiveOrIterable) {
var arr = makeArray(TA, primitiveOrIterable);
if (isPrimitive(arr)) return arr;
var obj = { length: arr.length };
for (var i = 0; i < obj.length; i++) obj[i] = arr[i];
return obj;
}

var makeIterable;
if (typeof Symbol !== "undefined" && Symbol.iterator) {
makeIterable = function makeIterable(TA, primitiveOrIterable) {
var src = makeArray(TA, primitiveOrIterable);
if (isPrimitive(src)) return src;
var obj = {};
obj[Symbol.iterator] = function() { return src[Symbol.iterator](); };
return obj;
};
}

function makeArrayBuffer(TA, primitiveOrIterable) {
var arr = makeArray(TA, primitiveOrIterable);
if (isPrimitive(arr)) return arr;
return new TA(arr).buffer;
}

var makeResizableArrayBuffer, makeGrownArrayBuffer, makeShrunkArrayBuffer, makeImmutableArrayBuffer;
if (ArrayBuffer.prototype.resize) {
var copyIntoArrayBuffer = function(destBuffer, srcBuffer) {
var destView = new Uint8Array(destBuffer);
var srcView = new Uint8Array(srcBuffer);
for (var i = 0; i < srcView.length; i++) destView[i] = srcView[i];
return destBuffer;
};

makeResizableArrayBuffer = function makeResizableArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return new ArrayBuffer(n, { maxByteLength: n * 2 });
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var resizable = new ArrayBuffer(byteLength, { maxByteLength: byteLength * 2 });
return copyIntoArrayBuffer(resizable, fixed);
};

makeGrownArrayBuffer = function makeGrownArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
var grown = new ArrayBuffer(Math.floor(n / 2), { maxByteLength: n });
grown.resize(n);
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var grown = new ArrayBuffer(Math.floor(byteLength / 2), { maxByteLength: byteLength });
grown.resize(byteLength);
return copyIntoArrayBuffer(grown, fixed);
};

makeShrunkArrayBuffer = function makeShrunkArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
var shrunk = new ArrayBuffer(n * 2, { maxByteLength: n * 2 });
shrunk.resize(n);
}
var fixed = makeArrayBuffer(TA, primitiveOrIterable);
var byteLength = fixed.byteLength;
var shrunk = new ArrayBuffer(byteLength * 2, { maxByteLength: byteLength * 2 });
copyIntoArrayBuffer(shrunk, fixed);
shrunk.resize(byteLength);
return shrunk;
};
}
if (ArrayBuffer.prototype.transferToImmutable) {
makeImmutableArrayBuffer = function makeImmutableArrayBuffer(TA, primitiveOrIterable) {
if (isPrimitive(primitiveOrIterable)) {
var n = Number(primitiveOrIterable) * TA.BYTES_PER_ELEMENT;
if (!(n >= 0 && n < 9007199254740992)) return primitiveOrIterable;
return (new ArrayBuffer(n)).transferToImmutable();
}
var mutable = makeArrayBuffer(TA, primitiveOrIterable);
return mutable.transferToImmutable();
};
}

var typedArrayCtorArgFactories = [makePassthrough, makeArray, makeArrayLike];
if (makeIterable) typedArrayCtorArgFactories.push(makeIterable);
typedArrayCtorArgFactories.push(makeArrayBuffer);
if (makeResizableArrayBuffer) typedArrayCtorArgFactories.push(makeResizableArrayBuffer);
if (makeGrownArrayBuffer) typedArrayCtorArgFactories.push(makeGrownArrayBuffer);
if (makeShrunkArrayBuffer) typedArrayCtorArgFactories.push(makeShrunkArrayBuffer);
if (makeImmutableArrayBuffer) typedArrayCtorArgFactories.push(makeImmutableArrayBuffer);

/**
* @typedef {"passthrough" | "arraylike" | "iterable" | "arraybuffer" | "resizable" | "immutable"} typedArrayArgFactoryFeature
*/

/**
* @param {Function} argFactory
* @param {typedArrayArgFactoryFeature[]} features
* @returns {boolean}
*/
function ctorArgFactoryMatchesSome(argFactory, features) {
for (var i = 0; i < features.length; ++i) {
switch (features[i]) {
case "passthrough":
return argFactory === makePassthrough;
case "arraylike":
return argFactory === makeArray || argFactory === makeArrayLike;
case "iterable":
return argFactory === makeIterable;
case "arraybuffer":
return (
argFactory === makeArrayBuffer ||
argFactory === makeResizableArrayBuffer ||
argFactory === makeGrownArrayBuffer ||
argFactory === makeShrunkArrayBuffer ||
argFactory === makeImmutableArrayBuffer
);
case "resizable":
return (
argFactory === makeResizableArrayBuffer ||
argFactory === makeGrownArrayBuffer ||
argFactory === makeShrunkArrayBuffer
);
case "immutable":
return argFactory === makeImmutableArrayBuffer;
}
throw Test262Error("unknown feature: " + features[i]);
}
}

/**
* Callback for testing a typed array constructor.
*
* @callback typedArrayConstructorCallback
* @param {Function} Constructor the constructor object to test with.
* @param {Function} TypedArrayConstructor the constructor object to test with
* @param {Function} [TypedArrayConstructorArgFactory] a function for making
* a TypedArrayConstructor arguments from a primitive (usually a number) or
* iterable (usually an array)
*/

/**
* Calls the provided function for every typed array constructor.
* Calls the provided function with (typedArrayCtor, typedArrayCtorArgFactory)
* pairs, where typedArrayCtor is Uint8Array/Int8Array/BigInt64Array/etc. and
* typedArrayCtorArgFactory is a function for mapping a primitive (usually a
* number) or iterable (usually an array) into a value suitable as the first
* argument of typedArrayCtor (an Array, arraylike, iterable, or ArrayBuffer).
*
* @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
* @param {Array} selected - An optional Array with filtered typed arrays
* @param {typedArrayConstructorCallback} f - the function to call
* @param {Array} [constructors] - an explict list of TypedArray constructors
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
* initial constructor argument factory functions, rather than starting with
* all argument factories
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
* constructor argument factory functions, after an initial selection
*/
function testWithTypedArrayConstructors(f, selected) {
var constructors = selected || typedArrayConstructors;
for (var i = 0; i < constructors.length; ++i) {
var constructor = constructors[i];
try {
f(constructor);
} catch (e) {
e.message += " (Testing with " + constructor.name + ".)";
throw e;
function testWithAllTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || allTypedArrayConstructors;
var ctorArgFactories = typedArrayCtorArgFactories;
if (includeArgFactories) {
ctorArgFactories = [];
for (var i = 0; i < typedArrayCtorArgFactories.length; ++i) {
if (ctorArgFactoryMatchesSome(typedArrayCtorArgFactories[i], includeArgFactories)) {
ctorArgFactories.push(typedArrayCtorArgFactories[i]);
}
}
}
if (excludeArgFactories) {
ctorArgFactories = ctorArgFactories.slice();
for (var i = ctorArgFactories.length - 1; i >= 0; --i) {
if (ctorArgFactoryMatchesSome(ctorArgFactories[i], excludeArgFactories)) {
ctorArgFactories.splice(i, 1);
}
}
}
if (ctorArgFactories.length === 0) {
throw Test262Error("no arg factories match include " + includeArgFactories + " and exclude " + excludeArgFactories);
}
for (var k = 0; k < ctorArgFactories.length; ++k) {
var argFactory = ctorArgFactories[k];
for (var i = 0; i < ctors.length; ++i) {
var constructor = ctors[i];
var boundArgFactory = argFactory.bind(undefined, constructor);
try {
f(constructor, boundArgFactory);
} catch (e) {
e.message += " (Testing with " + constructor.name + " and " + argFactory.name + ".)";
throw e;
}
}
}
}

/**
* Calls the provided function with (typedArrayCtor, typedArrayCtorArgFactory)
* pairs, where typedArrayCtor is Uint8Array/Int8Array/BigInt64Array/etc. and
* typedArrayCtorArgFactory is a function for mapping a primitive (usually a
* number) or iterable (usually an array) into a value suitable as the first
* argument of typedArrayCtor (an Array, arraylike, iterable, or ArrayBuffer).
*
* typedArrayCtor will not be BigInt64Array or BigUint64Array unless one or both
* of those are explicitly provided.
*
* @param {typedArrayConstructorCallback} f - the function to call
* @param {Array} [constructors] - an explict list of TypedArray constructors
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
* initial constructor argument factory functions, rather than starting with
* all argument factories
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
* constructor argument factory functions, after an initial selection
*/
function testWithTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || typedArrayConstructors;
testWithAllTypedArrayConstructors(f, ctors, includeArgFactories, excludeArgFactories);
}

/**
* Calls the provided function for every BigInt typed array constructor.
*
* @param {typedArrayConstructorCallback} f - the function to call
* @param {Array} [constructors] - an explict list of TypedArray constructors
* @param {typedArrayArgFactoryFeature[]} [includeArgFactories] - for selecting
* initial constructor argument factory functions, rather than starting with
* all argument factories
* @param {typedArrayArgFactoryFeature[]} [excludeArgFactories] - for excluding
* constructor argument factory functions, after an initial selection
*/
function testWithBigIntTypedArrayConstructors(f, constructors, includeArgFactories, excludeArgFactories) {
var ctors = constructors || [BigInt64Array, BigUint64Array];
testWithAllTypedArrayConstructors(f, ctors, includeArgFactories, excludeArgFactories);
}

var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ testWithTypedArrayConstructors(function(TA) {
assert.compareArray(indices, expectedIndices, 'indices (grow)');
assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
assert.sameValue(result, true, 'result (grow)');
});
}, null, ["passthrough"]);
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ testWithTypedArrayConstructors(function(TA) {
assert.compareArray(indices, expectedIndices, 'indices (grow)');
assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
assert.compareArray(result, expectedElements, 'result (grow)');
});
}, null, ["passthrough"]);
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ testWithTypedArrayConstructors(function(TA) {
assert.compareArray(indices, expectedIndices, 'indices (grow)');
assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
assert.sameValue(result, undefined, 'result (grow)');
});
}, null, ["passthrough"]);
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ testWithTypedArrayConstructors(function(TA) {
assert.compareArray(indices, expectedIndices, 'indices (grow)');
assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
assert.sameValue(result, -1, 'result (grow)');
});
}, null, ["passthrough"]);
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ testWithTypedArrayConstructors(function(TA) {
assert.compareArray(indices, expectedIndices, 'indices (grow)');
assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
assert.sameValue(result, undefined, 'result (grow)');
});
}, null, ["passthrough"]);
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ testWithTypedArrayConstructors(function(TA) {
assert.compareArray(indices, expectedIndices, 'indices (grow)');
assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
assert.sameValue(result, -1, 'result (grow)');
});
}, null, ["passthrough"]);
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ testWithTypedArrayConstructors(function(TA) {
assert.compareArray(indices, expectedIndices, 'indices (grow)');
assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
assert.sameValue(result, undefined, 'result (grow)');
});
}, null, ["passthrough"]);
Loading