tor-browser

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

object-for-timeout.js (2539B)


      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  Object valueOf, toString, toPrimitive Zero timeout arg should result in an +0 timeout
      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    Object -> Apply the following steps:
     18 
     19      Let primValue be ? ToPrimitive(argument, hint Number).
     20      Return ? ToNumber(primValue).
     21 
     22 features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, BigInt, arrow-function]
     23 flags: [async]
     24 ---*/
     25 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
     26 const i64a = new BigInt64Array(new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4));
     27 
     28 const valueOf = {
     29  valueOf() {
     30    return 0;
     31  }
     32 };
     33 
     34 const toString = {
     35  toString() {
     36    return '0';
     37  }
     38 };
     39 
     40 const toPrimitive = {
     41  [Symbol.toPrimitive]() {
     42    return 0;
     43  }
     44 };
     45 
     46 assert.sameValue(
     47  Atomics.waitAsync(i64a, 0, 0n, valueOf).value,
     48  'timed-out',
     49  'The value of Atomics.waitAsync(i64a, 0, 0n, valueOf).value is "timed-out"'
     50 );
     51 
     52 assert.sameValue(
     53  Atomics.waitAsync(i64a, 0, 0n, toString).value,
     54  'timed-out',
     55  'The value of Atomics.waitAsync(i64a, 0, 0n, toString).value is "timed-out"'
     56 );
     57 
     58 assert.sameValue(
     59  Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value,
     60  'timed-out',
     61  'The value of Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value is "timed-out"'
     62 );
     63 
     64 Promise.all([
     65  Atomics.waitAsync(i64a, 0, 0n, valueOf).value,
     66  Atomics.waitAsync(i64a, 0, 0n, toString).value,
     67  Atomics.waitAsync(i64a, 0, 0n, toPrimitive).value
     68 ]).then(outcomes => {
     69  assert.sameValue(outcomes[0], 'timed-out', 'The value of outcomes[0] is "timed-out"');
     70  assert.sameValue(outcomes[1], 'timed-out', 'The value of outcomes[1] is "timed-out"');
     71  assert.sameValue(outcomes[2], 'timed-out', 'The value of outcomes[2] is "timed-out"');
     72 }).then($DONE, $DONE);