was-woken-before-timeout.js (2075B)
1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics 2 // Copyright (C) 2018 Amal Hussein. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 esid: sec-atomics.wait 6 description: > 7 Test that Atomics.wait returns the right result when it was awoken before 8 a timeout 9 info: | 10 Atomics.wait( typedArray, index, value, timeout ) 11 12 2.Let i be ? ValidateAtomicAccess(typedArray, index). 13 ... 14 2.Let accessIndex be ? ToIndex(requestIndex). 15 16 9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception. 17 ... 18 3.If bufferData is a Data Block, return false 19 20 If value is undefined, then 21 Let index be 0. 22 includes: [atomicsHelper.js] 23 features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] 24 ---*/ 25 26 const RUNNING = 1; 27 const TIMEOUT = $262.agent.timeouts.huge; 28 29 const i64a = new BigInt64Array( 30 new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4) 31 ); 32 33 $262.agent.start(` 34 $262.agent.receiveBroadcast(function(sab) { 35 const i64a = new BigInt64Array(sab); 36 Atomics.add(i64a, ${RUNNING}, 1n); 37 38 const before = $262.agent.monotonicNow(); 39 const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT}); 40 const duration = $262.agent.monotonicNow() - before; 41 42 $262.agent.report(duration); 43 $262.agent.report(unpark); 44 $262.agent.leaving(); 45 }); 46 `); 47 48 $262.agent.safeBroadcast(i64a); 49 $262.agent.waitUntil(i64a, RUNNING, 1n); 50 51 // Try to yield control to ensure the agent actually started to wait. 52 $262.agent.tryYield(); 53 54 assert.sameValue(Atomics.notify(i64a, 0), 1, 'Atomics.notify(i64a, 0) returns 1'); 55 56 const lapse = $262.agent.getReport(); 57 58 assert( 59 lapse < TIMEOUT, 60 'The result of `(lapse < TIMEOUT)` is true' 61 ); 62 assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"'); 63 64 reportCompare(0, 0);