Debian Codegraph @

js/src/tests/test262/built-ins/Atomics/waitAsync/bigint/false-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 False 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 false;
28 }
29 };
30
31 const toPrimitive = {
32 [Symbol.toPrimitive]() {
33 return false;
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, false).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.report(Atomics.waitAsync(i64a, 0, 0n, false).value);
44 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, valueOf).value);
45 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value);
46 $262.agent.leaving();
47 });
48 `);
49
50 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4));
51
52 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => {
53 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n');
54
55 assert.sameValue(
56 await $262.agent.getReportAsync(),
57 'timed-out',
58 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
59 );
60
61 assert.sameValue(
62 await $262.agent.getReportAsync(),
63 'timed-out',
64 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
65 );
66
67 assert.sameValue(
68 await $262.agent.getReportAsync(),
69 'timed-out',
70 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
71 );
72
73 assert.sameValue(
74 await $262.agent.getReportAsync(),
75 'timed-out',
76 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
77 );
78
79 assert.sameValue(
80 await $262.agent.getReportAsync(),
81 'timed-out',
82 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
83 );
84
85 assert.sameValue(
86 await $262.agent.getReportAsync(),
87 'timed-out',
88 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
89 );
90
91 assert.sameValue(
92 Atomics.notify(i64a, 0),
93 0,
94 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0'
95 );
96 }).then($DONE, $DONE);