Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / TypedArrayConstructors / internals / Set / conversion-operation-consistent-nan.js
blobb97ef770e19c7d32023be6b065703da2aee0cbc5
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
5 description: Consistent canonicalization of NaN values
6 info: |
7   This test does not compare the actual byte values, instead it simply checks that
8   the value is some valid NaN encoding.
10   ---
12   [[Set]] ( P, V, Receiver)
14   ...
15   2. If Type(P) is String, then
16     ...
17     b. If numericIndex is not undefined, then
18       i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
19       ii. Return true.
20   ...
22   IntegerIndexedElementSet ( O, index, value )
24   Assert: O is an Integer-Indexed exotic object.
25   If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
26   Otherwise, let numValue be ? ToNumber(value).
27   Let buffer be O.[[ViewedArrayBuffer]].
28   If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
29     Let offset be O.[[ByteOffset]].
30     Let arrayTypeName be the String value of O.[[TypedArrayName]].
31     Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
32     Let indexedPosition be (ℝ(index) × elementSize) + offset.
33     Let elementType be the Element Type value in Table 62 for arrayTypeName.
34     Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
35   Return NormalCompletion(undefined).
37   #sec-setvalueinbuffer
38   SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ ,
39   isLittleEndian ] )
41   8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian).
43   #sec-numbertorawbytes
45   NumberToRawBytes( type, value, isLittleEndian )
47   1. If type is "Float32", then
48      a. Set rawBytes to a List containing the 4 bytes that are the result
49         of converting value to IEEE 754-2008 binary32 format using “Round to
50         nearest, ties to even” rounding mode. If isLittleEndian is false, the
51         bytes are arranged in big endian order. Otherwise, the bytes are
52         arranged in little endian order. If value is NaN, rawValue may be set
53         to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number
54         encoding. An implementation must always choose either the same encoding
55         for each implementation distinguishable *NaN* value, or an
56         implementation-defined canonical value.
57   2. Else, if type is "Float64", then
58      a. Set _rawBytes_ to a List containing the 8 bytes that are the IEEE
59         754-2008 binary64 format encoding of _value_. If _isLittleEndian_ is
60         *false*, the bytes are arranged in big endian order. Otherwise,
61         the bytes are arranged in little endian order. If _value_ is *NaN*,
62         _rawValue_ may be set to any implementation chosen IEEE 754-2008
63         binary64 format Not-a-Number encoding. An implementation must
64         always choose either the same encoding for each implementation
65         distinguishable *NaN* value, or an implementation-defined
66         canonical value.
67   ...
69   #sec-isnan-number
71   NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is
72   an expression of the form  X !== X. The result will be true if and only
73   if X is a NaN.
74 includes: [nans.js, testTypedArray.js]
75 features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
76 ---*/
78 testWithTypedArrayConstructors(function(FA) {
79   var precision = floatTypedArrayConstructorPrecision(FA);
80   var samples = new FA(1);
81   var controls, idx, aNaN;
83   for (idx = 0; idx < NaNs.length; ++idx) {
84     aNaN = NaNs[idx];
85     controls = new FA([aNaN, aNaN, aNaN]);
87     samples[0] = aNaN;
89     for (var i = 0; i < samples.length; i++) {
90       var sample = samples[i];
91       var control = controls[i];
93       assert(
94         samples[i] !== samples[i],
95         `The result of \`(samples[i] !== samples[i])\` is true (${precision} precision)`
96       );
98       assert(
99         controls[i] !== controls[i],
100         `The result of \`(controls[i] !== controls[i])\` is true (${precision} precision)`
101       );
102     }
103   }
104 }, floatArrayConstructors);
107 reportCompare(0, 0);