tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

no-spurious-wakeup-on-and.js (1730B)


      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 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.wait
      7 description: >
      8  Waiter does not spuriously nofity on index which is subject to And operation
      9 includes: [atomicsHelper.js]
     10 features: [Atomics, BigInt, SharedArrayBuffer, TypedArray]
     11 ---*/
     12 
     13 const RUNNING = 1;
     14 const TIMEOUT = $262.agent.timeouts.small;
     15 
     16 const i64a = new BigInt64Array(
     17  new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)
     18 );
     19 
     20 $262.agent.start(`
     21  $262.agent.receiveBroadcast(function(sab) {
     22    const i64a = new BigInt64Array(sab);
     23    Atomics.add(i64a, ${RUNNING}, 1n);
     24 
     25    const before = $262.agent.monotonicNow();
     26    const unpark = Atomics.wait(i64a, 0, 0n, ${TIMEOUT});
     27    const duration = $262.agent.monotonicNow() - before;
     28 
     29    $262.agent.report(duration);
     30    $262.agent.report(unpark);
     31    $262.agent.leaving();
     32  });
     33 `);
     34 
     35 $262.agent.safeBroadcast(i64a);
     36 $262.agent.waitUntil(i64a, RUNNING, 1n);
     37 
     38 // Try to yield control to ensure the agent actually started to wait.
     39 $262.agent.tryYield();
     40 
     41 Atomics.and(i64a, 0, 1n);
     42 
     43 const lapse = $262.agent.getReport();
     44 assert(
     45  lapse >= TIMEOUT,
     46  'The result of `(lapse >= TIMEOUT)` is true'
     47 );
     48 assert.sameValue(
     49  $262.agent.getReport(),
     50  'timed-out',
     51  '$262.agent.getReport() returns "timed-out"'
     52 );
     53 assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0');
     54 
     55 
     56 
     57 reportCompare(0, 0);