tor-browser

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

true-for-timeout.js (2260B)


      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  Throws a TypeError if index arg can not be converted to an Integer
      8 info: |
      9  Atomics.waitAsync( typedArray, index, value, timeout )
     10 
     11  1. Return DoWait(async, typedArray, index, value, timeout).
     12 
     13  DoWait ( mode, typedArray, index, value, timeout )
     14 
     15  6. Let q be ? ToNumber(timeout).
     16 
     17    Boolean -> If argument is true, return 1. If argument is false, return +0.
     18 
     19 flags: [async]
     20 includes: [atomicsHelper.js]
     21 features: [Atomics.waitAsync, SharedArrayBuffer, TypedArray, Atomics, BigInt, computed-property-names, Symbol, Symbol.toPrimitive, arrow-function]
     22 ---*/
     23 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
     24 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4));
     25 
     26 const valueOf = {
     27  valueOf() {
     28    return true;
     29  }
     30 };
     31 
     32 const toPrimitive = {
     33  [Symbol.toPrimitive]() {
     34    return true;
     35  }
     36 };
     37 
     38 let outcomes = [];
     39 let lifespan = 1000;
     40 let start = $262.agent.monotonicNow();
     41 
     42 (function wait() {
     43  let elapsed = $262.agent.monotonicNow() - start;
     44 
     45  if (elapsed > lifespan) {
     46    $DONE('Test timed out');
     47    return;
     48  }
     49 
     50  if (outcomes.length) {
     51    assert.sameValue(outcomes[0], 'timed-out', 'The value of outcomes[0] is "timed-out"');
     52    assert.sameValue(outcomes[1], 'timed-out', 'The value of outcomes[1] is "timed-out"');
     53    assert.sameValue(outcomes[2], 'timed-out', 'The value of outcomes[2] is "timed-out"');
     54    $DONE();
     55    return;
     56  }
     57 
     58  $262.agent.setTimeout(wait, 0);
     59 })();
     60 
     61 Promise.all([
     62  Atomics.waitAsync(i64a, 0, 0n, true).value,
     63  Atomics.waitAsync(i64a, 0, 0n, valueOf).value,
     64  Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value
     65 ]).then(results => outcomes = results, $DONE);