diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/TypedArray/constructor-length-too-large.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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); |