Issue #2838 - Update tests

This commit is contained in:
Moonchild 2025-08-04 17:17:45 +02:00 • committed by roytam1
commit fcc58bfbba
5 changed files with 43 additions and 13 deletions

View file

@ -69,8 +69,8 @@ assertEq(asmLink(asmCompile('glob', USE_ASM + 'var im=glob.Math.imul; function f
var module = asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f');
assertAsmLinkAlwaysFail(module, null, null);
assertAsmLinkAlwaysFail(module, this, null, null);
assertAsmLinkAlwaysFail(module, this, null, null);
assertAsmLinkFail(module, this, null, null);
assertAsmLinkFail(module, this, null, null);
assertAsmLinkAlwaysFail(module, this, null, new ArrayBuffer(1));
assertAsmLinkFail(module, this, null, new ArrayBuffer(4));
assertAsmLinkFail(module, this, null, new ArrayBuffer(100));

View file

@ -4,8 +4,8 @@ try {
var buf = new Uint8ClampedArray(a);
throw new Error("didn't throw");
} catch (e) {
assertEq(e instanceof TypeError, true,
"expected TypeError, instead threw: " + e);
assertEq(e instanceof RangeError, true,
"expected RangeError, instead threw: " + e);
caughtInvalidArguments = true;
}
assertEq(caughtInvalidArguments, true);
@ -20,8 +20,8 @@ while (true) {
assertEq(buf.length, 300);
} catch (e) {
assertEq(a, -1);
assertEq(e instanceof TypeError, true,
"expected TypeError, instead threw: " + e);
assertEq(e instanceof RangeError, true,
"expected RangeError, instead threw: " + e);
caughtInvalidArguments = true;
break;
}
@ -38,8 +38,8 @@ while (true) {
assertEq(buf.length, 0);
} catch (e) {
assertEq(a, -1);
assertEq(e instanceof TypeError, true,
"expected TypeError, instead threw: " + e);
assertEq(e instanceof RangeError, true,
"expected RangeError, instead threw: " + e);
caughtInvalidArguments = true;
break;
}

View file

@ -3,7 +3,7 @@
new Function(`
while (true) {
try {
var buf = new Uint8ClampedArray(a);
var buf = new Uint8ClampedArray(-1);
} catch (e) {
break;
}

View file

@ -0,0 +1,30 @@
// Test that all TypedArray constructor variants throw a RangeError when
// attempting to create a too large array.
// The maximum typed array length is (currently) limited to
// `(INT32_MAX / BYTES_PER_ELEMENT) - 1`.
const INT32_MAX = 2**31 - 1;
// 22.2.4.2 TypedArray ( length )
for (let TA of typedArrayConstructors) {
assertThrows(() => new TA(INT32_MAX), RangeError);
assertThrows(() => new TA(INT32_MAX >> Math.log2(TA.BYTES_PER_ELEMENT)), RangeError);
}
// Test disabled because allocating a 2**30 Int8Array easily leads to OOMs.
//
// 22.2.4.3 TypedArray ( typedArray )
// const largeInt8Array = new Int8Array(2**30);
// for (let TA of typedArrayConstructors.filter(c => c.BYTES_PER_ELEMENT > 1)) {
// assertThrows(() => new TA(largeInt8Array), RangeError);
// }
// 22.2.4.4 TypedArray ( object )
for (let TA of typedArrayConstructors) {
assertThrows(() => new TA({length: INT32_MAX}), RangeError);
assertThrows(() => new TA({length: INT32_MAX >> Math.log2(TA.BYTES_PER_ELEMENT)}), RangeError);
}
if (typeof reportCompare === "function")
reportCompare(true, true);

View file

@ -436,7 +436,7 @@ function test()
a = new ArrayBuffer(0x10);
checkThrows(() => new Uint32Array(buffer, 4, 0x3FFFFFFF));
checkThrows(() => new Float32Array(null));
check(() => new Float32Array(null).length === 0);
a = new Uint8Array(0x100);
b = Uint32Array.prototype.subarray.apply(a, [0, 0x100]);
@ -496,9 +496,9 @@ function test()
check(() => (new Float32Array(Math.sqrt(4))).length == 2);
check(() => (new Float32Array({ length: 10 })).length == 10);
check(() => (new Float32Array({})).length == 0);
checkThrows(() => new Float32Array("3"));
checkThrows(() => new Float32Array(null));
checkThrows(() => new Float32Array(undefined));
check(() => new Float32Array("3").length === 3);
check(() => new Float32Array(null).length === 0);
check(() => new Float32Array(undefined).length === 0);
// check that NaN conversions happen correctly with array conversions
check(() => (new Int32Array([NaN])[0]) == 0);