Skip to content

Commit

Permalink
assert,util: correct comparison when both contain same reference
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com>
PR-URL: #53431
Refs: #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>
  • Loading branch information
2 people authored and marco-ippolito committed Jul 19, 2024
1 parent cac300e commit 76fd0ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit 76fd0ea

Please sign in to comment.