nan-for-timeout-agent.js (1987B)
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 NaN timeout arg should result in an infinite 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 $262.agent.receiveBroadcast(async (sab) => { 26 const i64a = new BigInt64Array(sab); 27 Atomics.add(i64a, ${RUNNING}, 1n); 28 29 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, NaN).value); // NaN => +Infinity 30 $262.agent.leaving(); 31 }); 32 `); 33 34 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); 35 36 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { 37 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); 38 39 assert.sameValue( 40 Atomics.notify(i64a, 0), 41 1, 42 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 1' 43 ); 44 45 assert.sameValue( 46 await $262.agent.getReportAsync(), 47 'ok', 48 '(await $262.agent.getReportAsync()) resolves to the value "ok"' 49 ); 50 }).then($DONE, $DONE);