summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Atomics/waitAsync/good-views.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Atomics/waitAsync/good-views.js
parentInitial commit. (diff)
downloadfirefox-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/waitAsync/good-views.js')
-rw-r--r--js/src/tests/test262/built-ins/Atomics/waitAsync/good-views.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Atomics/waitAsync/good-views.js b/js/src/tests/test262/built-ins/Atomics/waitAsync/good-views.js
new file mode 100644
index 0000000000..343b706a41
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Atomics/waitAsync/good-views.js
@@ -0,0 +1,70 @@
+// |reftest| skip async -- Atomics.waitAsync is not supported
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-atomics.waitasync
+description: >
+ Test Atomics.waitAsync on arrays that allow atomic operations
+flags: [async]
+includes: [atomicsHelper.js, asyncHelpers.js]
+features: [Atomics.waitAsync, Atomics]
+---*/
+assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
+
+$262.agent.start(`
+ (async () => {
+ var sab = new SharedArrayBuffer(1024);
+ 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 " + (await Atomics.waitAsync(view, 0, 0, 0).value))
+ $262.agent.report("B " + (await Atomics.waitAsync(view, 0, 37, 0).value));
+
+ const results = [];
+ // 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);
+ results.push(await Atomics.waitAsync(view, Idx, 0).value);
+ }
+ $262.agent.report("C " + results.join(","));
+ $262.agent.leaving();
+ })();
+`);
+
+
+asyncTest(async () => {
+ const outcomes = [];
+
+ for (let i = 0; i < 3; i++) {
+ outcomes.push(await $262.agent.getReportAsync());
+ }
+
+ assert.sameValue(
+ outcomes[0],
+ 'A timed-out',
+ 'The value of outcomes[0] is "A timed-out"'
+ );
+
+ assert.sameValue(
+ outcomes[1],
+ 'B not-equal',
+ 'The value of outcomes[1] is "B not-equal"'
+ );
+ assert.sameValue(
+ outcomes[2],
+ 'C not-equal,not-equal,not-equal,not-equal,not-equal',
+ 'The value of outcomes[2] is "C not-equal,not-equal,not-equal,not-equal,not-equal"'
+ );
+});