tor-browser

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

undefined-for-timeout-agent.js (2707B)


      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  Undefined timeout arg should result in an infinite timeout
      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  6. Let q be ? ToNumber(timeout).
     17    ...
     18    Undefined    Return NaN.
     19 
     20  5.If q is NaN, let t be +∞, else let t be max(q, 0)
     21 
     22 flags: [async]
     23 includes: [atomicsHelper.js]
     24 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, arrow-function, async-functions]
     25 ---*/
     26 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
     27 
     28 const WAIT_INDEX = 0;
     29 const RUNNING = 1;
     30 const NUMAGENT = 2;
     31 const NOTIFYCOUNT = 2;
     32 
     33 $262.agent.start(`
     34  $262.agent.receiveBroadcast(async (sab) => {
     35    var i32a = new Int32Array(sab);
     36    Atomics.add(i32a, ${RUNNING}, 1);
     37 
     38    // undefined => NaN => +Infinity
     39    $262.agent.report("A " + (await Atomics.waitAsync(i32a, 0, 0, undefined).value));
     40    $262.agent.leaving();
     41  });
     42 `);
     43 
     44 $262.agent.start(`
     45  $262.agent.receiveBroadcast(async (sab) => {
     46    var i32a = new Int32Array(sab);
     47    Atomics.add(i32a, ${RUNNING}, 1);
     48 
     49    // undefined timeout arg => NaN => +Infinity
     50    $262.agent.report("B " + (await Atomics.waitAsync(i32a, 0, 0).value));
     51    $262.agent.leaving();
     52  });
     53 `);
     54 
     55 const i32a = new Int32Array(
     56  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
     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  assert.sameValue(
     64    Atomics.notify(i32a, WAIT_INDEX, NOTIFYCOUNT),
     65    NOTIFYCOUNT,
     66    'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0, 2) must return the value of NOTIFYCOUNT'
     67  );
     68 
     69  const reports = [
     70    await $262.agent.getReportAsync(),
     71    await $262.agent.getReportAsync(),
     72  ];
     73 
     74  reports.sort();
     75  assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"');
     76  assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"');
     77 }).then($DONE, $DONE);