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/Atomics | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Atomics')
-rw-r--r-- | js/src/tests/non262/Atomics/browser.js | 0 | ||||
-rw-r--r-- | js/src/tests/non262/Atomics/cross-compartment.js | 109 | ||||
-rw-r--r-- | js/src/tests/non262/Atomics/detached-buffers.js | 94 | ||||
-rw-r--r-- | js/src/tests/non262/Atomics/shell.js | 0 |
4 files changed, 203 insertions, 0 deletions
diff --git a/js/src/tests/non262/Atomics/browser.js b/js/src/tests/non262/Atomics/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/Atomics/browser.js diff --git a/js/src/tests/non262/Atomics/cross-compartment.js b/js/src/tests/non262/Atomics/cross-compartment.js new file mode 100644 index 0000000000..8ef46bda38 --- /dev/null +++ b/js/src/tests/non262/Atomics/cross-compartment.js @@ -0,0 +1,109 @@ +// |reftest| skip-if(!this.Atomics||!this.SharedArrayBuffer) fails-if(!xulRuntime.shell) + +const otherGlobal = newGlobal(); + +const intArrayConstructors = [ + otherGlobal.Int32Array, + otherGlobal.Int16Array, + otherGlobal.Int8Array, + otherGlobal.Uint32Array, + otherGlobal.Uint16Array, + otherGlobal.Uint8Array, +]; + +// Atomics.load +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + ta[0] = 1; + + assertEq(Atomics.load(ta, 0), 1); +} + +// Atomics.store +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + + Atomics.store(ta, 0, 1); + + assertEq(ta[0], 1); +} + +// Atomics.compareExchange +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + ta[0] = 1; + + let val = Atomics.compareExchange(ta, 0, 1, 2); + + assertEq(val, 1); + assertEq(ta[0], 2); +} + +// Atomics.exchange +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + ta[0] = 1; + + let val = Atomics.exchange(ta, 0, 2); + + assertEq(val, 1); + assertEq(ta[0], 2); +} + +// Atomics.add +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + ta[0] = 1; + + let val = Atomics.add(ta, 0, 2); + + assertEq(val, 1); + assertEq(ta[0], 3); +} + +// Atomics.sub +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + ta[0] = 3; + + let val = Atomics.sub(ta, 0, 2); + + assertEq(val, 3); + assertEq(ta[0], 1); +} + +// Atomics.and +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + ta[0] = 3; + + let val = Atomics.and(ta, 0, 1); + + assertEq(val, 3); + assertEq(ta[0], 1); +} + +// Atomics.or +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + ta[0] = 2; + + let val = Atomics.or(ta, 0, 1); + + assertEq(val, 2); + assertEq(ta[0], 3); +} + +// Atomics.xor +for (let TA of intArrayConstructors) { + let ta = new TA(new otherGlobal.SharedArrayBuffer(4)); + ta[0] = 3; + + let val = Atomics.xor(ta, 0, 1); + + assertEq(val, 3); + assertEq(ta[0], 2); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Atomics/detached-buffers.js b/js/src/tests/non262/Atomics/detached-buffers.js new file mode 100644 index 0000000000..e3bc269b40 --- /dev/null +++ b/js/src/tests/non262/Atomics/detached-buffers.js @@ -0,0 +1,94 @@ +// |reftest| skip-if(!this.Atomics) + +const intArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, +]; + +function badValue(ta) { + return { + valueOf() { + detachArrayBuffer(ta.buffer); + return 0; + } + }; +} + +// Atomics.load +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.load(ta, badValue(ta)), TypeError); +} + +// Atomics.store +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.store(ta, badValue(ta), 0), TypeError); + assertThrowsInstanceOf(() => Atomics.store(ta, 0, badValue(ta)), TypeError); +} + +// Atomics.compareExchange +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.compareExchange(ta, badValue(ta), 0, 0), TypeError); + assertThrowsInstanceOf(() => Atomics.compareExchange(ta, 0, badValue(ta), 0), TypeError); + assertThrowsInstanceOf(() => Atomics.compareExchange(ta, 0, 0, badValue(ta)), TypeError); +} + +// Atomics.exchange +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.exchange(ta, badValue(ta), 0), TypeError); + assertThrowsInstanceOf(() => Atomics.exchange(ta, 0, badValue(ta)), TypeError); +} + +// Atomics.add +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.add(ta, badValue(ta), 0), TypeError); + assertThrowsInstanceOf(() => Atomics.add(ta, 0, badValue(ta)), TypeError); +} + +// Atomics.sub +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.sub(ta, badValue(ta), 0), TypeError); + assertThrowsInstanceOf(() => Atomics.sub(ta, 0, badValue(ta)), TypeError); +} + +// Atomics.and +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.and(ta, badValue(ta), 0), TypeError); + assertThrowsInstanceOf(() => Atomics.and(ta, 0, badValue(ta)), TypeError); +} + +// Atomics.or +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.or(ta, badValue(ta), 0), TypeError); + assertThrowsInstanceOf(() => Atomics.or(ta, 0, badValue(ta)), TypeError); +} + +// Atomics.xor +for (let TA of intArrayConstructors) { + let ta = new TA(1); + + assertThrowsInstanceOf(() => Atomics.xor(ta, badValue(ta), 0), TypeError); + assertThrowsInstanceOf(() => Atomics.xor(ta, 0, badValue(ta)), TypeError); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Atomics/shell.js b/js/src/tests/non262/Atomics/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/non262/Atomics/shell.js |