tor-browser

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

undefined-index-defaults-to-zero.js (2402B)


      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  An undefined index arg should translate to 0
      9 info: |
     10  Atomics.notify( typedArray, index, count )
     11 
     12  2.Let i be ? ValidateAtomicAccess(typedArray, index).
     13    ...
     14      2.Let accessIndex be ? ToIndex(requestIndex).
     15 
     16      9.If IsSharedArrayBuffer(buffer) is false, throw a TypeError exception.
     17        ...
     18          3.If bufferData is a Data Block, return false
     19 
     20          If value is undefined, then
     21          Let index be 0.
     22 includes: [atomicsHelper.js]
     23 features: [Atomics, SharedArrayBuffer, TypedArray]
     24 ---*/
     25 
     26 var WAIT_INDEX = 0;
     27 var RUNNING = 1;
     28 
     29 var NUMAGENT = 2;
     30 
     31 for (var i = 0; i < NUMAGENT; i++) {
     32  $262.agent.start(`
     33    $262.agent.receiveBroadcast(function(sab) {
     34      const i32a = new Int32Array(sab);
     35 
     36      // Notify main thread that the agent was started.
     37      Atomics.add(i32a, ${RUNNING}, 1);
     38 
     39      // Wait until restarted by main thread.
     40      var status = Atomics.wait(i32a, ${WAIT_INDEX}, 0);
     41 
     42      // Report wait status.
     43      $262.agent.report(status);
     44 
     45      $262.agent.leaving();
     46    });
     47  `);
     48 }
     49 
     50 const i32a = new Int32Array(
     51  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
     52 );
     53 
     54 $262.agent.safeBroadcast(i32a);
     55 
     56 // Wait until both agents started.
     57 $262.agent.waitUntil(i32a, RUNNING, NUMAGENT);
     58 
     59 // Try to yield control to ensure the agents actually started to wait.
     60 $262.agent.tryYield();
     61 
     62 // Notify at index 0, undefined => 0.
     63 var woken = 0;
     64 while ((woken = Atomics.notify(i32a, undefined, 1)) === 0) ;
     65 assert.sameValue(woken, 1, 'Atomics.notify(i32a, undefined, 1) returns 1');
     66 
     67 assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"');
     68 
     69 // Notify again at index 0, default => 0.
     70 var woken = 0;
     71 while ((woken = Atomics.notify(i32a /*, default values used */)) === 0) ;
     72 assert.sameValue(woken, 1, 'Atomics.notify(i32a /*, default values used */) returns 1');
     73 
     74 assert.sameValue($262.agent.getReport(), 'ok', '$262.agent.getReport() returns "ok"');
     75 
     76 reportCompare(0, 0);