Prefer verifyProperty over assert.deepEqual when comparing property descriptors

This commit is contained in:
André Bargull 2025-04-30 14:16:08 +02:00 committed by Philip Chimento
parent 69e5cd3607
commit 5853b56f6e
13 changed files with 64 additions and 59 deletions

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
includes: [deepEqual.js] includes: [compareArray.js, propertyHelper.js]
flags: flags:
- noStrict - noStrict
description: | description: |
@ -11,46 +11,50 @@ esid: pending
---*/ ---*/
let Array_unscopables = Array.prototype[Symbol.unscopables]; let Array_unscopables = Array.prototype[Symbol.unscopables];
let desc = Reflect.getOwnPropertyDescriptor(Array.prototype, Symbol.unscopables); verifyProperty(Array.prototype, Symbol.unscopables, {
assert.deepEqual(desc, {
value: Array_unscopables, value: Array_unscopables,
writable: false, writable: false,
enumerable: false, enumerable: false,
configurable: true configurable: true
}, {
restore: true
}); });
assert.sameValue(Reflect.getPrototypeOf(Array_unscopables), null); assert.sameValue(Reflect.getPrototypeOf(Array_unscopables), null);
let desc2 = Object.getOwnPropertyDescriptor(Array_unscopables, "values"); verifyProperty(Array_unscopables, "values", {
assert.deepEqual(desc2, {
value: true, value: true,
writable: true, writable: true,
enumerable: true, enumerable: true,
configurable: true configurable: true
}, {
restore: true
}); });
let keys = Reflect.ownKeys(Array_unscopables); let keys = Reflect.ownKeys(Array_unscopables);
// FIXME: Once bug 1826643 is fixed, change this test so that all // FIXME: Once bug 1826643 is fixed, change this test so that all
// the keys are in alphabetical order // the keys are in alphabetical order
let expectedKeys = ["at", let expectedKeys = [
"copyWithin", "at",
"entries", "copyWithin",
"fill", "entries",
"find", "fill",
"findIndex", "find",
"findLast", "findIndex",
"findLastIndex", "findLast",
"flat", "findLastIndex",
"flatMap", "flat",
"includes", "flatMap",
"keys", "includes",
"toReversed", "keys",
"toSorted", "toReversed",
"toSpliced", "toSorted",
"values"]; "toSpliced",
"values"
];
assert.deepEqual(keys, expectedKeys); assert.compareArray(keys, expectedKeys);
for (let key of keys) for (let key of keys)
assert.sameValue(Array_unscopables[key], true); assert.sameValue(Array_unscopables[key], true);

View File

