tor-browser

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

false-for-timeout-agent.js (2125B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('arm64-simulator'))) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics
      2 // Copyright (C) 2018 Amal Hussein.  All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-atomics.wait
      7 description: >
      8  False timeout arg should result in an +0 timeout
      9 info: |
     10  Atomics.wait( typedArray, index, value, timeout )
     11 
     12  4. Let q be ? ToNumber(timeout).
     13 
     14    Boolean -> If argument is true, return 1. If argument is false, return +0.
     15 
     16 includes: [atomicsHelper.js]
     17 features: [Atomics, BigInt, SharedArrayBuffer, TypedArray]
     18 ---*/
     19 
     20 const i64a = new BigInt64Array(
     21  new SharedArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 4)
     22 );
     23 
     24 const RUNNING = 1;
     25 
     26 $262.agent.start(`
     27  const valueOf = {
     28    valueOf: function() {
     29      return false;
     30    }
     31  };
     32 
     33  const toPrimitive = {
     34    [Symbol.toPrimitive]: function() {
     35      return false;
     36    }
     37  };
     38 
     39  $262.agent.receiveBroadcast(function(sab) {
     40    const i64a = new BigInt64Array(sab);
     41    Atomics.add(i64a, ${RUNNING}, 1n);
     42 
     43    const status1 = Atomics.wait(i64a, 0, 0n, false);
     44    const status2 = Atomics.wait(i64a, 0, 0n, valueOf);
     45    const status3 = Atomics.wait(i64a, 0, 0n, toPrimitive);
     46 
     47    $262.agent.report(status1);
     48    $262.agent.report(status2);
     49    $262.agent.report(status3);
     50    $262.agent.leaving();
     51  });
     52 `);
     53 
     54 $262.agent.safeBroadcast(i64a);
     55 $262.agent.waitUntil(i64a, RUNNING, 1n);
     56 
     57 // Try to yield control to ensure the agent actually started to wait.
     58 $262.agent.tryYield();
     59 
     60 assert.sameValue(
     61  $262.agent.getReport(),
     62  'timed-out',
     63  '$262.agent.getReport() returns "timed-out"'
     64 );
     65 assert.sameValue(
     66  $262.agent.getReport(),
     67  'timed-out',
     68  '$262.agent.getReport() returns "timed-out"'
     69 );
     70 assert.sameValue(
     71  $262.agent.getReport(),
     72  'timed-out',
     73  '$262.agent.getReport() returns "timed-out"'
     74 );
     75 
     76 assert.sameValue(Atomics.notify(i64a, 0), 0, 'Atomics.notify(i64a, 0) returns 0');
     77 
     78 reportCompare(0, 0);