tor-browser

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

value-not-equal.js (1879B)


      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  Returns "not-equal" when value arg does not match an index in the typedArray
      9 info: |
     10  Atomics.wait( typedArray, index, value, timeout )
     11 
     12  3.Let v be ? ToInt32(value).
     13    ...
     14  14.If v is not equal to w, then
     15    a.Perform LeaveCriticalSection(WL).
     16    b. Return the String "not-equal".
     17 
     18 includes: [atomicsHelper.js]
     19 features: [Atomics, SharedArrayBuffer, TypedArray]
     20 ---*/
     21 
     22 const RUNNING = 1;
     23 
     24 var value = 42;
     25 
     26 $262.agent.start(`
     27  $262.agent.receiveBroadcast(function(sab) {
     28    const i32a = new Int32Array(sab);
     29    Atomics.add(i32a, ${RUNNING}, 1);
     30 
     31    $262.agent.report(Atomics.store(i32a, 0, ${value}));
     32    $262.agent.report(Atomics.wait(i32a, 0, 0));
     33    $262.agent.leaving();
     34  });
     35 `);
     36 
     37 const i32a = new Int32Array(
     38  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
     39 );
     40 
     41 // NB: We don't actually explicitly need to wait for the agent to start in this
     42 // test case, we only do it for consistency with other test cases which do
     43 // require the main agent to wait and yield control.
     44 
     45 $262.agent.safeBroadcast(i32a);
     46 $262.agent.waitUntil(i32a, RUNNING, 1);
     47 
     48 // Try to yield control to ensure the agent actually started to wait.
     49 $262.agent.tryYield();
     50 
     51 assert.sameValue(
     52  $262.agent.getReport(),
     53  value.toString(),
     54  '$262.agent.getReport() returns value.toString()'
     55 );
     56 assert.sameValue(
     57  $262.agent.getReport(),
     58  'not-equal',
     59  '$262.agent.getReport() returns "not-equal"'
     60 );
     61 
     62 reportCompare(0, 0);