From 5853b56f6ec52bd871b752d49c0428dba1f07cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 30 Apr 2025 14:16:08 +0200 Subject: [PATCH] Prefer verifyProperty over assert.deepEqual when comparing property descriptors --- test/staging/sm/Array/unscopables.js | 48 ++++++++++--------- .../staging/sm/Function/Function-prototype.js | 7 ++- test/staging/sm/Function/throw-type-error.js | 5 +- test/staging/sm/Set/difference.js | 6 +-- test/staging/sm/Set/intersection.js | 6 +-- test/staging/sm/Set/is-disjoint-from.js | 6 +-- test/staging/sm/Set/is-subset-of.js | 6 +-- test/staging/sm/Set/is-superset-of.js | 6 +-- test/staging/sm/Set/symmetric-difference.js | 6 +-- test/staging/sm/Set/union.js | 6 +-- test/staging/sm/TypedArray/set.js | 7 +-- test/staging/sm/TypedArray/toLocaleString.js | 7 +-- test/staging/sm/TypedArray/toString.js | 7 +-- 13 files changed, 64 insertions(+), 59 deletions(-) diff --git a/test/staging/sm/Array/unscopables.js b/test/staging/sm/Array/unscopables.js index 9dd498f4f8..7c71f0d636 100644 --- a/test/staging/sm/Array/unscopables.js +++ b/test/staging/sm/Array/unscopables.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [deepEqual.js] +includes: [compareArray.js, propertyHelper.js] flags: - noStrict description: | @@ -11,46 +11,50 @@ esid: pending ---*/ let Array_unscopables = Array.prototype[Symbol.unscopables]; -let desc = Reflect.getOwnPropertyDescriptor(Array.prototype, Symbol.unscopables); -assert.deepEqual(desc, { +verifyProperty(Array.prototype, Symbol.unscopables, { value: Array_unscopables, writable: false, enumerable: false, configurable: true +}, { + restore: true }); assert.sameValue(Reflect.getPrototypeOf(Array_unscopables), null); -let desc2 = Object.getOwnPropertyDescriptor(Array_unscopables, "values"); -assert.deepEqual(desc2, { +verifyProperty(Array_unscopables, "values", { value: true, writable: true, enumerable: true, configurable: true +}, { + restore: true }); let keys = Reflect.ownKeys(Array_unscopables); // FIXME: Once bug 1826643 is fixed, change this test so that all // the keys are in alphabetical order -let expectedKeys = ["at", - "copyWithin", - "entries", - "fill", - "find", - "findIndex", - "findLast", - "findLastIndex", - "flat", - "flatMap", - "includes", - "keys", - "toReversed", - "toSorted", - "toSpliced", - "values"]; +let expectedKeys = [ + "at", + "copyWithin", + "entries", + "fill", + "find", + "findIndex", + "findLast", + "findLastIndex", + "flat", + "flatMap", + "includes", + "keys", + "toReversed", + "toSorted", + "toSpliced", + "values" +]; -assert.deepEqual(keys, expectedKeys); +assert.compareArray(keys, expectedKeys); for (let key of keys) assert.sameValue(Array_unscopables[key], true); diff --git a/test/staging/sm/Function/Function-prototype.js b/test/staging/sm/Function/Function-prototype.js index adb786d1c7..8d7ac18add 100644 --- a/test/staging/sm/Function/Function-prototype.js +++ b/test/staging/sm/Function/Function-prototype.js @@ -2,19 +2,18 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [deepEqual.js] +includes: [propertyHelper.js] flags: - noStrict description: | pending esid: pending ---*/ -var desc = Object.getOwnPropertyDescriptor(Function.prototype, "length"); -assert.deepEqual(desc, + +verifyProperty(Function.prototype, "length", {value: 0, writable: false, enumerable: false, configurable: true}); assert.sameValue(Function.prototype.prototype, undefined); assert.sameValue(Function.prototype.callee, undefined); assert.throws(TypeError, () => Function.prototype.caller); assert.throws(TypeError, () => Function.prototype.arguments); - diff --git a/test/staging/sm/Function/throw-type-error.js b/test/staging/sm/Function/throw-type-error.js index db7df749da..a777faf78a 100644 --- a/test/staging/sm/Function/throw-type-error.js +++ b/test/staging/sm/Function/throw-type-error.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [deepEqual.js] +includes: [propertyHelper.js] flags: - noStrict description: | @@ -17,9 +17,8 @@ const ThrowTypeError = function(){ return Object.getOwnPropertyDescriptor(arguments, "callee").get; }(); -assert.deepEqual(Object.getOwnPropertyDescriptor(ThrowTypeError, "length"), { +verifyProperty(ThrowTypeError, "length", { value: 0, writable: false, enumerable: false, configurable: false }); assert.sameValue(Object.isFrozen(ThrowTypeError), true); - diff --git a/test/staging/sm/Set/difference.js b/test/staging/sm/Set/difference.js index 41abb0d959..aa151a6ea1 100644 --- a/test/staging/sm/Set/difference.js +++ b/test/staging/sm/Set/difference.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-Set-shell.js, deepEqual.js, compareArray.js] +includes: [sm/non262-Set-shell.js, compareArray.js, propertyHelper.js] flags: - noStrict description: | @@ -11,10 +11,10 @@ esid: pending ---*/ assert.sameValue(typeof Set.prototype.difference, "function"); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.difference, "length"), { +verifyProperty(Set.prototype.difference, "length", { value: 1, writable: false, enumerable: false, configurable: true, }); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.difference, "name"), { +verifyProperty(Set.prototype.difference, "name", { value: "difference", writable: false, enumerable: false, configurable: true, }); diff --git a/test/staging/sm/Set/intersection.js b/test/staging/sm/Set/intersection.js index 458bf1bfb6..15731efb78 100644 --- a/test/staging/sm/Set/intersection.js +++ b/test/staging/sm/Set/intersection.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-Set-shell.js, deepEqual.js, compareArray.js] +includes: [sm/non262-Set-shell.js, compareArray.js, propertyHelper.js] flags: - noStrict description: | @@ -11,10 +11,10 @@ esid: pending ---*/ assert.sameValue(typeof Set.prototype.intersection, "function"); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.intersection, "length"), { +verifyProperty(Set.prototype.intersection, "length", { value: 1, writable: false, enumerable: false, configurable: true, }); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.intersection, "name"), { +verifyProperty(Set.prototype.intersection, "name", { value: "intersection", writable: false, enumerable: false, configurable: true, }); diff --git a/test/staging/sm/Set/is-disjoint-from.js b/test/staging/sm/Set/is-disjoint-from.js index c0be35817a..fef8423197 100644 --- a/test/staging/sm/Set/is-disjoint-from.js +++ b/test/staging/sm/Set/is-disjoint-from.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-Set-shell.js, deepEqual.js, compareArray.js] +includes: [sm/non262-Set-shell.js, compareArray.js, propertyHelper.js] flags: - noStrict description: | @@ -11,10 +11,10 @@ esid: pending ---*/ assert.sameValue(typeof Set.prototype.isDisjointFrom, "function"); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.isDisjointFrom, "length"), { +verifyProperty(Set.prototype.isDisjointFrom, "length", { value: 1, writable: false, enumerable: false, configurable: true, }); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.isDisjointFrom, "name"), { +verifyProperty(Set.prototype.isDisjointFrom, "name", { value: "isDisjointFrom", writable: false, enumerable: false, configurable: true, }); diff --git a/test/staging/sm/Set/is-subset-of.js b/test/staging/sm/Set/is-subset-of.js index cdbf5e5c98..c5bd5e654b 100644 --- a/test/staging/sm/Set/is-subset-of.js +++ b/test/staging/sm/Set/is-subset-of.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-Set-shell.js, deepEqual.js, compareArray.js] +includes: [sm/non262-Set-shell.js, compareArray.js, propertyHelper.js] flags: - noStrict description: | @@ -11,10 +11,10 @@ esid: pending ---*/ assert.sameValue(typeof Set.prototype.isSubsetOf, "function"); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.isSubsetOf, "length"), { +verifyProperty(Set.prototype.isSubsetOf, "length", { value: 1, writable: false, enumerable: false, configurable: true, }); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.isSubsetOf, "name"), { +verifyProperty(Set.prototype.isSubsetOf, "name", { value: "isSubsetOf", writable: false, enumerable: false, configurable: true, }); diff --git a/test/staging/sm/Set/is-superset-of.js b/test/staging/sm/Set/is-superset-of.js index b391a1cf43..fdb29b9456 100644 --- a/test/staging/sm/Set/is-superset-of.js +++ b/test/staging/sm/Set/is-superset-of.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-Set-shell.js, deepEqual.js, compareArray.js] +includes: [sm/non262-Set-shell.js, compareArray.js, propertyHelper.js] flags: - noStrict description: | @@ -11,10 +11,10 @@ esid: pending ---*/ assert.sameValue(typeof Set.prototype.isSupersetOf, "function"); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.isSupersetOf, "length"), { +verifyProperty(Set.prototype.isSupersetOf, "length", { value: 1, writable: false, enumerable: false, configurable: true, }); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.isSupersetOf, "name"), { +verifyProperty(Set.prototype.isSupersetOf, "name", { value: "isSupersetOf", writable: false, enumerable: false, configurable: true, }); diff --git a/test/staging/sm/Set/symmetric-difference.js b/test/staging/sm/Set/symmetric-difference.js index 1d39d3adf1..78b14573b8 100644 --- a/test/staging/sm/Set/symmetric-difference.js +++ b/test/staging/sm/Set/symmetric-difference.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-Set-shell.js, deepEqual.js, compareArray.js] +includes: [sm/non262-Set-shell.js, compareArray.js, propertyHelper.js] flags: - noStrict description: | @@ -11,10 +11,10 @@ esid: pending ---*/ assert.sameValue(typeof Set.prototype.symmetricDifference, "function"); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.symmetricDifference, "length"), { +verifyProperty(Set.prototype.symmetricDifference, "length", { value: 1, writable: false, enumerable: false, configurable: true, }); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.symmetricDifference, "name"), { +verifyProperty(Set.prototype.symmetricDifference, "name", { value: "symmetricDifference", writable: false, enumerable: false, configurable: true, }); diff --git a/test/staging/sm/Set/union.js b/test/staging/sm/Set/union.js index 678520f27c..c00bb1e3d5 100644 --- a/test/staging/sm/Set/union.js +++ b/test/staging/sm/Set/union.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-Set-shell.js, deepEqual.js, compareArray.js] +includes: [sm/non262-Set-shell.js, compareArray.js, propertyHelper.js] flags: - noStrict description: | @@ -11,10 +11,10 @@ esid: pending ---*/ assert.sameValue(typeof Set.prototype.union, "function"); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.union, "length"), { +verifyProperty(Set.prototype.union, "length", { value: 1, writable: false, enumerable: false, configurable: true, }); -assert.deepEqual(Object.getOwnPropertyDescriptor(Set.prototype.union, "name"), { +verifyProperty(Set.prototype.union, "name", { value: "union", writable: false, enumerable: false, configurable: true, }); diff --git a/test/staging/sm/TypedArray/set.js b/test/staging/sm/TypedArray/set.js index d0ee394534..73bd179250 100644 --- a/test/staging/sm/TypedArray/set.js +++ b/test/staging/sm/TypedArray/set.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-TypedArray-shell.js, deepEqual.js] +includes: [sm/non262-TypedArray-shell.js, propertyHelper.js] flags: - noStrict description: | @@ -18,13 +18,14 @@ assert.sameValue(typeof TypedArrayPrototype.set, "function"); // The concrete TypedArray prototypes do not have an own "set" property. assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("set")), true); -assert.deepEqual(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "set"), { +verifyProperty(TypedArrayPrototype, "set", { value: TypedArrayPrototype.set, writable: true, enumerable: false, configurable: true, +}, { + restore: true }); assert.sameValue(TypedArrayPrototype.set.name, "set"); assert.sameValue(TypedArrayPrototype.set.length, 1); - diff --git a/test/staging/sm/TypedArray/toLocaleString.js b/test/staging/sm/TypedArray/toLocaleString.js index 67e48b47dc..406a161875 100644 --- a/test/staging/sm/TypedArray/toLocaleString.js +++ b/test/staging/sm/TypedArray/toLocaleString.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-TypedArray-shell.js, deepEqual.js] +includes: [sm/non262-TypedArray-shell.js, propertyHelper.js] flags: - noStrict description: | @@ -21,11 +21,13 @@ assert.sameValue(TypedArrayPrototype.toLocaleString === Array.prototype.toLocale // The concrete TypedArray prototypes do not have an own "toLocaleString" property. assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toLocaleString")), true); -assert.deepEqual(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "toLocaleString"), { +verifyProperty(TypedArrayPrototype, "toLocaleString", { value: TypedArrayPrototype.toLocaleString, writable: true, enumerable: false, configurable: true, +}, { + restore: true }); assert.sameValue(TypedArrayPrototype.toLocaleString.name, "toLocaleString"); @@ -86,4 +88,3 @@ for (let constructor of anyTypedArrayConstructors) { assert.sameValue(called, true); } Number.prototype.toLocaleString = originalNumberToLocaleString; - diff --git a/test/staging/sm/TypedArray/toString.js b/test/staging/sm/TypedArray/toString.js index 41ae8708c4..d8cb4e04f3 100644 --- a/test/staging/sm/TypedArray/toString.js +++ b/test/staging/sm/TypedArray/toString.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262-TypedArray-shell.js, deepEqual.js] +includes: [sm/non262-TypedArray-shell.js, propertyHelper.js] flags: - noStrict description: | @@ -20,11 +20,13 @@ assert.sameValue(TypedArrayPrototype.toString, Array.prototype.toString); // The concrete TypedArray prototypes do not have an own "toString" property. assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toString")), true); -assert.deepEqual(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "toString"), { +verifyProperty(TypedArrayPrototype, "toString", { value: TypedArrayPrototype.toString, writable: true, enumerable: false, configurable: true, +}, { + restore: true }); for (let constructor of anyTypedArrayConstructors) { @@ -79,4 +81,3 @@ for (let constructor of anyTypedArrayConstructors) { let {array, expected} = testCases[constructor.name]; assert.sameValue(new constructor(array).toString(), expected); } -