value-not-equal-agent.js (2472B)
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 Returns "not-equal" when value arg does not match an index in the typedArray 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 16. Let w be ! AtomicLoad(typedArray, i). 17 17. If v is not equal to w, then 18 a. Perform LeaveCriticalSection(WL). 19 b. If mode is sync, then 20 i. Return the String "not-equal". 21 c. Perform ! Call(capability.[[Resolve]], undefined, « "not-equal" »). 22 d. Return promiseCapability.[[Promise]]. 23 24 flags: [async] 25 includes: [atomicsHelper.js] 26 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, arrow-function, async-functions] 27 ---*/ 28 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 29 30 const RUNNING = 1; 31 const value = 42; 32 33 $262.agent.start(` 34 $262.agent.receiveBroadcast(function(sab) { 35 const i32a = new Int32Array(sab); 36 Atomics.add(i32a, ${RUNNING}, 1); 37 38 $262.agent.report(Atomics.store(i32a, 0, ${value})); 39 $262.agent.report(Atomics.waitAsync(i32a, 0, 0).value); 40 $262.agent.leaving(); 41 }); 42 `); 43 44 const i32a = new Int32Array( 45 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) 46 ); 47 48 $262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => { 49 50 assert.sameValue(agentCount, 1, 'The value of `agentCount` is 1'); 51 52 assert.sameValue( 53 await $262.agent.getReportAsync(), 54 '42', 55 '(await $262.agent.getReportAsync()) resolves to the value "42"' 56 ); 57 assert.sameValue( 58 await $262.agent.getReportAsync(), 59 'not-equal', 60 '(await $262.agent.getReportAsync()) resolves to the value "not-equal"' 61 ); 62 assert.sameValue( 63 Atomics.notify(i32a, 0, 1), 64 0, 65 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0, 1) must return 0' 66 ); 67 }).then($DONE, $DONE);