Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/waitAsync/nan-for-timeout-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 /*---
6 esid: sec-atomics.waitasync
7 description: >
8 NaN timeout arg should result in an infinite timeout
9 info: |
10 Atomics.waitAsync( typedArray, index, value, timeout )
11
12 1. Return DoWait(async, typedArray, index, value, timeout).
13
14 DoWait ( mode, typedArray, index, value, timeout )
15
16 6. Let q be ? ToNumber(timeout).
17
18 flags: [async]
19 includes: [atomicsHelper.js]
20 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, arrow-function, async-functions]
21 ---*/
22 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
23
24 const RUNNING = 1;
25
26 $262.agent.start(`
27 $262.agent.receiveBroadcast(async (sab) => {
28 const i32a = new Int32Array(sab);
29 Atomics.add(i32a, ${RUNNING}, 1);
30
31 $262.agent.report(await Atomics.waitAsync(i32a, 0, 0, NaN).value); // NaN => +Infinity
32 $262.agent.leaving();
33 });
34 `);
35
36 const i32a = new Int32Array(
37 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
38 );
39
40 $262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
41
42 assert.sameValue(agentCount, 1, 'The value of `agentCount` is 1');
43
44 assert.sameValue(Atomics.notify(i32a, 0), 1, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0) must return 1');
45
46 assert.sameValue(
47 await $262.agent.getReportAsync(),
48 'ok',
49 '(await $262.agent.getReportAsync()) resolves to the value "ok"'
50 );
51
52 }).then($DONE, $DONE);
53
54