tor-browser

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

good-views.js (2625B)


      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 Rick Waldron. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 esid: sec-atomics.and
      6 description: Test Atomics.and on arrays that allow atomic operations
      7 includes: [testAtomics.js, testBigIntTypedArray.js]
      8 features: [ArrayBuffer, Atomics, BigInt, DataView, SharedArrayBuffer, Symbol, TypedArray]
      9 ---*/
     10 const sab = new SharedArrayBuffer(1024);
     11 const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2);
     12 
     13 testWithBigIntTypedArrayConstructors(function(TA) {
     14  const view = new TA(sab, 32, 20);
     15  const control = new TA(ab, 0, 2);
     16  view[8] = 0x33333333n;
     17  control[0] = 0x33333333n;
     18 
     19  assert.sameValue(
     20    Atomics.and(view, 8, 0x55555555n),
     21    control[0],
     22    'Atomics.and(view, 8, 0x55555555n) returns the value of `control[0]` (0x33333333n)'
     23  );
     24 
     25  control[0] = 0x11111111n;
     26 
     27  assert.sameValue(
     28    view[8],
     29    control[0],
     30    'The value of view[8] equals the value of `control[0]` (0x11111111n)'
     31  );
     32 
     33  assert.sameValue(
     34    Atomics.and(view, 8, 0xF0F0F0F0n),
     35    control[0],
     36    'Atomics.and(view, 8, 0xF0F0F0F0n) returns the value of `control[0]` (0x11111111n)'
     37  );
     38 
     39  control[0] = 0x10101010n;
     40 
     41  assert.sameValue(
     42    view[8],
     43    control[0],
     44    'The value of view[8] equals the value of `control[0]` (0x10101010n)'
     45  );
     46 
     47  view[3] = -5n;
     48  control[0] = -5n;
     49 
     50  assert.sameValue(
     51    Atomics.and(view, 3, 0n),
     52    control[0],
     53    'Atomics.and(view, 3, 0n) returns the value of `control[0]` (-5n)'
     54  );
     55 
     56  assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
     57  control[0] = 12345n;
     58  view[3] = 12345n;
     59 
     60  assert.sameValue(
     61    Atomics.and(view, 3, 0n),
     62    control[0],
     63    'Atomics.and(view, 3, 0n) returns the value of `control[0]` (12345n)'
     64  );
     65 
     66  assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
     67  control[0] = 123456789n;
     68  view[3] = 123456789n;
     69 
     70  assert.sameValue(
     71    Atomics.and(view, 3, 0n),
     72    control[0],
     73    'Atomics.and(view, 3, 0n) returns the value of `control[0]` (123456789n)'
     74  );
     75 
     76  assert.sameValue(view[3], 0n, 'The value of view[3] is 0n');
     77 
     78  testWithAtomicsInBoundsIndices(function(IdxGen) {
     79    let Idx = IdxGen(view);
     80    view.fill(0n);
     81    Atomics.store(view, Idx, 37n);
     82    assert.sameValue(Atomics.and(view, Idx, 0n), 37n, 'Atomics.and(view, Idx, 0n) returns 37n');
     83  });
     84 });
     85 
     86 reportCompare(0, 0);