tor-browser

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

good-views.js (2389B)


      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.exchange
      7 description: Test Atomics.exchange on arrays that allow atomic operations.
      8 includes: [testAtomics.js, testTypedArray.js]
      9 features: [ArrayBuffer, Atomics, DataView, SharedArrayBuffer, Symbol, TypedArray]
     10 ---*/
     11 
     12 const sab = new SharedArrayBuffer(1024);
     13 const ab = new ArrayBuffer(16);
     14 const views = nonClampedIntArrayConstructors.slice();
     15 
     16 testWithTypedArrayConstructors(function(TA) {
     17  // Make it interesting - use non-zero byteOffsets and non-zero indexes.
     18 
     19  const view = new TA(sab, 32, 20);
     20  const control = new TA(ab, 0, 2);
     21 
     22  view[8] = 0;
     23  assert.sameValue(Atomics.exchange(view, 8, 10), 0,
     24    'Atomics.exchange(view, 8, 10) returns 0');
     25  assert.sameValue(view[8], 10, 'The value of view[8] is 10');
     26 
     27  assert.sameValue(Atomics.exchange(view, 8, -5), 10,
     28    'Atomics.exchange(view, 8, -5) returns 10');
     29  control[0] = -5;
     30  assert.sameValue(view[8], control[0], 'The value of view[8] equals the value of `control[0]` (-5)');
     31 
     32  view[3] = -5;
     33  control[0] = -5;
     34  assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
     35    'Atomics.exchange(view, 3, 0) returns the value of `control[0]` (-5)');
     36 
     37  control[0] = 12345;
     38  view[3] = 12345;
     39  assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
     40    'Atomics.exchange(view, 3, 0) returns the value of `control[0]` (12345)');
     41 
     42  control[0] = 123456789;
     43  view[3] = 123456789;
     44  assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
     45    'Atomics.exchange(view, 3, 0) returns the value of `control[0]` (123456789)');
     46 
     47  // In-bounds boundary cases for indexing
     48  testWithAtomicsInBoundsIndices(function(IdxGen) {
     49    let Idx = IdxGen(view);
     50    view.fill(0);
     51    // Atomics.store() computes an index from Idx in the same way as other
     52    // Atomics operations, not quite like view[Idx].
     53    Atomics.store(view, Idx, 37);
     54    assert.sameValue(Atomics.exchange(view, Idx, 0), 37, 'Atomics.exchange(view, Idx, 0) returns 37');
     55  });
     56 }, views);
     57 
     58 reportCompare(0, 0);