symbol-for-timeout-throws-agent.js (2518B)
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 Throws a TypeError if index arg can not be converted to an Integer 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 Symbol --> Throw a TypeError exception. 18 19 flags: [async] 20 includes: [atomicsHelper.js] 21 features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, 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 $262.agent.receiveBroadcast(function(sab) { 28 const i64a = new BigInt64Array(sab); 29 Atomics.add(i64a, ${RUNNING}, 1n); 30 31 let status1 = ''; 32 let status2 = ''; 33 34 try { 35 Atomics.waitAsync(i64a, 0, 0n, Symbol('1')); 36 } catch (error) { 37 status1 = 'A ' + error.name; 38 } 39 try { 40 Atomics.waitAsync(i64a, 0, 0n, Symbol('2')); 41 } catch (error) { 42 status2 = 'B ' + error.name; 43 } 44 45 $262.agent.report(status1); 46 $262.agent.report(status2); 47 $262.agent.leaving(); 48 }); 49 `); 50 51 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)); 52 53 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => { 54 assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n'); 55 56 assert.sameValue( 57 await $262.agent.getReportAsync(), 58 'A TypeError', 59 '(await $262.agent.getReportAsync()) resolves to the value "A TypeError"' 60 ); 61 62 assert.sameValue( 63 await $262.agent.getReportAsync(), 64 'B TypeError', 65 '(await $262.agent.getReportAsync()) resolves to the value "B TypeError"' 66 ); 67 68 assert.sameValue( 69 Atomics.notify(i64a, 0), 70 0, 71 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0' 72 ); 73 }).then($DONE, $DONE);