Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/true-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 esid: sec-atomics.waitasync
6 description: >
7 True timeout arg should result in an +0 timeout
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 6. Let q be ? ToNumber(timeout).
16
17 flags: [async]
18 includes: [atomicsHelper.js]
19 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions]
20 ---*/
21 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
22 const RUNNING = 1;
23
24 $262.agent.start(`
25 const valueOf = {
26 valueOf() {
27 return true;
28 }
29 };
30
31 const toPrimitive = {
32 [Symbol.toPrimitive]() {
33 return true;
34 }
35 };
36
37 $262.agent.receiveBroadcast(async (sab) => {
38 const i64a = new BigInt64Array(sab);
39 Atomics.add(i64a, ${RUNNING}, 1n);
40 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, true).value);
41 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value);
42 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value);
43 $262.agent.leaving();
44 });
45 `);
46
47 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4));
48
49 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => {
50 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n');
51
52 assert.sameValue(
53 await $262.agent.getReportAsync(),
54 'timed-out',
55 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
56 );
57
58 assert.sameValue(
59 await $262.agent.getReportAsync(),
60 'timed-out',
61 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
62 );
63
64 assert.sameValue(
65 await $262.agent.getReportAsync(),
66 'timed-out',
67 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
68 );
69
70 assert.sameValue(
71 Atomics.notify(i64a, 0),
72 0,
73 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0'
74 );
75 }).then($DONE, $DONE);