good-views.js (1777B)
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.store 6 description: Test Atomics.store on arrays that allow atomic operations. 7 includes: [testAtomics.js, testBigIntTypedArray.js] 8 features: [ArrayBuffer, Atomics, BigInt, DataView, SharedArrayBuffer, Symbol, TypedArray] 9 ---*/ 10 // Make it interesting - use non-zero byteOffsets and non-zero indexes. 11 // In-bounds boundary cases for indexing 12 const sab = new SharedArrayBuffer(1024); 13 const ab = new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 2); 14 15 testWithBigIntTypedArrayConstructors(function(TA) { 16 const view = new TA(sab, 32, 20); 17 const control = new TA(ab, 0, 2); 18 19 const values = [ 20 10n, 21 -5n, 22 12345n, 23 123456789n, 24 BigInt('33'), 25 { 26 valueOf: function() { return 33n; } 27 } 28 ]; 29 30 for (let i = 0; i < values.length; i++) { 31 let val = values[i]; 32 assert.sameValue( 33 Atomics.store(view, 3, val), 34 BigInt(val), 35 'Atomics.store(view, 3, val) returns BigInt(val)' 36 ); 37 38 control[0] = val; 39 40 assert.sameValue( 41 view[3], 42 control[0], 43 'The value of view[3] equals the value of `control[0]` (val)' 44 ); 45 } 46 47 testWithAtomicsInBoundsIndices(function(IdxGen) { 48 let Idx = IdxGen(view); 49 view.fill(0n); 50 Atomics.store(view, Idx, 37n); 51 assert.sameValue(Atomics.load(view, Idx), 37n, 'Atomics.load(view, Idx) returns 37n'); 52 }); 53 }); 54 55 reportCompare(0, 0);