null-for-timeout-agent.js (3307B)
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 null timeout arg should result in an +0 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 Null -> Return +0. 18 19 flags: [async] 20 includes: [atomicsHelper.js] 21 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions] 22 ---*/ 23 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 24 const RUNNING = 1; 25 26 $262.agent.start(` 27 const valueOf = { 28 valueOf() { 29 return null; 30 } 31 }; 32 33 const toPrimitive = { 34 [Symbol.toPrimitive]() { 35 return null; 36 } 37 }; 38 39 $262.agent.receiveBroadcast(async (sab) => { 40 const i64a = new BigInt64Array(sab); 41 Atomics.add(i64a, ${RUNNING}, 1n); 42 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, null).value); 43 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); 44 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); 45 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, null).value); 46 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, valueOf).value); 47 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); 48 $262.agent.leaving(); 49 }); 50 `); 51 52 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); 53 54 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { 55 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); 56 57 assert.sameValue( 58 await $262.agent.getReportAsync(), 59 'timed-out', 60 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 61 ); 62 63 assert.sameValue( 64 await $262.agent.getReportAsync(), 65 'timed-out', 66 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 67 ); 68 69 assert.sameValue( 70 await $262.agent.getReportAsync(), 71 'timed-out', 72 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 73 ); 74 75 assert.sameValue( 76 await $262.agent.getReportAsync(), 77 'timed-out', 78 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 79 ); 80 81 assert.sameValue( 82 await $262.agent.getReportAsync(), 83 'timed-out', 84 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 85 ); 86 87 assert.sameValue( 88 await $262.agent.getReportAsync(), 89 'timed-out', 90 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 91 ); 92 93 assert.sameValue( 94 Atomics.notify(i64a, 0), 95 0, 96 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' 97 ); 98 }).then($DONE, $DONE);