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