tor-browser

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

symbol-for-value-throws-agent.js (2270B)


      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 value arg is a Symbol
      9 info: |
     10  Atomics.wait( typedArray, index, value, timeout )
     11 
     12  3. Let v be ? ToInt32(value).
     13 
     14  ToInt32(value)
     15 
     16  1.Let number be ? ToNumber(argument).
     17 
     18    Symbol --> Throw a TypeError exception.
     19 
     20 includes: [atomicsHelper.js]
     21 features: [Atomics, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray]
     22 ---*/
     23 
     24 const RUNNING = 1;
     25 
     26 $262.agent.start(`
     27  const poisonedValueOf = {
     28    valueOf: function() {
     29      throw new Test262Error('should not evaluate this code');
     30    }
     31  };
     32 
     33  const poisonedToPrimitive = {
     34    [Symbol.toPrimitive]: function() {
     35      throw new Test262Error("passing a poisoned object using @@ToPrimitive");
     36    }
     37  };
     38 
     39  $262.agent.receiveBroadcast(function(sab) {
     40    const i32a = new Int32Array(sab);
     41    Atomics.add(i32a, ${RUNNING}, 1);
     42 
     43    let status1 = "";
     44    let status2 = "";
     45 
     46    try {
     47      Atomics.wait(i32a, 0, Symbol("1"), poisonedValueOf);
     48    } catch (error) {
     49      status1 = 'Symbol("1")';
     50    }
     51    try {
     52      Atomics.wait(i32a, 0, Symbol("2"), poisonedToPrimitive);
     53    } catch (error) {
     54      status2 = 'Symbol("2")';
     55    }
     56 
     57    $262.agent.report(status1);
     58    $262.agent.report(status2);
     59    $262.agent.leaving();
     60  });
     61 `);
     62 
     63 const i32a = new Int32Array(
     64  new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
     65 );
     66 
     67 $262.agent.safeBroadcast(i32a);
     68 $262.agent.waitUntil(i32a, RUNNING, 1);
     69 
     70 // Try to yield control to ensure the agent actually started to wait.
     71 $262.agent.tryYield();
     72 
     73 assert.sameValue(
     74  $262.agent.getReport(),
     75  'Symbol("1")',
     76  '$262.agent.getReport() returns "Symbol("1")"'
     77 );
     78 assert.sameValue(
     79  $262.agent.getReport(),
     80  'Symbol("2")',
     81  '$262.agent.getReport() returns "Symbol("2")"'
     82 );
     83 
     84 assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
     85 
     86 reportCompare(0, 0);