Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Atomics / sub / expected-return-value.js
blobb798da4a4a00f6e0943b1b736809fc249a208be8
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.
5 /*---
6 esid: sec-atomics.sub
7 description: >
8   Atomics.and returns the value that existed at the
9   index prior to the operation.
10 info: |
11   Atomics.sub( typedArray, index, value )
13   1. Return ? AtomicReadModifyWrite(typedArray, index, value, subtract).
15   AtomicReadModifyWrite( typedArray, index, value, op )
17   ...
18   9. Return GetModifySetValueInBuffer(buffer, indexedPosition,
19                                       elementType, v, op).
22   GetModifySetValueInBuffer( arrayBuffer,
23     byteIndex, type, value, op [ , isLittleEndian ] )
25   ...
26   16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian).
28 features: [Atomics, SharedArrayBuffer, TypedArray]
29 ---*/
31 const i32a = new Int32Array(
32   new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
34 const update = 0b00000001000000001000000010000001;
36 i32a[0] = update;
38 assert.sameValue(
39   Atomics.sub(i32a, 0, update),
40   update,
41   'Atomics.sub(i32a, 0, update) returns the value of `update` (0b00000001000000001000000010000001)'
43 assert.sameValue(i32a[0], 0, 'The value of i32a[0] is 0');
45 reportCompare(0, 0);