diff --git a/harness/nans.js b/harness/nans.js index e541dba02b..3636a0b8c4 100644 --- a/harness/nans.js +++ b/harness/nans.js @@ -7,6 +7,15 @@ description: | weak basis for assertions regarding the consistent canonicalization of NaN values in Array buffers. ---*/ -var distinctNaNs = [ - 0/0, Infinity/Infinity, -(0/0), Math.pow(-1, 0.5), -Math.pow(-1, 0.5) + +var NaNs = [ + () => NaN, + () => Number.NaN, + () => NaN * 0, + () => 0/0, + () => Infinity/Infinity, + () => -(0/0), + () => Math.pow(-1, 0.5), + () => -Math.pow(-1, 0.5), + () => Number("Not-a-Number"), ]; diff --git a/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence-define-own-property-reassign.js b/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence-define-own-property-reassign.js new file mode 100644 index 0000000000..fe1d3ba2a1 --- /dev/null +++ b/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence-define-own-property-reassign.js @@ -0,0 +1,68 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Replaces value field even if they pass in the SameValue algorithm, including + distinct NaN values +info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + Previously, this test compared the "value" field using the SameValue + algorithm (thereby ignoring distinct NaN values) + + --- + + [[DefineOwnProperty]] (P, Desc) + + Return ? OrdinaryDefineOwnProperty(O, P, Desc). + + #sec-ordinarydefineownproperty + OrdinaryDefineOwnProperty ( O, P, Desc ) + + 1. Let current be ? O.[[GetOwnProperty]](P). + 2. Let extensible be O.[[Extensible]]. + 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, + current). + + #sec-validateandapplypropertydescriptor + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + + ... + 7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, + then + a. If current.[[Configurable]] is false and current.[[Writable]] is false, + then + ... + ... + 9. If O is not undefined, then + a. For each field of Desc that is present, set the corresponding attribute + of the property named P of object O to the value of the field. + 10. Return true. + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js] +---*/ + +var len = NaNs.length; + +for (var idx = 0; idx < len; ++idx) { + for (var jdx = 0; jdx < len; ++jdx) { + var a = {}; + + a.prop = NaNs[idx](); + a.prop = NaNs[jdx](); + + assert( + a.prop !== a.prop, + `Object property value reassigned to NaN produced by (${NaNs[idx].toString()}) results in a valid NaN` + ); + } +} diff --git a/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence-define-own-property-reconfigure.js b/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence-define-own-property-reconfigure.js new file mode 100644 index 0000000000..7eb257bc16 --- /dev/null +++ b/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence-define-own-property-reconfigure.js @@ -0,0 +1,75 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc +description: > + Replaces value field even if they pass in the SameValue algorithm, including + distinct NaN values +info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + Previously, this method compared the "value" field using the SameValue + algorithm (thereby ignoring distinct NaN values) + + --- + + [[DefineOwnProperty]] (P, Desc) + + Return ? OrdinaryDefineOwnProperty(O, P, Desc). + + #sec-ordinarydefineownproperty + OrdinaryDefineOwnProperty ( O, P, Desc ) + + 1. Let current be ? O.[[GetOwnProperty]](P). + 2. Let extensible be O.[[Extensible]]. + 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, + current). + + #sec-validateandapplypropertydescriptor + ValidateAndApplyPropertyDescriptor ( O, P, extensible, Desc, current ) + + ... + 7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, + then + a. If current.[[Configurable]] is false and current.[[Writable]] is false, + then + ... + ... + 9. If O is not undefined, then + a. For each field of Desc that is present, set the corresponding attribute + of the property named P of object O to the value of the field. + 10. Return true. + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js] +---*/ + +var len = NaNs.length; + +for (var idx = 0; idx < len; ++idx) { + for (var jdx = 0; jdx < len; ++jdx) { + var a = {}; + var b = {}; + + Object.defineProperty(a, "prop", { + value: NaNs[idx](), + configurable: true, + }); + + Object.defineProperty(a, "prop", { + value: NaNs[jdx](), + }); + + assert( + a.prop !== a.prop, + `Object property value reconfigured to NaN produced by (${NaNs[idx].toString()}) results in a valid NaN` + ); + } +} diff --git a/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence.js b/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence.js deleted file mode 100644 index d6f4455ad1..0000000000 --- a/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence.js +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2016 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc -es6id: 9.1.6 -description: > - Replaces value field even if they pass in the SameValue algorithm, including - distinct NaN values -info: | - Previously, this method compared the "value" field using the SameValue - algorithm (thereby ignoring distinct NaN values) - - --- - - [[DefineOwnProperty]] (P, Desc) - - 1. Return ? OrdinaryDefineOwnProperty(O, P, Desc). - - 9.1.6.1 OrdinaryDefineOwnProperty - - 1. Let current be ? O.[[GetOwnProperty]](P). - 2. Let extensible be O.[[Extensible]]. - 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, - current). - - 9.1.6.3 ValidateAndApplyPropertyDescriptor - - [...] - 7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, - then - a. If current.[[Configurable]] is false and current.[[Writable]] is false, - then - [...] - [...] - 9. If O is not undefined, then - a. For each field of Desc that is present, set the corresponding attribute - of the property named P of object O to the value of the field. - 10. Return true. -features: [Float64Array, Uint8Array, Uint16Array] -includes: [nans.js] ----*/ - -var isLittleEndian = new Uint8Array(new Uint16Array([1]).buffer)[0] !== 0; - -var float = new Float64Array(1); -var ints = new Uint8Array(float.buffer); -var len = distinctNaNs.length; - -function byteValue(value) { - float[0] = value; - - var hex = "0123456789ABCDEF"; - var s = ""; - for (var i = 0; i < 8; ++i) { - var v = ints[isLittleEndian ? 7 - i : i]; - s += hex[(v >> 4) & 0xf] + hex[v & 0xf]; - } - return s; -} - -/** - * Iterate over each pair of distinct NaN values (with replacement). If two or - * more suitable NaN values cannot be identified, the semantics under test - * cannot be verified and this test is expected to pass without evaluating any - * assertions. - */ -for (var idx = 0; idx < len; ++idx) { - for (var jdx = 0; jdx < len; ++jdx) { - // NB: Don't store the distinct NaN values as global variables, because - // global variables are properties of the global object. And in this test - // we want to ensure NaN-valued properties in objects are properly handled, - // so storing NaN values in the (global) object defeats the purpose. - if (byteValue(distinctNaNs[idx]) === byteValue(distinctNaNs[jdx])) { - continue; - } - - var subject = {}; - subject.prop = distinctNaNs[idx]; - subject.prop = distinctNaNs[jdx]; - - assert.sameValue( - byteValue(subject.prop), - byteValue(distinctNaNs[jdx]), - 'Property value was re-set' - ); - } -} diff --git a/test/built-ins/TypedArray/prototype/copyWithin/bit-precision.js b/test/built-ins/TypedArray/prototype/copyWithin/bit-precision.js index 215f01f4a5..1aa660622b 100644 --- a/test/built-ins/TypedArray/prototype/copyWithin/bit-precision.js +++ b/test/built-ins/TypedArray/prototype/copyWithin/bit-precision.js @@ -17,14 +17,14 @@ features: [TypedArray] ---*/ function body(FloatArray) { - var subject = new FloatArray(distinctNaNs.length * 2); + var subject = new FloatArray(NaNs.length * 2); - distinctNaNs.forEach(function(v, i) { - subject[i] = v; + NaNs.forEach(function(v, i) { + subject[i] = v(); }); var originalBytes, copiedBytes; - var length = distinctNaNs.length * FloatArray.BYTES_PER_ELEMENT; + var length = NaNs.length * FloatArray.BYTES_PER_ELEMENT; originalBytes = new Uint8Array( subject.buffer, @@ -32,7 +32,7 @@ function body(FloatArray) { length ); - subject.copyWithin(distinctNaNs.length, 0); + subject.copyWithin(NaNs.length, 0); copiedBytes = new Uint8Array( subject.buffer, length diff --git a/test/built-ins/TypedArray/prototype/fill/fill-values-conversion-operations-consistent-nan.js b/test/built-ins/TypedArray/prototype/fill/fill-values-conversion-operations-consistent-nan.js index 80e435b2e1..34e1f507bc 100644 --- a/test/built-ins/TypedArray/prototype/fill/fill-values-conversion-operations-consistent-nan.js +++ b/test/built-ins/TypedArray/prototype/fill/fill-values-conversion-operations-consistent-nan.js @@ -2,8 +2,14 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.fill -description: Consistent canonicalization of NaN values +description: > + An implementation must always choose either the same encoding for each implementation distinguishable *NaN* value, or an implementation-defined canonical value. info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) %TypedArray%.prototype.fill is a distinct function that implements the same @@ -17,7 +23,8 @@ info: | ... - 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + #sec-array.prototype.fill + Array.prototype.fill (value [ , start [ , end ] ] ) ... 7. Repeat, while k < final @@ -25,46 +32,70 @@ info: | b. Perform ? Set(O, Pk, value, true). ... - 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) - ... - 8. If type is "Float32", then + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + NumberToRawBytes( type, value, isLittleEndian ) + + 1. If type is "Float32", then a. Set rawBytes to a List containing the 4 bytes that are the result of converting value to IEEE 754-2008 binary32 format using “Round to nearest, ties to even” rounding mode. If isLittleEndian is false, the bytes are arranged in big endian order. Otherwise, the bytes are arranged in little endian order. If value is NaN, rawValue may be set to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number - encoding. An implementation must always choose the same encoding for - each implementation distinguishable NaN value. - 9. Else, if type is "Float64", then - a. Set rawBytes to a List containing the 8 bytes that are the IEEE - 754-2008 binary64 format encoding of value. If isLittleEndian is false, - the bytes are arranged in big endian order. Otherwise, the bytes are - arranged in little endian order. If value is NaN, rawValue may be set - to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number - encoding. An implementation must always choose the same encoding for - each implementation distinguishable NaN value. + encoding. An implementation must always choose either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. Else, if type is "Float64", then + a. Set _rawBytes_ to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of _value_. If _isLittleEndian_ is + *false*, the bytes are arranged in big endian order. Otherwise, + the bytes are arranged in little endian order. If _value_ is *NaN*, + _rawValue_ may be set to any implementation chosen IEEE 754-2008 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. ... -includes: [nans.js, testTypedArray.js, compareArray.js] + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, testTypedArray.js] features: [TypedArray] ---*/ -function body(FloatArray) { - var sample = new FloatArray(3); - var control, idx, someNaN, sampleBytes, controlBytes; +testWithTypedArrayConstructors(function(FA) { + var precision = FA === Float32Array ? "single" : "double"; + var samples = new FA(3); + var controls, idx, aNaN; - for (idx = 0; idx < distinctNaNs.length; ++idx) { - someNaN = distinctNaNs[idx]; - control = new FloatArray([someNaN, someNaN, someNaN]); + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx](); + controls = new Float32Array([aNaN, aNaN, aNaN]); - sample.fill(someNaN); + samples.fill(aNaN); - sampleBytes = new Uint8Array(sample.buffer); - controlBytes = new Uint8Array(control.buffer); - assert(compareArray(sampleBytes, controlBytes), 'NaN value #' + idx); + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + `samples (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)` + ); + + assert( + controls[i] !== controls[i], + `controls (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)` + ); + } } -} - -testWithTypedArrayConstructors(body, [Float32Array, Float64Array]); +}, [Float32Array, Float64Array]); diff --git a/test/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js b/test/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js index 15b63f7915..7774273dc3 100644 --- a/test/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js +++ b/test/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js @@ -45,12 +45,12 @@ features: [TypedArray] ---*/ function body(FloatArray) { - var sample = new FloatArray(distinctNaNs); + var sample = new FloatArray(NaNs.map(n => n())); var sampleBytes, resultBytes; var i = 0; var result = sample.map(function() { - return distinctNaNs[i++]; + return NaNs[i++]; }); sampleBytes = new Uint8Array(sample.buffer); diff --git a/test/built-ins/TypedArray/prototype/set/bit-precision.js b/test/built-ins/TypedArray/prototype/set/bit-precision.js index 0e9aac1c86..569d9cdd79 100644 --- a/test/built-ins/TypedArray/prototype/set/bit-precision.js +++ b/test/built-ins/TypedArray/prototype/set/bit-precision.js @@ -19,9 +19,9 @@ includes: [nans.js, compareArray.js, testTypedArray.js] features: [TypedArray] ---*/ -function body(FloatArray) { - var source = new FloatArray(distinctNaNs); - var target = new FloatArray(distinctNaNs.length); +function body(FA) { + var source = new FA(NaNs.map(n => n())); + var target = new FA(NaNs.length); var sourceBytes, targetBytes; target.set(source); diff --git a/test/built-ins/TypedArray/prototype/slice/bit-precision.js b/test/built-ins/TypedArray/prototype/slice/bit-precision.js index 6f86ad033f..4698d460c6 100644 --- a/test/built-ins/TypedArray/prototype/slice/bit-precision.js +++ b/test/built-ins/TypedArray/prototype/slice/bit-precision.js @@ -25,7 +25,7 @@ features: [TypedArray] ---*/ function body(FloatArray) { - var subject = new FloatArray(distinctNaNs); + var subject = new FloatArray(NaNs.map(n => n())); var sliced, subjectBytes, slicedBytes; sliced = subject.slice(); diff --git a/test/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js b/test/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js index d01684942b..bb652e602e 100644 --- a/test/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js +++ b/test/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js @@ -50,8 +50,8 @@ features: [TypedArray] ---*/ function body(FloatArray) { - var first = new FloatArray(distinctNaNs); - var second = new FloatArray(distinctNaNs); + var first = new FloatArray(NaNs.map(n => n())); + var second = new FloatArray(NaNs.map(n => n())); var firstBytes = new Uint8Array(first.buffer); var secondBytes = new Uint8Array(second.buffer); diff --git a/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js b/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js index c990ecd979..434b557e67 100644 --- a/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js +++ b/test/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js @@ -4,7 +4,12 @@ esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc description: Consistent canonicalization of NaN values info: | - 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + [[DefineOwnProperty]] ( P, Desc) ... 3. If Type(P) is String, then @@ -16,52 +21,78 @@ info: | 2. Return ? IntegerIndexedElementSet(O, intIndex, value). ... - 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + #sec-integerindexedelementset + IntegerIndexedElementSet ( O, index, value ) ... 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). ... - 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) - ... - 8. If type is "Float32", then + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + NumberToRawBytes( type, value, isLittleEndian ) + + 1. If type is "Float32", then a. Set rawBytes to a List containing the 4 bytes that are the result of converting value to IEEE 754-2008 binary32 format using “Round to nearest, ties to even” rounding mode. If isLittleEndian is false, the bytes are arranged in big endian order. Otherwise, the bytes are arranged in little endian order. If value is NaN, rawValue may be set to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number - encoding. An implementation must always choose the same encoding for - each implementation distinguishable NaN value. - 9. Else, if type is "Float64", then - a. Set rawBytes to a List containing the 8 bytes that are the IEEE - 754-2008 binary64 format encoding of value. If isLittleEndian is false, - the bytes are arranged in big endian order. Otherwise, the bytes are - arranged in little endian order. If value is NaN, rawValue may be set - to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number - encoding. An implementation must always choose the same encoding for - each implementation distinguishable NaN value. + encoding. An implementation must always choose either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. Else, if type is "Float64", then + a. Set _rawBytes_ to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of _value_. If _isLittleEndian_ is + *false*, the bytes are arranged in big endian order. Otherwise, + the bytes are arranged in little endian order. If _value_ is *NaN*, + _rawValue_ may be set to any implementation chosen IEEE 754-2008 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. ... -includes: [nans.js, testTypedArray.js, compareArray.js] + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, testTypedArray.js] features: [TypedArray] ---*/ -function body(FloatArray) { - var sample = new FloatArray(1); - var control, idx, someNaN, sampleBytes, controlBytes; +testWithTypedArrayConstructors(function(FA) { + var precision = FA === Float32Array ? "single" : "double"; + var samples = new FA(1); + var controls, idx, aNaN; - for (idx = 0; idx < distinctNaNs.length; ++idx) { - someNaN = distinctNaNs[idx]; - control = new FloatArray([someNaN]); + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx](); + controls = new FA([aNaN, aNaN, aNaN]); - Object.defineProperty(sample, '0', { value: someNaN }); + Object.defineProperty(samples, "0", { value: aNaN }); - sampleBytes = new Uint8Array(sample.buffer); - controlBytes = new Uint8Array(control.buffer); - assert(compareArray(sampleBytes, controlBytes)); + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + `samples (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)` + ); + + assert( + controls[i] !== controls[i], + `controls (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)` + ); + } } -} +}, [Float32Array, Float64Array]); -testWithTypedArrayConstructors(body, [Float32Array, Float64Array]); diff --git a/test/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js b/test/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js index 39a672a641..6d9b1677a5 100644 --- a/test/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js +++ b/test/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js @@ -4,7 +4,12 @@ esid: sec-integer-indexed-exotic-objects-set-p-v-receiver description: Consistent canonicalization of NaN values info: | - 9.4.5.5 [[Set]] ( P, V, Receiver) + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + [[Set]] ( P, V, Receiver) ... 2. If Type(P) is String, then @@ -13,52 +18,79 @@ info: | i. Return ? IntegerIndexedElementSet(O, numericIndex, V). ... - 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + #sec-integerindexedelementset + IntegerIndexedElementSet ( O, index, value ) ... 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). ... - 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , isLittleEndian ] ) - ... - 8. If type is "Float32", then + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + + NumberToRawBytes( type, value, isLittleEndian ) + + 1. If type is "Float32", then a. Set rawBytes to a List containing the 4 bytes that are the result of converting value to IEEE 754-2008 binary32 format using “Round to nearest, ties to even” rounding mode. If isLittleEndian is false, the bytes are arranged in big endian order. Otherwise, the bytes are arranged in little endian order. If value is NaN, rawValue may be set to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number - encoding. An implementation must always choose the same encoding for - each implementation distinguishable NaN value. - 9. Else, if type is "Float64", then - a. Set rawBytes to a List containing the 8 bytes that are the IEEE - 754-2008 binary64 format encoding of value. If isLittleEndian is false, - the bytes are arranged in big endian order. Otherwise, the bytes are - arranged in little endian order. If value is NaN, rawValue may be set - to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number - encoding. An implementation must always choose the same encoding for - each implementation distinguishable NaN value. + encoding. An implementation must always choose either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. Else, if type is "Float64", then + a. Set _rawBytes_ to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of _value_. If _isLittleEndian_ is + *false*, the bytes are arranged in big endian order. Otherwise, + the bytes are arranged in little endian order. If _value_ is *NaN*, + _rawValue_ may be set to any implementation chosen IEEE 754-2008 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. ... -includes: [nans.js, testTypedArray.js, compareArray.js] + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, testTypedArray.js] features: [TypedArray] ---*/ -function body(FloatArray) { - var sample = new FloatArray(1); - var control, idx, someNaN, sampleBytes, controlBytes; +testWithTypedArrayConstructors(function(FA) { + var precision = FA === Float32Array ? "single" : "double"; + var samples = new FA(1); + var controls, idx, aNaN; - for (idx = 0; idx < distinctNaNs.length; ++idx) { - someNaN = distinctNaNs[idx]; - control = new FloatArray([someNaN]); + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx](); + controls = new FA([aNaN, aNaN, aNaN]); - sample[0] = someNaN; + samples[0] = aNaN; - sampleBytes = new Uint8Array(sample.buffer); - controlBytes = new Uint8Array(control.buffer); - assert(compareArray(sampleBytes, controlBytes), 'NaN value #' + idx); + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + `samples (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)` + ); + + assert( + controls[i] !== controls[i], + `controls (${NaNs[idx].toString()}) produces a valid NaN (${precision} precision)` + ); + } } -} +}, [Float32Array, Float64Array]); -testWithTypedArrayConstructors(body, [Float32Array, Float64Array]); diff --git a/test/built-ins/isNaN/return-true-nan.js b/test/built-ins/isNaN/return-true-nan.js index 1942f1c81f..d77e4cb584 100644 --- a/test/built-ins/isNaN/return-true-nan.js +++ b/test/built-ins/isNaN/return-true-nan.js @@ -14,6 +14,6 @@ info: | includes: [nans.js] ---*/ -distinctNaNs.forEach(function(v, i) { - assert.sameValue(isNaN(v), true, "value on position: " + i); +NaNs.forEach(function(v, i) { + assert.sameValue(isNaN(v()), true, "value on position: " + i); }); diff --git a/test/harness/nans.js b/test/harness/nans.js index b228838d05..bd0d7b9bd7 100644 --- a/test/harness/nans.js +++ b/test/harness/nans.js @@ -2,17 +2,23 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- description: > - Including nans.js will expose: + Including nans.js will expose: - var distinctNaNs = [ - 0/0, Infinity/Infinity, -(0/0), Math.pow(-1, 0.5), -Math.pow(-1, 0.5) - ]; + var NaNs = [ + () => NaN, + () => Number.NaN, + () => NaN * 0, + () => 0/0, + () => Infinity/Infinity, + () => -(0/0), + () => Math.pow(-1, 0.5), + () => -Math.pow(-1, 0.5), + () => Number("Not-a-Number"), + ]; includes: [nans.js] ---*/ -assert.sameValue(Number.isNaN(distinctNaNs[0]), true); -assert.sameValue(Number.isNaN(distinctNaNs[1]), true); -assert.sameValue(Number.isNaN(distinctNaNs[2]), true); -assert.sameValue(Number.isNaN(distinctNaNs[3]), true); -assert.sameValue(Number.isNaN(distinctNaNs[4]), true); +for (var i = 0; i < NaNs.length; i++) { + assert.sameValue(Number.isNaN(NaNs[i]()), true, NaNs[i].toString()); +}