Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / Atomics / sub / validate-arraytype-before-value-coercion.js
blob7af4d36a94454a7c6703560ee5c518e43eb9e2eb
1 // |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally
2 // Copyright (C) 2019 AndrĂ© Bargull. 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   TypedArray type is validated before `value` argument is coerced.
9 info: |
10   24.4.10 Atomics.sub ( typedArray, index, value )
11     1. Return ? AtomicReadModifyWrite(typedArray, index, value, sub).
13   24.4.1.11 AtomicReadModifyWrite ( typedArray, index, value, op )
14     1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray).
15     ...
17   24.4.1.1 ValidateSharedIntegerTypedArray ( typedArray [ , onlyInt32 ] )
18     ...
19     4. Let typeName be typedArray.[[TypedArrayName]].
20     5. If onlyInt32 is true, then
21       a. If typeName is not "Int32Array", throw a TypeError exception.
22     6. Else,
23       a. If typeName is not "Int8Array", "Uint8Array", "Int16Array", "Uint16Array", "Int32Array",
24          or "Uint32Array", throw a TypeError exception.
25     ...
26 includes: [testTypedArray.js]
27 features: [Atomics, TypedArray]
28 ---*/
30 var value = {
31   valueOf() {
32     throw new Test262Error("value coerced");
33   }
36 for (var badArrayType of nonAtomicsFriendlyTypedArrayConstructors) {
37   var typedArray = new badArrayType(new SharedArrayBuffer(8));
38   assert.throws(TypeError, function() {
39     Atomics.sub(typedArray, 0, value);
40   });
43 reportCompare(0, 0);