diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 9adffea09a14c5..905946fdee3f44 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -416,9 +416,7 @@ function mapMightHaveLoosePrim(a, b, prim, item, memo) { !innerDeepEqual(item, curB, false, memo)) { return false; } - const curA = a.get(altValue); - return curA === undefined && a.has(altValue) || - innerDeepEqual(item, curA, false, memo); + return !a.has(altValue) && innerDeepEqual(item, curB, false, memo); } function setEquiv(a, b, strict, memo) { @@ -560,11 +558,10 @@ function objEquiv(a, b, strict, keys, memos, iterationType) { } else { // Array is sparse. const keysA = objectKeys(a); - i++; for (; i < keysA.length; i++) { const key = keysA[i]; if (!hasOwnProperty(b, key) || - !innerDeepEqual(a[key], b[i], strict, memos)) { + !innerDeepEqual(a[key], b[key], strict, memos)) { return false; } } diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index ddbc5e78eafcaf..fc63d95f641b66 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -239,6 +239,7 @@ assertNotDeepOrStrict(new Set([1, 2, 3, 4]), new Set([1, 2, 3])); assertDeepAndStrictEqual(new Set(['1', '2', '3']), new Set(['1', '2', '3'])); assertDeepAndStrictEqual(new Set([[1, 2], [3, 4]]), new Set([[3, 4], [1, 2]])); assertNotDeepOrStrict(new Set([{ a: 0 }]), new Set([{ a: 1 }])); +assertNotDeepOrStrict(new Set([Symbol()]), new Set([Symbol()])); { const a = [ 1, 2 ]; @@ -394,6 +395,14 @@ assertOnlyDeepEqual( new Map([[1, {}]]), new Map([[true, {}]]) ); +assertOnlyDeepEqual( + new Map([[undefined, true]]), + new Map([[null, true]]) +); +assertNotDeepOrStrict( + new Map([[undefined, true]]), + new Map([[true, true]]) +); // GH-6416. Make sure circular refs don't throw. { @@ -563,9 +572,20 @@ assertOnlyDeepEqual( assertDeepAndStrictEqual(m3, m4); } -// Handle sparse arrays -assertDeepAndStrictEqual([1, , , 3], [1, , , 3]); -assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); +// Handle sparse arrays. +{ + assertDeepAndStrictEqual([1, , , 3], [1, , , 3]); + assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]); + const a = new Array(3); + const b = new Array(3); + a[2] = true; + b[1] = true; + assertNotDeepOrStrict(a, b); + b[2] = true; + assertNotDeepOrStrict(a, b); + a[0] = true; + assertNotDeepOrStrict(a, b); +} // Handle different error messages { @@ -617,6 +637,8 @@ assertDeepAndStrictEqual(-0, -0); Object.defineProperty(obj2, Symbol(), { value: 1 }); assertOnlyDeepEqual(obj1, obj3); assertDeepAndStrictEqual(obj1, obj2); + obj2[Symbol()] = true; + assertOnlyDeepEqual(obj1, obj2); // TypedArrays have a fast path. Test for this as well. const a = new Uint8Array(4); const b = new Uint8Array(4);