tor-browser

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

good-views.js (2943B)


      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) 2017 Mozilla Corporation.  All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-atomics.or
      7 description: Test Atomics.or on arrays that allow atomic operations
      8 includes: [testAtomics.js, testTypedArray.js]
      9 features: [ArrayBuffer, Atomics, DataView, SharedArrayBuffer, Symbol, TypedArray]
     10 ---*/
     11 
     12 var sab = new SharedArrayBuffer(1024);
     13 var ab = new ArrayBuffer(16);
     14 var views = nonClampedIntArrayConstructors.slice();
     15 
     16 testWithTypedArrayConstructors(function(TA) {
     17  // Make it interesting - use non-zero byteOffsets and non-zero indexes.
     18 
     19  var view = new TA(sab, 32, 20);
     20  var control = new TA(ab, 0, 2);
     21 
     22  view[8] = 0x33333333;
     23  control[0] = 0x33333333;
     24  assert.sameValue(Atomics.or(view, 8, 0x55555555), control[0],
     25    'Atomics.or(view, 8, 0x55555555) returns the value of `control[0]` (0x33333333)');
     26 
     27  control[0] = 0x77777777;
     28  assert.sameValue(
     29    view[8],
     30    control[0],
     31    'The value of view[8] equals the value of `control[0]` (0x77777777)'
     32  );
     33  assert.sameValue(Atomics.or(view, 8, 0xF0F0F0F0), control[0],
     34    'Atomics.or(view, 8, 0xF0F0F0F0) returns the value of `control[0]` (0x77777777)');
     35 
     36  control[0] = 0xF7F7F7F7;
     37  assert.sameValue(
     38    view[8],
     39    control[0],
     40    'The value of view[8] equals the value of `control[0]` (0xF7F7F7F7)'
     41  );
     42 
     43  view[3] = -5;
     44  control[0] = -5;
     45  assert.sameValue(Atomics.or(view, 3, 0), control[0],
     46    'Atomics.or(view, 3, 0) returns the value of `control[0]` (-5)');
     47  assert.sameValue(
     48    view[3],
     49    control[0],
     50    'The value of view[3] equals the value of `control[0]` (-5)'
     51  );
     52 
     53  control[0] = 12345;
     54  view[3] = 12345;
     55  assert.sameValue(Atomics.or(view, 3, 0), control[0],
     56    'Atomics.or(view, 3, 0) returns the value of `control[0]` (12345)');
     57  assert.sameValue(
     58    view[3],
     59    control[0],
     60    'The value of view[3] equals the value of `control[0]` (12345)'
     61  );
     62 
     63  control[0] = 123456789;
     64  view[3] = 123456789;
     65  assert.sameValue(Atomics.or(view, 3, 0), control[0],
     66    'Atomics.or(view, 3, 0) returns the value of `control[0]` (123456789)');
     67  assert.sameValue(
     68    view[3],
     69    control[0],
     70    'The value of view[3] equals the value of `control[0]` (123456789)'
     71  );
     72 
     73  // In-bounds boundary cases for indexing
     74  testWithAtomicsInBoundsIndices(function(IdxGen) {
     75    let Idx = IdxGen(view);
     76    view.fill(0);
     77    // Atomics.store() computes an index from Idx in the same way as other
     78    // Atomics operations, not quite like view[Idx].
     79    Atomics.store(view, Idx, 37);
     80    assert.sameValue(Atomics.or(view, Idx, 0), 37, 'Atomics.or(view, Idx, 0) returns 37');
     81  });
     82 }, views);
     83 
     84 reportCompare(0, 0);