tor-browser

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

waiterlist-block-indexedposition-wake.js (3306B)


      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 /*---
      6 esid: sec-atomics.waitasync
      7 description: >
      8  Get the correct WaiterList
      9 info: |
     10  Atomics.waitAsync( typedArray, index, value, timeout )
     11 
     12  1. Return DoWait(async, typedArray, index, value, timeout).
     13 
     14  DoWait ( mode, typedArray, index, value, timeout )
     15 
     16  11. Let indexedPosition be (i × 4) + offset.
     17  12. Let WL be GetWaiterList(block, indexedPosition).
     18 
     19  GetWaiterList( block, i )
     20 
     21  ...
     22  4. Return the WaiterList that is referenced by the pair (block, i).
     23 
     24 flags: [async]
     25 includes: [atomicsHelper.js]
     26 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, arrow-function, async-functions]
     27 ---*/
     28 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
     29 
     30 const NUMAGENT = 2;
     31 const RUNNING = 4;
     32 
     33 $262.agent.start(`
     34  $262.agent.receiveBroadcast(async (sab) => {
     35    const i64a = new BigInt64Array(sab);
     36    Atomics.add(i64a, ${RUNNING}, 1n);
     37 
     38    // Wait on index 0
     39    $262.agent.report(await Atomics.waitAsync(i64a, 0, 0n, Infinity).value);
     40    $262.agent.leaving();
     41  });
     42 `);
     43 
     44 $262.agent.start(`
     45  $262.agent.receiveBroadcast(async (sab) => {
     46    const i64a = new BigInt64Array(sab);
     47    Atomics.add(i64a, ${RUNNING}, 1n);
     48 
     49    // Wait on index 2
     50    $262.agent.report(await Atomics.waitAsync(i64a, 2, 0n, Infinity).value);
     51    $262.agent.leaving();
     52  });
     53 `);
     54 
     55 const i64a = new BigInt64Array(
     56  new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)
     57 );
     58 
     59 $262.agent.safeBroadcastAsync(i64a, RUNNING, BigInt(NUMAGENT)).then(async (agentCount) => {
     60 
     61  assert.sameValue(
     62    agentCount,
     63    BigInt(NUMAGENT),
     64    'The value of `agentCount` must return the same value returned by BigInt(NUMAGENT)'
     65  );
     66 
     67  // Notify index 1, notifies nothing
     68  assert.sameValue(Atomics.notify(i64a, 1), 0, 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)), 1) must return 0');
     69 
     70  // Notify index 3, notifies nothing
     71  assert.sameValue(Atomics.notify(i64a, 3), 0, 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)), 3) must return 0');
     72 
     73  // Notify index 2, notifies 1
     74  assert.sameValue(Atomics.notify(i64a, 2), 1, 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)), 2) must return 1');
     75  assert.sameValue(
     76    await $262.agent.getReportAsync(),
     77    'ok',
     78    '(await $262.agent.getReportAsync()) resolves to the value "ok"'
     79  );
     80 
     81  // Notify index 0, notifies 1
     82  assert.sameValue(Atomics.notify(i64a, 0), 1, 'Atomics.notify(new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 5)), 0) must return 1');
     83  assert.sameValue(
     84    await $262.agent.getReportAsync(),
     85    'ok',
     86    '(await $262.agent.getReportAsync()) resolves to the value "ok"'
     87  );
     88 
     89 }).then($DONE, $DONE);