tor-browser

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

was-woken-before-timeout.js (2353B)


      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 was awoken before
      8  a timeout
      9 flags: [async]
     10 includes: [atomicsHelper.js]
     11 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions]
     12 ---*/
     13 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
     14 const RUNNING = 1;
     15 const TIMEOUT = $262.agent.timeouts.huge;
     16 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4));
     17 
     18 $262.agent.start(`
     19  $262.agent.receiveBroadcast(async (sab) => {
     20    const i64a = new BigInt64Array(sab);
     21    Atomics.add(i64a, ${RUNNING}, 1n);
     22 
     23    const before = $262.agent.monotonicNow();
     24    const unpark = await Atomics.waitAsync(i64a, 0, 0n, ${TIMEOUT}).value;
     25    const duration = $262.agent.monotonicNow() - before;
     26 
     27    $262.agent.report(duration);
     28    $262.agent.report(unpark);
     29    $262.agent.leaving();
     30  });
     31 `);
     32 
     33 $262.agent.safeBroadcastAsync(i64a, RUNNING, 1n).then(async agentCount => {
     34  assert.sameValue(agentCount, 1n, 'The value of `agentCount` is 1n');
     35 
     36  assert.sameValue(
     37    Atomics.notify(i64a, 0),
     38    1,
     39    'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 1'
     40  );
     41 
     42  const lapse = await $262.agent.getReportAsync();
     43  assert(lapse < TIMEOUT, 'The result of evaluating `(lapse < TIMEOUT)` is true');
     44  const result = await $262.agent.getReportAsync();
     45  assert.sameValue(result, 'ok', 'The value of `result` is "ok"');
     46  assert.sameValue(result, 'ok', 'The value of `result` is "ok"');
     47 
     48  assert.sameValue(
     49    Atomics.notify(i64a, 0),
     50    0,
     51    'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)), 0) must return 0'
     52  );
     53 }).then($DONE, $DONE);