assert: fix deepEqual inconsistencies
PR-URL: https://github.com/nodejs/node/pull/14491 Fixes: https://github.com/nodejs/node/issues/14441 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
8a53897325
commit
a8149c4799
@ -271,8 +271,15 @@ function innerDeepEqual(actual, expected, strict, memos) {
|
|||||||
position: 0
|
position: 0
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
if (memos.actual.has(actual)) {
|
// We prevent up to two map.has(x) calls by directly retrieving the value
|
||||||
return memos.actual.get(actual) === memos.expected.get(expected);
|
// and checking for undefined. The map can only contain numbers, so it is
|
||||||
|
// safe to check for undefined only.
|
||||||
|
const expectedMemoA = memos.actual.get(actual);
|
||||||
|
if (expectedMemoA !== undefined) {
|
||||||
|
const expectedMemoB = memos.expected.get(expected);
|
||||||
|
if (expectedMemoB !== undefined) {
|
||||||
|
return expectedMemoA === expectedMemoB;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memos.position++;
|
memos.position++;
|
||||||
}
|
}
|
||||||
|
@ -303,6 +303,26 @@ assertOnlyDeepEqual(
|
|||||||
new Set([undefined])
|
new Set([undefined])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Circular structures
|
||||||
|
{
|
||||||
|
const a = {};
|
||||||
|
const b = {};
|
||||||
|
a.a = a;
|
||||||
|
b.a = {};
|
||||||
|
b.a.a = a;
|
||||||
|
assertDeepAndStrictEqual(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const a = new Set();
|
||||||
|
const b = new Set();
|
||||||
|
const c = new Set();
|
||||||
|
a.add(a);
|
||||||
|
b.add(b);
|
||||||
|
c.add(a);
|
||||||
|
assertDeepAndStrictEqual(b, c);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const values = [
|
const values = [
|
||||||
123,
|
123,
|
||||||
|
@ -578,8 +578,8 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
|
|||||||
|
|
||||||
const h = { ref: g };
|
const h = { ref: g };
|
||||||
|
|
||||||
a.throws(makeBlock(a.deepEqual, f, h), /AssertionError/);
|
a.doesNotThrow(makeBlock(a.deepEqual, f, h));
|
||||||
a.throws(makeBlock(a.deepStrictEqual, f, h), /AssertionError/);
|
a.doesNotThrow(makeBlock(a.deepStrictEqual, f, h));
|
||||||
}
|
}
|
||||||
// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
|
// GH-7178. Ensure reflexivity of deepEqual with `arguments` objects.
|
||||||
const args = (function() { return arguments; })();
|
const args = (function() { return arguments; })();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user