diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/non262/TypedArray/constructor-length-too-large.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/TypedArray/constructor-length-too-large.js')
-rw-r--r-- | js/src/tests/non262/TypedArray/constructor-length-too-large.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/constructor-length-too-large.js b/js/src/tests/non262/TypedArray/constructor-length-too-large.js new file mode 100644 index 0000000000..7a7a785041 --- /dev/null +++ b/js/src/tests/non262/TypedArray/constructor-length-too-large.js @@ -0,0 +1,40 @@ +// |reftest| skip-if(!xulRuntime.shell) + +// Test that all TypedArray constructor variants throw a RangeError when +// attempting to create a too large array. + +// The maximum typed array length is limited to `(INT32_MAX/BYTES_PER_ELEMENT)` +// on all 32-bit systems; on 64-bit systems the limit is 8GB presently. + +const INT32_MAX = 2**31 - 1; +const EIGHTGB = 8 * 1024 * 1024 * 1024; + +function tooLarge(elementSize) { + if (largeArrayBufferSupported()) { + return (EIGHTGB / elementSize) + 1; + } + return (INT32_MAX + 1) / elementSize; +} + +// 22.2.4.2 TypedArray ( length ) +for (let TA of typedArrayConstructors) { + assertThrowsInstanceOf(() => new TA(tooLarge(1)), RangeError); + assertThrowsInstanceOf(() => new TA(tooLarge(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)) { +// assertThrowsInstanceOf(() => new TA(largeInt8Array), RangeError); +// } + +// 22.2.4.4 TypedArray ( object ) +for (let TA of typedArrayConstructors) { + assertThrowsInstanceOf(() => new TA({length: tooLarge(1)}), RangeError); + assertThrowsInstanceOf(() => new TA({length: tooLarge(TA.BYTES_PER_ELEMENT)}), RangeError); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |