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/test262/built-ins/Atomics/wait/good-views.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Atomics/wait/good-views.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Atomics/wait/good-views.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Atomics/wait/good-views.js b/js/src/tests/test262/built-ins/Atomics/wait/good-views.js new file mode 100644 index 0000000000..67e4da6314 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/wait/good-views.js @@ -0,0 +1,69 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Test Atomics.wait on arrays that allow atomic operations, + in an Agent that is allowed to wait. +includes: [atomicsHelper.js] +features: [Atomics] +---*/ + +// Let's assume 'wait' is not allowed on the main thread, +// even in the shell. + +$262.agent.start(` + var sab = new SharedArrayBuffer(1024); + var ab = new ArrayBuffer(16); + + var good_indices = [ (view) => 0/-1, // -0 + (view) => '-0', + (view) => view.length - 1, + (view) => ({ valueOf: () => 0 }), + (view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString + ]; + + var view = new Int32Array(sab, 32, 20); + + view[0] = 0; + $262.agent.report("A " + Atomics.wait(view, 0, 0, 0)) + $262.agent.report("B " + Atomics.wait(view, 0, 37, 0)); + + // In-bounds boundary cases for indexing + for ( let IdxGen of good_indices ) { + let Idx = IdxGen(view); + view.fill(0); + // Atomics.store() computes an index from Idx in the same way as other + // Atomics operations, not quite like view[Idx]. + Atomics.store(view, Idx, 37); + $262.agent.report("C " + Atomics.wait(view, Idx, 0)); + } + + $262.agent.report("done"); + $262.agent.leaving(); +`); + +assert.sameValue( + $262.agent.getReport(), + 'A timed-out', + '$262.agent.getReport() returns "A timed-out"' +); + +assert.sameValue( + $262.agent.getReport(), + 'B not-equal', + '$262.agent.getReport() returns "B not-equal"' +); + +var r; +while ((r = $262.agent.getReport()) !== "done") { + assert.sameValue( + r, + 'C not-equal', + '$262.agent.getReport() returns "C not-equal"' + ); +} + +reportCompare(0, 0); |