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/detached-array-buffer-checks.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/detached-array-buffer-checks.js | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/detached-array-buffer-checks.js b/js/src/tests/non262/TypedArray/detached-array-buffer-checks.js new file mode 100644 index 0000000000..55256fb29d --- /dev/null +++ b/js/src/tests/non262/TypedArray/detached-array-buffer-checks.js @@ -0,0 +1,107 @@ +// Nearly every %TypedArray%.prototype method should throw a TypeError when called +// atop a detached array buffer. Here we check verify that this holds true for +// all relevant functions. +let buffer = new ArrayBuffer(32); +let array = new Int32Array(buffer); +detachArrayBuffer(buffer); + +// A nice poisoned callable to ensure that we fail on a detached buffer check +// before a method attempts to do anything with its arguments. +var POISON = (function() { + var internalTarget = {}; + var throwForAllTraps = + new Proxy(internalTarget, { get(target, prop, receiver) { + assertEq(target, internalTarget); + assertEq(receiver, throwForAllTraps); + throw "FAIL: " + prop + " trap invoked"; + }}); + return new Proxy(throwForAllTraps, throwForAllTraps); +}); + + +assertThrowsInstanceOf(() => { + array.copyWithin(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.entries(); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.fill(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.filter(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.find(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.findIndex(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.forEach(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.indexOf(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.includes(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.join(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.keys(); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.lastIndexOf(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.map(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.reduce(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.reduceRight(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.reverse(); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.slice(POISON, POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.some(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.values(); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.every(POISON); +}, TypeError); + +assertThrowsInstanceOf(() => { + array.sort(POISON); +}, TypeError); + +if (typeof reportCompare === "function") + reportCompare(true, true); |