undefined-for-timeout-agent.js (2783B)
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 Undefined 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 Undefined Return NaN. 19 20 5.If q is NaN, let t be +∞, else let t be max(q, 0) 21 22 flags: [async] 23 includes: [atomicsHelper.js] 24 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] 25 ---*/ 26 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 27 28 const WAIT_INDEX = 0; 29 const RUNNING = 1; 30 const NUMAGENT = 2; 31 const NOTIFYCOUNT = 2; 32 33 $262.agent.start(` 34 $262.agent.receiveBroadcast(async (sab) => { 35 var i64a = new BigInt64Array(sab); 36 Atomics.add(i64a, ${RUNNING}, 1n); 37 38 // undefined => NaN => +Infinity 39 $262.agent.report("A " + (await Atomics.waitAsync(i64a, 0, 0n, undefined).value)); 40 $262.agent.leaving(); 41 }); 42 `); 43 44 $262.agent.start(` 45 $262.agent.receiveBroadcast(async (sab) => { 46 var i64a = new BigInt64Array(sab); 47 Atomics.add(i64a, ${RUNNING}, 1n); 48 49 // undefined timeout arg => NaN => +Infinity 50 $262.agent.report("B " + (await Atomics.waitAsync(i64a, 0, 0n).value)); 51 $262.agent.leaving(); 52 }); 53 `); 54 55 const i64a = new BigInt64Array( 56 new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) 57 ); 58 59 $262.agent.safeBroadcastAsync(i64a, RUNNING, BigInt(NUMAGENT)).then(async (agentCount) => { 60 61 assert.sameValue( 62 agentCount, 63 BigInt(NUMAGENT), 64 'The value of `agentCount` must return the same value returned by BigInt(NUMAGENT)' 65 ); 66 67 assert.sameValue( 68 Atomics.notify(i64a, WAIT_INDEX, NOTIFYCOUNT), 69 NOTIFYCOUNT, 70 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0, 2) must return the value of NOTIFYCOUNT' 71 ); 72 73 const reports = [ 74 await $262.agent.getReportAsync(), 75 await $262.agent.getReportAsync(), 76 ]; 77 78 reports.sort(); 79 assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"'); 80 assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"'); 81 }).then($DONE, $DONE);