From fcc58bfbba99682838b79001d078832788f5c779 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 4 Aug 2025 17:17:45 +0200 Subject: [PATCH] Issue #2838 - Update tests --- js/src/jit-test/tests/asm.js/testBasic.js | 4 +-- js/src/jit-test/tests/basic/bug1292858.js | 12 ++++---- js/src/jit-test/tests/ion/bug1298354.js | 2 +- .../constructor-length-too-large.js | 30 +++++++++++++++++++ js/src/tests/js1_8_5/extensions/typedarray.js | 8 ++--- 5 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 js/src/tests/ecma_6/TypedArray/constructor-length-too-large.js diff --git a/js/src/jit-test/tests/asm.js/testBasic.js b/js/src/jit-test/tests/asm.js/testBasic.js index f47a837f3a..aa710eb219 100644 --- a/js/src/jit-test/tests/asm.js/testBasic.js +++ b/js/src/jit-test/tests/asm.js/testBasic.js @@ -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)); diff --git a/js/src/jit-test/tests/basic/bug1292858.js b/js/src/jit-test/tests/basic/bug1292858.js index 788eb96523..f905274e17 100644 --- a/js/src/jit-test/tests/basic/bug1292858.js +++ b/js/src/jit-test/tests/basic/bug1292858.js @@ -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; } diff --git a/js/src/jit-test/tests/ion/bug1298354.js b/js/src/jit-test/tests/ion/bug1298354.js index 73502df5a7..b443031fe1 100644 --- a/js/src/jit-test/tests/ion/bug1298354.js +++ b/js/src/jit-test/tests/ion/bug1298354.js @@ -3,7 +3,7 @@ new Function(` while (true) { try { - var buf = new Uint8ClampedArray(a); + var buf = new Uint8ClampedArray(-1); } catch (e) { break; } diff --git a/js/src/tests/ecma_6/TypedArray/constructor-length-too-large.js b/js/src/tests/ecma_6/TypedArray/constructor-length-too-large.js new file mode 100644 index 0000000000..6b6226851b --- /dev/null +++ b/js/src/tests/ecma_6/TypedArray/constructor-length-too-large.js @@ -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); diff --git a/js/src/tests/js1_8_5/extensions/typedarray.js b/js/src/tests/js1_8_5/extensions/typedarray.js index 885f94551f..c0ac5a35ce 100644 --- a/js/src/tests/js1_8_5/extensions/typedarray.js +++ b/js/src/tests/js1_8_5/extensions/typedarray.js @@ -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);