tor-browser

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

count-defaults-to-infinity-missing.js (2446B)


      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.notify
      7 description: >
      8  Default to +Infinity when missing 'count' argument to Atomics.notify
      9 info: |
     10  Atomics.notify( typedArray, index, count )
     11 
     12  ...
     13  3. If count is undefined, let c be +∞.
     14  ...
     15 
     16 includes: [atomicsHelper.js]
     17 features: [Atomics, SharedArrayBuffer, TypedArray]
     18 ---*/
     19 
     20 const RUNNING = 0; // Index to notify agent has started.
     21 const WAIT_INDEX = 1; // Index all agents are waiting on.
     22 const BUFFER_SIZE = 2;
     23 
     24 const NUMAGENT = 4; // Total number of agents started
     25 
     26 for (var i = 0; i < NUMAGENT; i++) {
     27  $262.agent.start(`
     28    $262.agent.receiveBroadcast(function(sab) {
     29      const i32a = new Int32Array(sab);
     30      Atomics.add(i32a, ${RUNNING}, 1);
     31 
     32      // Wait until restarted by main thread.
     33      var status = Atomics.wait(i32a, ${WAIT_INDEX}, 0);
     34 
     35      // Report wait status and then exit the agent.
     36      var name = String.fromCharCode(0x41 + ${i}); // "A", "B", "C", or "D"
     37      $262.agent.report(name + " " + status);
     38      $262.agent.leaving();
     39    });
     40  `);
     41 }
     42 
     43 const i32a = new Int32Array(
     44  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE)
     45 );
     46 
     47 $262.agent.safeBroadcast(i32a);
     48 $262.agent.waitUntil(i32a, RUNNING, NUMAGENT);
     49 
     50 // An agent may have been interrupted between reporting its initial report
     51 // and the `Atomics.wait` call. Try to yield control to ensure the agent
     52 // actually started to wait.
     53 $262.agent.tryYield();
     54 
     55 assert.sameValue(Atomics.notify(i32a, WAIT_INDEX /*, count missing */), NUMAGENT,
     56                 'Atomics.notify(i32a, WAIT_INDEX /*, count missing */) returns the value of `NUMAGENT`');
     57 
     58 const reports = [];
     59 for (var i = 0; i < NUMAGENT; i++) {
     60  reports.push($262.agent.getReport());
     61 }
     62 reports.sort();
     63 
     64 assert.sameValue(reports[0], 'A ok', 'The value of reports[0] is "A ok"');
     65 assert.sameValue(reports[1], 'B ok', 'The value of reports[1] is "B ok"');
     66 assert.sameValue(reports[2], 'C ok', 'The value of reports[2] is "C ok"');
     67 assert.sameValue(reports[3], 'D ok', 'The value of reports[3] is "D ok"');
     68 
     69 reportCompare(0, 0);