assert,util: correct comparison when both contain same reference

Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/53431
Refs: https://github.com/nodejs/node/issues/53423
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Daniel Lemire
2024-06-17 09:30:24 -04:00
committed by GitHub
parent 2333573f39
commit ee5c6b6604
2 changed files with 7 additions and 2 deletions

View File

@@ -502,8 +502,9 @@ function setEquiv(a, b, strict, memo) {
for (const val of b) {
// Primitive values have already been handled above.
if (typeof val === 'object' && val !== null) {
if (!setHasEqualElement(set, val, strict, memo))
if (!a.has(val) && !setHasEqualElement(set, val, strict, memo)) {
return false;
}
} else if (!strict &&
!a.has(val) &&
!setHasEqualElement(set, val, strict, memo)) {

View File

@@ -375,7 +375,11 @@ assertOnlyDeepEqual(
new Map([[undefined, null], ['+000', 2n]]),
new Map([[null, undefined], [false, '2']]),
);
const xarray = ['x'];
assertDeepAndStrictEqual(
new Set([xarray, ['y']]),
new Set([xarray, ['y']])
);
assertOnlyDeepEqual(
new Set([null, '', 1n, 5, 2n, false]),
new Set([undefined, 0, 5n, true, '2', '-000'])