tor-browser

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

good-views.js (2300B)


      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.add
      7 description: Test Atomics.add 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  // Add positive number
     23  view[8] = 0;
     24  assert.sameValue(Atomics.add(view, 8, 10), 0, 'Atomics.add(view, 8, 10) returns 0');
     25  assert.sameValue(view[8], 10, 'The value of view[8] is 10');
     26 
     27  // Add negative number
     28  assert.sameValue(Atomics.add(view, 8, -5), 10, 'Atomics.add(view, 8, -5) returns 10');
     29  assert.sameValue(view[8], 5, 'The value of view[8] is 5');
     30 
     31  view[3] = -5;
     32  control[0] = -5;
     33  assert.sameValue(Atomics.add(view, 3, 0), control[0],
     34    'Atomics.add(view, 3, 0) returns the value of `control[0]` (-5)');
     35 
     36  control[0] = 12345;
     37  view[3] = 12345;
     38  assert.sameValue(Atomics.add(view, 3, 0), control[0],
     39    'Atomics.add(view, 3, 0) returns the value of `control[0]` (12345)');
     40 
     41  control[0] = 123456789;
     42  view[3] = 123456789;
     43  assert.sameValue(Atomics.add(view, 3, 0), control[0],
     44    'Atomics.add(view, 3, 0) returns the value of `control[0]` (123456789)');
     45 
     46  // In-bounds boundary cases for indexing
     47  testWithAtomicsInBoundsIndices(function(IdxGen) {
     48    let Idx = IdxGen(view);
     49    view.fill(0);
     50    // Atomics.store() computes an index from Idx in the same way as other
     51    // Atomics operations, not quite like view[Idx].
     52    Atomics.store(view, Idx, 37);
     53    assert.sameValue(Atomics.add(view, Idx, 0), 37, 'Atomics.add(view, Idx, 0) returns 37');
     54  });
     55 }, views);
     56 
     57 reportCompare(0, 0);