From 2497ed0ae9867e5e48e31855bf840b63bac74951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 30 Apr 2025 14:15:28 +0200 Subject: [PATCH] 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. --- harness/sm/non262-shell.js | 37 -------------------- test/staging/sm/object/15.2.3.9.js | 37 +++++--------------- test/staging/sm/strict/15.4.5.1.js | 55 ++++-------------------------- 3 files changed, 14 insertions(+), 115 deletions(-) diff --git a/harness/sm/non262-shell.js b/harness/sm/non262-shell.js index 11fa3f23d2..c73bb988a3 100644 --- a/harness/sm/non262-shell.js +++ b/harness/sm/non262-shell.js @@ -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; diff --git a/test/staging/sm/object/15.2.3.9.js b/test/staging/sm/object/15.2.3.9.js index 53247c0285..cd23029b0c 100644 --- a/test/staging/sm/object/15.2.3.9.js +++ b/test/staging/sm/object/15.2.3.9.js @@ -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 }); diff --git a/test/staging/sm/strict/15.4.5.1.js b/test/staging/sm/strict/15.4.5.1.js index 2fed2eae7b..af707f72d0 100644 --- a/test/staging/sm/strict/15.4.5.1.js +++ b/test/staging/sm/strict/15.4.5.1.js @@ -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]);