negative-count.js (1434B)
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) 2017 Mozilla Corporation. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-atomics.notify 7 description: > 8 Test that Atomics.notify notifies zero waiters if the count is negative 9 includes: [atomicsHelper.js] 10 features: [Atomics, SharedArrayBuffer, TypedArray] 11 ---*/ 12 13 const RUNNING = 1; 14 const TIMEOUT = $262.agent.timeouts.long; 15 16 $262.agent.start(` 17 $262.agent.receiveBroadcast(function(sab) { 18 const i32a = new Int32Array(sab); 19 Atomics.add(i32a, ${RUNNING}, 1); 20 21 $262.agent.report(Atomics.wait(i32a, 0, 0, ${TIMEOUT})); 22 $262.agent.leaving(); 23 }); 24 `); 25 26 const i32a = new Int32Array( 27 new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) 28 ); 29 30 $262.agent.safeBroadcast(i32a); 31 $262.agent.waitUntil(i32a, RUNNING, 1); 32 33 // Try to yield control to ensure the agent actually started to wait. 34 $262.agent.tryYield(); 35 36 assert.sameValue(Atomics.notify(i32a, 0, -1), 0, 'Atomics.notify(i32a, 0, -1) returns 0'); // Don't actually notify it 37 38 assert.sameValue($262.agent.getReport(), 'timed-out', '$262.agent.getReport() returns "timed-out"'); 39 40 reportCompare(0, 0);