Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/value-not-equal-agent.js

raw
1 // |reftest| shell-option(--setpref=atomics_wait_async) skip-if(!this.hasOwnProperty('SharedArrayBuffer')||!this.hasOwnProperty('Atomics')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))||!xulRuntime.shell) async -- SharedArrayBuffer,Atomics is not enabled unconditionally, ARM64 Simulator cannot emulate atomics, requires shell-options
2 // Copyright (C) 2020 Rick Waldron. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: sec-atomics.waitasync
6 description: >
7 Returns "not-equal" when value arg does not match an index in the typedArray
8 info: |
9 Atomics.waitAsync( typedArray, index, value, timeout )
10
11 1. Return DoWait(async, typedArray, index, value, timeout).
12
13 DoWait ( mode, typedArray, index, value, timeout )
14
15 16. Let w be ! AtomicLoad(typedArray, i).
16 17. If v is not equal to w, then
17 a. Perform LeaveCriticalSection(WL).
18 b. If mode is sync, then
19 i. Return the String "not-equal".
20 c. Perform ! Call(capability.[[Resolve]], undefined, « "not-equal" »).
21 d. Return promiseCapability.[[Promise]].
22
23 flags: [async]
24 includes: [atomicsHelper.js]
25 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions]
26 ---*/
27 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
28 const RUNNING = 1;
29 const value = 42n;
30
31 $262.agent.start(`
32 $262.agent.receiveBroadcast(function(sab) {
33 const i64a = new BigInt64Array(sab);
34 Atomics.add(i64a, ${RUNNING}, 1n);
35 $262.agent.report(Atomics.store(i64a, 0, 42n));
36 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n).value);
37 $262.agent.leaving();
38 });
39 `);
40
41 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4));
42
43 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => {
44 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n');
45
46 assert.sameValue(
47 await $262.agent.getReportAsync(),
48 value.toString(),
49 '(await $262.agent.getReportAsync()) must return the same value returned by value.toString()'
50 );
51
52 assert.sameValue(
53 await $262.agent.getReportAsync(),
54 'not-equal',
55 '(await $262.agent.getReportAsync()) resolves to the value "not-equal"'
56 );
57
58 assert.sameValue(
59 Atomics.notify(i64a, 0, 1),
60 0,
61 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0, 1) must return 0'
62 );
63 }).then($DONE, $DONE);