tor-browser

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

no-spurious-wakeup-no-operation.js (2689B)


      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 esid: sec-atomics.waitasync
      6 description: >
      7  Test that Atomics.waitAsync returns the right result when it timed out and that
      8  the time to time out is reasonable.
      9 info: |
     10  AddWaiter ( WL, waiterRecord )
     11 
     12  5. Append waiterRecord as the last element of WL.[[Waiters]]
     13  6. If waiterRecord.[[Timeout]] is finite, then in parallel,
     14    a. Wait waiterRecord.[[Timeout]] milliseconds.
     15    b. Perform TriggerTimeout(WL, waiterRecord).
     16 
     17  TriggerTimeout( WL, waiterRecord )
     18 
     19  3. If waiterRecord is in WL.[[Waiters]], then
     20    a. Set waiterRecord.[[Result]] to "timed-out".
     21    b. Perform RemoveWaiter(WL, waiterRecord).
     22    c. Perform NotifyWaiter(WL, waiterRecord).
     23  4. Perform LeaveCriticalSection(WL).
     24 
     25 flags: [async]
     26 includes: [atomicsHelper.js]
     27 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions]
     28 ---*/
     29 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
     30 const RUNNING = 1;
     31 const TIMEOUT = $262.agent.timeouts.small;
     32 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4));
     33 
     34 $262.agent.start(`
     35  $262.agent.receiveBroadcast(async (sab) => {
     36    const i64a = new BigInt64Array(sab);
     37    Atomics.add(i64a, ${RUNNING}, 1n);
     38 
     39    const before = $262.agent.monotonicNow();
     40    const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value;
     41    const duration = $262.agent.monotonicNow() - before;
     42 
     43    $262.agent.report(duration);
     44    $262.agent.report(unpark);
     45    $262.agent.leaving();
     46  });
     47 `);
     48 
     49 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => {
     50  assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n');
     51  const lapse = await $262.agent.getReportAsync();
     52  assert(lapse >= TIMEOUT, 'The result of evaluating `(lapse >= TIMEOUT)` is true');
     53  const result = await $262.agent.getReportAsync();
     54  assert.sameValue(result, 'timed-out', 'The value of `result` is "timed-out"');
     55 
     56  assert.sameValue(
     57    Atomics.notify(i64a, 0),
     58    0,
     59    'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0'
     60  );
     61 }).then($DONE, $DONE);