true-for-timeout.js (2257B)
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 Boolean -> If argument is true, return 1. If argument is false, return +0. 19 20 flags: [async] 21 includes: [atomicsHelper.js] 22 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function] 23 ---*/ 24 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"'); 25 const i32a = new Int32Array( 26 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) 27 ); 28 29 const valueOf = { 30 valueOf() { 31 return true; 32 } 33 }; 34 35 const toPrimitive = { 36 [Symbol.toPrimitive]() { 37 return true; 38 } 39 }; 40 41 let outcomes = []; 42 let lifespan = 1000; 43 let start = $262.agent.monotonicNow(); 44 45 (function wait() { 46 let elapsed = $262.agent.monotonicNow() - start; 47 if (elapsed > lifespan) { 48 $DONE("Test timed out"); 49 return; 50 } 51 if (outcomes.length) { 52 assert.sameValue(outcomes[0], 'timed-out', 'The value of outcomes[0] is "timed-out"'); 53 assert.sameValue(outcomes[1], 'timed-out', 'The value of outcomes[1] is "timed-out"'); 54 assert.sameValue(outcomes[2], 'timed-out', 'The value of outcomes[2] is "timed-out"'); 55 $DONE(); 56 return; 57 } 58 59 $262.agent.setTimeout(wait, 0); 60 })(); 61 62 Promise.all([ 63 Atomics.waitAsync(i32a, 0, 0, true).value, 64 Atomics.waitAsync(i32a, 0, 0, valueOf).value, 65 Atomics.waitAsync(i32a, 0, 0, toPrimitive).value, 66 ]).then(results => (outcomes = results), $DONE);