tor-browser

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

symbol-for-timeout-throws-agent.js (1913B)


      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  Throws a TypeError if index arg can not be converted to an Integer
      9 info: |
     10  Atomics.wait( typedArray, index, value, timeout )
     11 
     12  4. Let q be ? ToNumber(timeout).
     13 
     14    Symbol --> Throw a TypeError exception.
     15 
     16 includes: [atomicsHelper.js]
     17 features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray]
     18 ---*/
     19 
     20 const RUNNING = 1;
     21 
     22 $262.agent.start(`
     23  $262.agent.receiveBroadcast(function(sab) {
     24    const i32a = new Int32Array(sab);
     25    Atomics.add(i32a, ${RUNNING}, 1);
     26 
     27    let status1 = "";
     28    let status2 = "";
     29 
     30    try {
     31      Atomics.wait(i32a, 0, 0, Symbol("1"));
     32    } catch (error) {
     33      status1 = 'Symbol("1")';
     34    }
     35    try {
     36      Atomics.wait(i32a, 0, 0, Symbol("2"));
     37    } catch (error) {
     38      status2 = 'Symbol("2")';
     39    }
     40 
     41    $262.agent.report(status1);
     42    $262.agent.report(status2);
     43    $262.agent.leaving();
     44  });
     45 `);
     46 
     47 const i32a = new Int32Array(
     48  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
     49 );
     50 
     51 $262.agent.safeBroadcast(i32a);
     52 $262.agent.waitUntil(i32a, RUNNING, 1);
     53 
     54 // Try to yield control to ensure the agent actually started to wait.
     55 $262.agent.tryYield();
     56 
     57 assert.sameValue(
     58  $262.agent.getReport(),
     59  'Symbol("1")',
     60  '$262.agent.getReport() returns "Symbol("1")"'
     61 );
     62 assert.sameValue(
     63  $262.agent.getReport(),
     64  'Symbol("2")',
     65  '$262.agent.getReport() returns "Symbol("2")"'
     66 );
     67 
     68 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
     69 
     70 reportCompare(0, 0);