@ -2,19 +2,18 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
includes: [deepEqual.js] includes: [propertyHelper.js]
flags: flags:
- noStrict - noStrict
description: | description: |
pending pending
esid: 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}); {value: 0, writable: false, enumerable: false, configurable: true});
assert.sameValue(Function.prototype.prototype, undefined); assert.sameValue(Function.prototype.prototype, undefined);
assert.sameValue(Function.prototype.callee, undefined); assert.sameValue(Function.prototype.callee, undefined);
assert.throws(TypeError, () => Function.prototype.caller); assert.throws(TypeError, () => Function.prototype.caller);
assert.throws(TypeError, () => Function.prototype.arguments); assert.throws(TypeError, () => Function.prototype.arguments);

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
includes: [deepEqual.js] includes: [propertyHelper.js]
flags: flags:
- noStrict - noStrict
description: | description: |
@ -17,9 +17,8 @@ const ThrowTypeError = function(){
return Object.getOwnPropertyDescriptor(arguments, "callee").get; return Object.getOwnPropertyDescriptor(arguments, "callee").get;
}(); }();
assert.deepEqual(Object.getOwnPropertyDescriptor(ThrowTypeError, "length"), { verifyProperty(ThrowTypeError, "length", {
value: 0, writable: false, enumerable: false, configurable: false value: 0, writable: false, enumerable: false, configurable: false
}); });
assert.sameValue(Object.isFrozen(ThrowTypeError), true); assert.sameValue(Object.isFrozen(ThrowTypeError), true);

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -11,10 +11,10 @@ esid: pending
---*/ ---*/
assert.sameValue(typeof Set.prototype.difference, "function"); 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, 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, value: "difference", writable: false, enumerable: false, configurable: true,
}); });

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -11,10 +11,10 @@ esid: pending
---*/ ---*/
assert.sameValue(typeof Set.prototype.intersection, "function"); 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, 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, value: "intersection", writable: false, enumerable: false, configurable: true,
}); });

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -11,10 +11,10 @@ esid: pending
---*/ ---*/
assert.sameValue(typeof Set.prototype.isDisjointFrom, "function"); 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, 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, value: "isDisjointFrom", writable: false, enumerable: false, configurable: true,
}); });

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -11,10 +11,10 @@ esid: pending
---*/ ---*/
assert.sameValue(typeof Set.prototype.isSubsetOf, "function"); 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, 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, value: "isSubsetOf", writable: false, enumerable: false, configurable: true,
}); });

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -11,10 +11,10 @@ esid: pending
---*/ ---*/
assert.sameValue(typeof Set.prototype.isSupersetOf, "function"); 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, 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, value: "isSupersetOf", writable: false, enumerable: false, configurable: true,
}); });

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -11,10 +11,10 @@ esid: pending
---*/ ---*/
assert.sameValue(typeof Set.prototype.symmetricDifference, "function"); 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, 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, value: "symmetricDifference", writable: false, enumerable: false, configurable: true,
}); });

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -11,10 +11,10 @@ esid: pending
---*/ ---*/
assert.sameValue(typeof Set.prototype.union, "function"); 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, 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, value: "union", writable: false, enumerable: false, configurable: true,
}); });

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -18,13 +18,14 @@ assert.sameValue(typeof TypedArrayPrototype.set, "function");
// The concrete TypedArray prototypes do not have an own "set" property. // The concrete TypedArray prototypes do not have an own "set" property.
assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("set")), true); assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("set")), true);
assert.deepEqual(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "set"), { verifyProperty(TypedArrayPrototype, "set", {
value: TypedArrayPrototype.set, value: TypedArrayPrototype.set,
writable: true, writable: true,
enumerable: false, enumerable: false,
configurable: true, configurable: true,
}, {
restore: true
}); });
assert.sameValue(TypedArrayPrototype.set.name, "set"); assert.sameValue(TypedArrayPrototype.set.name, "set");
assert.sameValue(TypedArrayPrototype.set.length, 1); assert.sameValue(TypedArrayPrototype.set.length, 1);

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -21,11 +21,13 @@ assert.sameValue(TypedArrayPrototype.toLocaleString === Array.prototype.toLocale
// The concrete TypedArray prototypes do not have an own "toLocaleString" property. // The concrete TypedArray prototypes do not have an own "toLocaleString" property.
assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toLocaleString")), true); assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toLocaleString")), true);
assert.deepEqual(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "toLocaleString"), { verifyProperty(TypedArrayPrototype, "toLocaleString", {
value: TypedArrayPrototype.toLocaleString, value: TypedArrayPrototype.toLocaleString,
writable: true, writable: true,
enumerable: false, enumerable: false,
configurable: true, configurable: true,
}, {
restore: true
}); });
assert.sameValue(TypedArrayPrototype.toLocaleString.name, "toLocaleString"); assert.sameValue(TypedArrayPrototype.toLocaleString.name, "toLocaleString");
@ -86,4 +88,3 @@ for (let constructor of anyTypedArrayConstructors) {
assert.sameValue(called, true); assert.sameValue(called, true);
} }
Number.prototype.toLocaleString = originalNumberToLocaleString; Number.prototype.toLocaleString = originalNumberToLocaleString;

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file. // 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: flags:
- noStrict - noStrict
description: | description: |
@ -20,11 +20,13 @@ assert.sameValue(TypedArrayPrototype.toString, Array.prototype.toString);
// The concrete TypedArray prototypes do not have an own "toString" property. // The concrete TypedArray prototypes do not have an own "toString" property.
assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toString")), true); assert.sameValue(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toString")), true);
assert.deepEqual(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "toString"), { verifyProperty(TypedArrayPrototype, "toString", {
value: TypedArrayPrototype.toString, value: TypedArrayPrototype.toString,
writable: true, writable: true,
enumerable: false, enumerable: false,
configurable: true, configurable: true,
}, {
restore: true
}); });
for (let constructor of anyTypedArrayConstructors) { for (let constructor of anyTypedArrayConstructors) {
@ -79,4 +81,3 @@ for (let constructor of anyTypedArrayConstructors) {
let {array, expected} = testCases[constructor.name]; let {array, expected} = testCases[constructor.name];
assert.sameValue(new constructor(array).toString(), expected); assert.sameValue(new constructor(array).toString(), expected);
} }