tor-browser

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

object-for-timeout-agent.js (3488B)


      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  Object valueOf, toString, toPrimitive Zero timeout arg should result in an +0 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    Object -> Apply the following steps:
     19 
     20      Let primValue be ? ToPrimitive(argument, hint Number).
     21      Return ? ToNumber(primValue).
     22 
     23 flags: [async]
     24 includes: [atomicsHelper.js]
     25 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, arrow-function, async-functions]
     26 ---*/
     27 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
     28 
     29 const RUNNING = 1;
     30 
     31 $262.agent.start(`
     32  const valueOf = {
     33    valueOf() {
     34      return 0;
     35    }
     36  };
     37 
     38  const toString = {
     39    toString() {
     40      return "0";
     41    }
     42  };
     43 
     44  const toPrimitive = {
     45    [Symbol.toPrimitive]() {
     46      return 0;
     47    }
     48  };
     49 
     50  $262.agent.receiveBroadcast(async (sab) => {
     51    const i32a = new Int32Array(sab);
     52    Atomics.add(i32a, ${RUNNING}, 1);
     53    $262.agent.report(await Atomics.waitAsync(i32a, 0, 0, valueOf).value);
     54    $262.agent.report(await Atomics.waitAsync(i32a, 0, 0, toString).value);
     55    $262.agent.report(await Atomics.waitAsync(i32a, 0, 0, toPrimitive).value);
     56    $262.agent.report(Atomics.waitAsync(i32a, 0, 0, valueOf).value);
     57    $262.agent.report(Atomics.waitAsync(i32a, 0, 0, toString).value);
     58    $262.agent.report(Atomics.waitAsync(i32a, 0, 0, toPrimitive).value);
     59    $262.agent.leaving();
     60  });
     61 `);
     62 
     63 const i32a = new Int32Array(
     64  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
     65 );
     66 
     67 $262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
     68 
     69  assert.sameValue(agentCount, 1, 'The value of `agentCount` is 1');
     70 
     71  assert.sameValue(
     72    await $262.agent.getReportAsync(),
     73    'timed-out',
     74    '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
     75  );
     76  assert.sameValue(
     77    await $262.agent.getReportAsync(),
     78    'timed-out',
     79    '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
     80  );
     81  assert.sameValue(
     82    await $262.agent.getReportAsync(),
     83    'timed-out',
     84    '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
     85  );
     86  assert.sameValue(
     87    await $262.agent.getReportAsync(),
     88    'timed-out',
     89    '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
     90  );
     91  assert.sameValue(
     92    await $262.agent.getReportAsync(),
     93    'timed-out',
     94    '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
     95  );
     96  assert.sameValue(
     97    await $262.agent.getReportAsync(),
     98    'timed-out',
     99    '(await $262.agent.getReportAsync()) resolves to the value "timed-out"'
    100  );
    101 
    102  assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)), 0) must return 0');
    103 
    104 }).then($DONE, $DONE);