undefined-index-defaults-to-zero-agent.js (2807B)
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, 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 i32a = new Int32Array(sab); 40 Atomics.add(i32a, ${RUNNING}, 1); 41 42 $262.agent.report("A " + (await Atomics.waitAsync(i32a, undefined, 0).value)); 43 $262.agent.leaving(); 44 }); 45 `); 46 47 $262.agent.start(` 48 $262.agent.receiveBroadcast(async (sab) => { 49 var i32a = new Int32Array(sab); 50 Atomics.add(i32a, ${RUNNING}, 1); 51 52 $262.agent.report("B " + (await Atomics.waitAsync(i32a, undefined, 0).value)); 53 $262.agent.leaving(); 54 }); 55 `); 56 57 const i32a = new Int32Array( 58 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) 59 ); 60 61 $262.agent.safeBroadcastAsync(i32a, RUNNING, NUMAGENT).then(async (agentCount) => { 62 63 assert.sameValue(agentCount, NUMAGENT, 'The value of `agentCount` is expected to equal the value of NUMAGENT'); 64 65 assert.sameValue( 66 Atomics.notify(i32a, WAIT_INDEX, NOTIFYCOUNT), 67 NOTIFYCOUNT, 68 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0, 2) must return the value of NOTIFYCOUNT' 69 ); 70 71 const reports = [ 72 await $262.agent.getReportAsync(), 73 await $262.agent.getReportAsync(), 74 ]; 75 76 reports.sort(); 77 assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"'); 78 assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"'); 79 }).then($DONE, $DONE);