From 57f08843967390f950c78471fd59adbbac886e92 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Wed, 12 Jun 2019 21:14:14 +0300 Subject: [PATCH] Use SameValue in verifyProperty helper (#2185) --- harness/propertyHelper.js | 13 +++++++------ test/harness/verifyProperty-same-value.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 test/harness/verifyProperty-same-value.js diff --git a/harness/propertyHelper.js b/harness/propertyHelper.js index edf86e9490..a3a57a1beb 100644 --- a/harness/propertyHelper.js +++ b/harness/propertyHelper.js @@ -47,7 +47,7 @@ function verifyProperty(obj, name, desc, options) { var failures = []; if (Object.prototype.hasOwnProperty.call(desc, 'value')) { - if (desc.value !== originalDesc.value) { + if (!isSameValue(desc.value, originalDesc.value)) { failures.push("descriptor value should be " + desc.value); } } @@ -113,10 +113,11 @@ function isEnumerable(obj, name) { Object.prototype.propertyIsEnumerable.call(obj, name); } -function isEqualTo(obj, name, expectedValue) { - var actualValue = obj[name]; +function isSameValue(a, b) { + if (a === 0 && b === 0) return 1 / a === 1 / b; + if (a !== a && b !== b) return true; - return assert._isSameValue(actualValue, expectedValue); + return a === b; } function isWritable(obj, name, verifyProp, value) { @@ -133,7 +134,7 @@ function isWritable(obj, name, verifyProp, value) { } } - writeSucceeded = isEqualTo(obj, verifyProp || name, newValue); + writeSucceeded = isSameValue(obj[verifyProp || name], newValue); // Revert the change only if it was successful (in other cases, reverting // is unnecessary and may trigger exceptions for certain property @@ -150,7 +151,7 @@ function isWritable(obj, name, verifyProp, value) { } function verifyEqualTo(obj, name, value) { - if (!isEqualTo(obj, name, value)) { + if (!isSameValue(obj[name], value)) { $ERROR("Expected obj[" + String(name) + "] to equal " + value + ", actually " + obj[name]); } diff --git a/test/harness/verifyProperty-same-value.js b/test/harness/verifyProperty-same-value.js new file mode 100644 index 0000000000..f871461522 --- /dev/null +++ b/test/harness/verifyProperty-same-value.js @@ -0,0 +1,19 @@ +// Copyright (C) 2019 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: > + verifyProperty uses SameValue for value comparison. +includes: [propertyHelper.js] +---*/ + +var obj = { + a: NaN, + b: -0, +}; + +assert(verifyProperty(obj, 'a', { value: NaN })); +assert(verifyProperty(obj, 'b', { value: -0 })); + +assert.throws(Test262Error, function() { + verifyProperty(obj, 'b', { value: 0 }); +});