tor-browser

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

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


      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, 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 i32a = new Int32Array(sab);
     36    Atomics.add(i32a, ${RUNNING}, 1);
     37 
     38    // Wait on index 0
     39    $262.agent.report(await Atomics.waitAsync(i32a, 0, 0, Infinity).value);
     40    $262.agent.leaving();
     41  });
     42 `);
     43 
     44 $262.agent.start(`
     45  $262.agent.receiveBroadcast(async (sab) => {
     46    const i32a = new Int32Array(sab);
     47    Atomics.add(i32a, ${RUNNING}, 1);
     48 
     49    // Wait on index 2
     50    $262.agent.report(await Atomics.waitAsync(i32a, 2, 0, Infinity).value);
     51    $262.agent.leaving();
     52  });
     53 `);
     54 
     55 const i32a = new Int32Array(
     56  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 5)
     57 );
     58 
     59 $262.agent.safeBroadcastAsync(i32a, RUNNING, NUMAGENT).then(async (agentCount) => {
     60 
     61  assert.sameValue(agentCount, NUMAGENT, 'The value of `agentCount` is expected to equal the value of NUMAGENT');
     62 
     63  // Notify index 1, notifies nothing
     64  assert.sameValue(Atomics.notify(i32a, 1), 0, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 5)), 1) must return 0');
     65 
     66  // Notify index 3, notifies nothing
     67  assert.sameValue(Atomics.notify(i32a, 3), 0, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 5)), 3) must return 0');
     68 
     69  // Notify index 2, notifies 1
     70  assert.sameValue(Atomics.notify(i32a, 2), 1, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 5)), 2) must return 1');
     71  assert.sameValue(
     72    await $262.agent.getReportAsync(),
     73    'ok',
     74    '(await $262.agent.getReportAsync()) resolves to the value "ok"'
     75  );
     76 
     77  // Notify index 0, notifies 1
     78  assert.sameValue(Atomics.notify(i32a, 0), 1, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 5)), 0) must return 1');
     79  assert.sameValue(
     80    await $262.agent.getReportAsync(),
     81    'ok',
     82    '(await $262.agent.getReportAsync()) resolves to the value "ok"'
     83  );
     84 
     85 }).then($DONE, $DONE);