mirror of
https://github.com/tc39/test262.git
synced 2025-07-31 01:44:54 +02:00
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:
parent
43670a1912
commit
2497ed0ae9
@ -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. */
|
/** Make an iterator with a return method. */
|
||||||
globalThis.makeIterator = function makeIterator(overrides) {
|
globalThis.makeIterator = function makeIterator(overrides) {
|
||||||
var throwMethod;
|
var throwMethod;
|
||||||
|
@ -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:
|
flags:
|
||||||
- noStrict
|
- noStrict
|
||||||
description: |
|
description: |
|
||||||
@ -28,31 +28,10 @@ var o = Object.defineProperties({}, properties);
|
|||||||
|
|
||||||
Object.freeze(o);
|
Object.freeze(o);
|
||||||
|
|
||||||
function getPropertyOf(obj) {
|
verifyProperty(o, "all", { value: 1, writable: false, enumerable: true, configurable: false });
|
||||||
return function (prop) {
|
verifyProperty(o, "readOnly", { value: 2, writable: false, enumerable: true, configurable: false });
|
||||||
return Object.getOwnPropertyDescriptor(obj, prop);
|
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 });
|
||||||
assert.sameValue(deepEqual(Object.getOwnPropertyDescriptor(o, 'all'),
|
verifyProperty(o, "getandset", { get: getme, set: setme, enumerable: true, configurable: false });
|
||||||
{ 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);
|
|
||||||
|
|
||||||
|
@ -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:
|
flags:
|
||||||
- noStrict
|
- noStrict
|
||||||
description: |
|
description: |
|
||||||
@ -33,55 +33,12 @@ function strict1(out)
|
|||||||
|
|
||||||
out.array = null;
|
out.array = null;
|
||||||
nonStrict1(out);
|
nonStrict1(out);
|
||||||
assert.sameValue(deepEqual(out.array, [1, 2, 3]), true);
|
assert.compareArray(out.array, [1, 2, 3]);
|
||||||
|
|
||||||
out.array = null;
|
out.array = null;
|
||||||
try
|
|
||||||
{
|
assert.throws(TypeError, function() {
|
||||||
strict1(out);
|
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:
|
assert.compareArray(out.array, [1, 2, 3]);
|
||||||
// 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");
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user