undefined-index-defaults-to-zero-agent.js (2883B)
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 Undefined index arg is coerced to zero 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 2. Let i be ? ValidateAtomicAccess(typedArray, index). 16 ... 17 2.Let accessIndex be ? ToIndex(requestIndex). 18 19 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. 20 ... 21 3.If bufferData is a Data Block, return false 22 23 If value is undefined, then 24 Let index be 0. 25 26 flags: [async] 27 includes: [atomicsHelper.js] 28 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] 29 ---*/ 30 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 31 32 const WAIT_INDEX = 0; 33 const RUNNING = 1; 34 const NUMAGENT = 2; 35 const NOTIFYCOUNT = 2; 36 37 $262.agent.start(` 38 $262.agent.receiveBroadcast(async (sab) => { 39 var i64a = new BigInt64Array(sab); 40 Atomics.add(i64a, ${RUNNING}, 1n); 41 42 $262.agent.report("A " + (await Atomics.waitAsync(i64a, undefined, 0n).value)); 43 $262.agent.leaving(); 44 }); 45 `); 46 47 $262.agent.start(` 48 $262.agent.receiveBroadcast(async (sab) => { 49 var i64a = new BigInt64Array(sab); 50 Atomics.add(i64a, ${RUNNING}, 1n); 51 52 $262.agent.report("B " + (await Atomics.waitAsync(i64a, undefined, 0n).value)); 53 $262.agent.leaving(); 54 }); 55 `); 56 57 const i64a = new BigInt64Array( 58 new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) 59 ); 60 61 $262.agent.safeBroadcastAsync(i64a, RUNNING, BigInt(NUMAGENT)).then(async (agentCount) => { 62 63 assert.sameValue( 64 agentCount, 65 BigInt(NUMAGENT), 66 'The value of `agentCount` must return the same value returned by BigInt(NUMAGENT)' 67 ); 68 69 assert.sameValue( 70 Atomics.notify(i64a, WAIT_INDEX, NOTIFYCOUNT), 71 NOTIFYCOUNT, 72 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0, 2) must return the value of NOTIFYCOUNT' 73 ); 74 75 const reports = [ 76 await $262.agent.getReportAsync(), 77 await $262.agent.getReportAsync(), 78 ]; 79 80 reports.sort(); 81 assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"'); 82 assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"'); 83 }).then($DONE, $DONE);