Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/wait/nan-for-timeout.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics
2 // Copyright (C) 2018 Amal Hussein. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-atomics.wait
7 description: >
8 NaN timeout arg should result in an infinite timeout
9 info: |
10 Atomics.wait( typedArray, index, value, timeout )
11
12 4.Let q be ? ToNumber(timeout).
13 ...
14 Undefined Return NaN.
15 5.If q is NaN, let t be +∞, else let t be max(q, 0)
16
17 includes: [atomicsHelper.js]
18 features: [Atomics, SharedArrayBuffer, TypedArray]
19 ---*/
20
21 const RUNNING = 1;
22
23 $262.agent.start(`
24 $262.agent.receiveBroadcast(function(sab) {
25 const i32a = new Int32Array(sab);
26 Atomics.add(i32a, ${RUNNING}, 1);
27
28 $262.agent.report(Atomics.wait(i32a, 0, 0, NaN)); // NaN => +Infinity
29 $262.agent.leaving();
30 });
31 `);
32
33 const i32a = new Int32Array(
34 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
35 );
36
37 $262.agent.safeBroadcast(i32a);
38 $262.agent.waitUntil(i32a, RUNNING, 1);
39
40 // Try to yield control to ensure the agent actually started to wait.
41 $262.agent.tryYield();
42
43 assert.sameValue(Atomics.notify(i32a, 0), 1, 'Atomics.notify(i32a, 0) returns 1');
44 assert.sameValue($262.agent.getReport(), "ok", '$262.agent.getReport() returns "ok"');
45
46 reportCompare(0, 0);