object-for-timeout-agent.js (3531B)
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 Object valueOf, toString, toPrimitive Zero 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 Object -> Apply the following steps: 18 19 Let primValue be ? ToPrimitive(argument, hint Number). 20 Return ? ToNumber(primValue). 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 const RUNNING = 1; 28 29 $262.agent.start(` 30 const valueOf = { 31 valueOf() { 32 return 0; 33 } 34 }; 35 36 const toString = { 37 toString() { 38 return "0"; 39 } 40 }; 41 42 const toPrimitive = { 43 [Symbol.toPrimitive]() { 44 return 0; 45 } 46 }; 47 48 $262.agent.receiveBroadcast(async (sab) => { 49 const i64a = new BigInt64Array(sab); 50 Atomics.add(i64a, ${RUNNING}, 1n); 51 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, valueOf).value); 52 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toString).value); 53 $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); 54 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, valueOf).value); 55 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, toString).value); 56 $262.agent.report(Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value); 57 $262.agent.leaving(); 58 }); 59 `); 60 61 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); 62 63 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { 64 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); 65 66 assert.sameValue( 67 await $262.agent.getReportAsync(), 68 'timed-out', 69 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 70 ); 71 72 assert.sameValue( 73 await $262.agent.getReportAsync(), 74 'timed-out', 75 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 76 ); 77 78 assert.sameValue( 79 await $262.agent.getReportAsync(), 80 'timed-out', 81 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 82 ); 83 84 assert.sameValue( 85 await $262.agent.getReportAsync(), 86 'timed-out', 87 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 88 ); 89 90 assert.sameValue( 91 await $262.agent.getReportAsync(), 92 'timed-out', 93 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 94 ); 95 96 assert.sameValue( 97 await $262.agent.getReportAsync(), 98 'timed-out', 99 '(await $262.agent.getReportAsync()) resolves to the value "timed-out"' 100 ); 101 102 assert.sameValue( 103 Atomics.notify(i64a, 0), 104 0, 105 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' 106 ); 107 }).then($DONE, $DONE);