tor-browser

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

object-for-timeout.js (2536B)


      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 features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics, arrow-function]
     24 flags: [async]
     25 ---*/
     26 assert.sameValue(typeof Atomics.waitAsync, 'function', 'The value of `typeof Atomics.waitAsync` is "function"');
     27 const i32a = new Int32Array(
     28  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
     29 );
     30 
     31 const valueOf = {
     32  valueOf() {
     33    return 0;
     34  }
     35 };
     36 
     37 const toString = {
     38  toString() {
     39    return "0";
     40  }
     41 };
     42 
     43 const toPrimitive = {
     44  [Symbol.toPrimitive]() {
     45    return 0;
     46  }
     47 };
     48 
     49 assert.sameValue(
     50  Atomics.waitAsync(i32a, 0, 0, valueOf).value,
     51  'timed-out',
     52  'The value of Atomics.waitAsync(i32a, 0, 0, valueOf).value is "timed-out"'
     53 );
     54 assert.sameValue(
     55  Atomics.waitAsync(i32a, 0, 0, toString).value,
     56  'timed-out',
     57  'The value of Atomics.waitAsync(i32a, 0, 0, toString).value is "timed-out"'
     58 );
     59 assert.sameValue(
     60  Atomics.waitAsync(i32a, 0, 0, toPrimitive).value,
     61  'timed-out',
     62  'The value of Atomics.waitAsync(i32a, 0, 0, toPrimitive).value is "timed-out"'
     63 );
     64 
     65 Promise.all([
     66    Atomics.waitAsync(i32a, 0, 0, valueOf).value,
     67    Atomics.waitAsync(i32a, 0, 0, toString).value,
     68    Atomics.waitAsync(i32a, 0, 0, toPrimitive).value,
     69  ]).then(outcomes => {
     70    assert.sameValue(outcomes[0], "timed-out", 'The value of outcomes[0] is "timed-out"');
     71    assert.sameValue(outcomes[1], "timed-out", 'The value of outcomes[1] is "timed-out"');
     72    assert.sameValue(outcomes[2], "timed-out", 'The value of outcomes[2] is "timed-out"');
     73  }).then($DONE, $DONE);