From 32b1984275a31e748b7947a2142d63c76dec3ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 1 Nov 2017 07:54:05 -0700 Subject: [PATCH] Fix multiple issues in nan-equivalence.js test case --- features.txt | 1 + .../DefineOwnProperty/nan-equivalence.js | 43 +++++++++++-------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/features.txt b/features.txt index f3072571d7..0b0b8e6774 100644 --- a/features.txt +++ b/features.txt @@ -115,6 +115,7 @@ template TypedArray u180e Uint8Array +Uint16Array WeakMap WeakSet diff --git a/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence.js b/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence.js index cfa2f4bdd7..d6f4455ad1 100644 --- a/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence.js +++ b/test/built-ins/Object/internals/DefineOwnProperty/nan-equivalence.js @@ -19,7 +19,7 @@ info: | 9.1.6.1 OrdinaryDefineOwnProperty 1. Let current be ? O.[[GetOwnProperty]](P). - 2. Let extensible be the value of the [[Extensible]] internal slot of O. + 2. Let extensible be O.[[Extensible]]. 3. Return ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current). @@ -28,27 +28,34 @@ info: | [...] 7. Else if IsDataDescriptor(current) and IsDataDescriptor(Desc) are both true, then - a. If the [[Configurable]] field of current is false, then + a. If current.[[Configurable]] is false and current.[[Writable]] is false, + then [...] - b. Else the [[Configurable]] field of current is true, so any change is - acceptable. [...] 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] +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; -var idx, jdx, subject, first, second; + function byteValue(value) { float[0] = value; - return ints[0] + (ints[1] << 8) + (ints[2] << 16) + (ints[3] << 32) + - (ints[4] << 64) + (ints[5] << 64) + (ints[6] << 128) + (ints[7] << 256); + + 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; } /** @@ -57,21 +64,23 @@ function byteValue(value) { * cannot be verified and this test is expected to pass without evaluating any * assertions. */ -for (idx = 0; idx < len; ++idx) { - for (jdx = 0 ; jdx < len; ++jdx) { - first = distinctNaNs[idx]; - second = distinctNaNs[jdx]; - if (byteValue(first) === byteValue(second)) { +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; } - subject = {}; - subject.prop = first; - subject.prop = second; + var subject = {}; + subject.prop = distinctNaNs[idx]; + subject.prop = distinctNaNs[jdx]; assert.sameValue( byteValue(subject.prop), - byteValue(second), + byteValue(distinctNaNs[jdx]), 'Property value was re-set' ); }