tor-browser

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

undefined-for-timeout.js (2285B)


      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  Undefined timeout arg should result in an infinite timeout
      9 info: |
     10  Atomics.wait( typedArray, index, value, timeout )
     11 
     12  4.Let q be ? ToNumber(timeout).
     13    ...
     14    Undefined    Return NaN.
     15  5.If q is NaN, let t be +∞, else let t be max(q, 0)
     16 
     17 includes: [atomicsHelper.js]
     18 features: [Atomics, SharedArrayBuffer, TypedArray]
     19 ---*/
     20 
     21 const WAIT_INDEX = 0; // Index all agents are waiting on
     22 const RUNNING = 1;
     23 const NUMAGENT = 2;   // Total number of agents started
     24 const NOTIFYCOUNT = 2;  // Total number of agents to notify up
     25 
     26 $262.agent.start(`
     27  $262.agent.receiveBroadcast(function(sab) {
     28    var i32a = new Int32Array(sab);
     29    Atomics.add(i32a, ${RUNNING}, 1);
     30 
     31    // undefined => NaN => +Infinity
     32    $262.agent.report("A " + Atomics.wait(i32a, 0, 0, undefined));
     33    $262.agent.leaving();
     34  });
     35 `);
     36 
     37 $262.agent.start(`
     38  $262.agent.receiveBroadcast(function(sab) {
     39    var i32a = new Int32Array(sab);
     40    Atomics.add(i32a, ${RUNNING}, 1);
     41 
     42    // undefined timeout arg => NaN => +Infinity
     43    $262.agent.report("B " + Atomics.wait(i32a, 0, 0));
     44    $262.agent.leaving();
     45  });
     46 `);
     47 
     48 const i32a = new Int32Array(
     49  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
     50 );
     51 
     52 $262.agent.safeBroadcast(i32a);
     53 $262.agent.waitUntil(i32a, RUNNING, NUMAGENT);
     54 
     55 // Try to yield control to ensure the agent actually started to wait.
     56 $262.agent.tryYield();
     57 
     58 assert.sameValue(
     59  Atomics.notify(i32a, WAIT_INDEX, NOTIFYCOUNT),
     60  NOTIFYCOUNT,
     61  'Atomics.notify(i32a, WAIT_INDEX, NOTIFYCOUNT) returns the value of `NOTIFYCOUNT` (2)'
     62 );
     63 
     64 const reports = [];
     65 for (var i = 0; i < NUMAGENT; i++) {
     66  reports.push($262.agent.getReport());
     67 }
     68 reports.sort();
     69 
     70 assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"');
     71 assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"');
     72 
     73 reportCompare(0, 0);