Replace another deepEqual function from sm-staging

Replace the `deepEqual` function with `assert.compareArray` resp.
`verifyProperty`.

Also remove the second part of "sm/strict/15.4.5.1.js", because it's
terribly out-dated w.r.t. the SpiderMonkey implementation of Array
objects.
This commit is contained in:
André Bargull 2025-04-30 14:15:28 +02:00 committed by Ms2ger
parent 43670a1912
commit 2497ed0ae9
3 changed files with 14 additions and 115 deletions

View File

@ -42,43 +42,6 @@ allow_unused: True
};
};
/*
* Return true if A is equal to B, where equality on arrays and objects
* means that they have the same set of enumerable properties, the values
* of each property are deep_equal, and their 'length' properties are
* equal. Equality on other types is ==.
*/
globalThis.deepEqual = function deepEqual(a, b) {
if (typeof a != typeof b)
return false;
if (typeof a == 'object') {
var props = {};
// For every property of a, does b have that property with an equal value?
for (var prop in a) {
if (!deepEqual(a[prop], b[prop]))
return false;
props[prop] = true;
}
// Are all of b's properties present on a?
for (var prop in b)
if (!props[prop])
return false;
// length isn't enumerable, but we want to check it, too.
return a.length == b.length;
}
if (a === b) {
// Distinguish 0 from -0, even though they are ===.
return a !== 0 || 1/a === 1/b;
}
// Treat NaNs as equal, even though NaN !== NaN.
// NaNs are the only non-reflexive values, i.e., if a !== a, then a is a NaN.
// isNaN is broken: it converts its argument to number, so isNaN("foo") => true
return a !== a && b !== b;
}
/** Make an iterator with a return method. */
globalThis.makeIterator = function makeIterator(overrides) {
var throwMethod;

View File

@ -4,7 +4,7 @@
*/
/*---
includes: [sm/non262.js, sm/non262-shell.js, sm/non262-object-shell.js]
includes: [sm/non262.js, sm/non262-shell.js, sm/non262-object-shell.js, propertyHelper.js]
flags:
- noStrict
description: |
@ -28,31 +28,10 @@ var o = Object.defineProperties({}, properties);
Object.freeze(o);
function getPropertyOf(obj) {
return function (prop) {
return Object.getOwnPropertyDescriptor(obj, prop);
};
};
assert.sameValue(deepEqual(Object.getOwnPropertyDescriptor(o, 'all'),
{ value: 1, writable:false, enumerable:true, configurable:false }),
true);
assert.sameValue(deepEqual(Object.getOwnPropertyDescriptor(o, 'readOnly'),
{ value: 2, writable:false, enumerable:true, configurable:false }),
true);
assert.sameValue(deepEqual(Object.getOwnPropertyDescriptor(o, 'nonConfig'),
{ value: 3, writable:false, enumerable:true, configurable:false }),
true);
assert.sameValue(deepEqual(Object.getOwnPropertyDescriptor(o, 'none'),
{ value: 4, writable:false, enumerable:true, configurable:false }),
true);
assert.sameValue(deepEqual(Object.getOwnPropertyDescriptor(o, 'getter'),
{ get: getme, set: (void 0), enumerable:true, configurable:false }),
true);
assert.sameValue(deepEqual(Object.getOwnPropertyDescriptor(o, 'setter'),
{ set: setme, get: (void 0), enumerable:true, configurable:false }),
true);
assert.sameValue(deepEqual(Object.getOwnPropertyDescriptor(o, 'getandset'),
{ get: getme, set: setme, enumerable:true, configurable:false }),
true);
verifyProperty(o, "all", { value: 1, writable: false, enumerable: true, configurable: false });
verifyProperty(o, "readOnly", { value: 2, writable: false, enumerable: true, configurable: false });
verifyProperty(o, "nonConfig", { value: 3, writable: false, enumerable: true, configurable: false });
verifyProperty(o, "none", { value: 4, writable: false, enumerable: true, configurable: false });
verifyProperty(o, "getter", { get: getme, set: (void 0), enumerable: true, configurable: false });
verifyProperty(o, "setter", { set: setme, get: (void 0), enumerable: true, configurable: false });
verifyProperty(o, "getandset", { get: getme, set: setme, enumerable: true, configurable: false });

View File

@ -4,7 +4,7 @@
*/
/*---
includes: [sm/non262.js, sm/non262-strict-shell.js, sm/non262-shell.js]
includes: [sm/non262.js, sm/non262-strict-shell.js, sm/non262-shell.js, compareArray.js]
flags:
- noStrict
description: |
@ -33,55 +33,12 @@ function strict1(out)
out.array = null;
nonStrict1(out);
assert.sameValue(deepEqual(out.array, [1, 2, 3]), true);
assert.compareArray(out.array, [1, 2, 3]);
out.array = null;
try
{
assert.throws(TypeError, function() {
strict1(out);
throw "no error";
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, "expected TypeError, got " + e);
}
assert.sameValue(deepEqual(out.array, [1, 2, 3]), true);
});
// Internally, SpiderMonkey has two representations for arrays:
// fast-but-inflexible, and slow-but-flexible. Adding a non-index property
// to an array turns it into the latter. We should test on both kinds.
function addx(obj) {
obj.x = 5;
return obj;
}
function nonStrict2(out)
{
var a = out.array = addx(arr());
a.length = 2;
}
function strict2(out)
{
"use strict";
var a = out.array = addx(arr());
a.length = 2;
}
out.array = null;
nonStrict2(out);
assert.sameValue(deepEqual(out.array, addx([1, 2, 3])), true);
out.array = null;
try
{
strict2(out);
throw "no error";
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, "expected TypeError, got " + e);
}
assert.sameValue(deepEqual(out.array, addx([1, 2, 3])), true);
print("Tests complete");
assert.compareArray(out.array, [1, 2, 3]);