assert: fix TypeError on deepStrictEqual with null Map key or Set member - #64449
assert: fix TypeError on deepStrictEqual with null Map key or Set member#64449semx wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64449 +/- ##
==========================================
- Coverage 92.37% 90.19% -2.18%
==========================================
Files 417 771 +354
Lines 188656 264911 +76255
Branches 28838 50318 +21480
==========================================
+ Hits 174268 238937 +64669
- Misses 14051 16925 +2874
- Partials 337 9049 +8712
🚀 New features to boost your workflow:
|
19f16d9 to
98843e4
Compare
|
First I think it needs a rebase? |
98843e4 to
cdd7206
Compare
|
Rebased onto current |
deepStrictEqual() and util.isDeepStrictEqual() threw "Cannot read properties of null (reading 'constructor')" instead of comparing when a Map key or Set member was null/undefined (or another primitive) and lined up against object-only keys/members in the other collection with an equal count. The primitive/null handling was gated behind an optimization that is skipped when the counts match, letting such keys reach objectComparisonStart, which dereferences `.constructor`. Resolve primitive and null keys/members directly in every case. Signed-off-by: semx <7532921+semx@users.noreply.github.com>
cdd7206 to
d28dd4e
Compare
|
Rebased onto current |
assert.deepStrictEqual()(andutil.isDeepStrictEqual()) throw aTypeErrorinstead of comparing when the firstMaphas anull(or other primitive) key that lines up against object-only keys in the other map:The same happens for an
undefinedkey.Sethas the identical problem for anull/undefinedmember (once the set is large enough to skip the small-set fast path):It only triggers in strict mode when the other collection's keys/members are all objects and their count equals the first collection's size.
Cause
In
mapObjectEquivandsetObjectEquiv(lib/internal/util/comparisons.js), primitive/nullkeys and members are resolved directly viab.has()/b.get(), but that handling was gated behindextraChecks(array.length !== a.size). When the counts match, the gate is skipped and the primitive/nullkey/member falls through toobjectComparisonStart, which dereferences.constructorand throws onnull/undefined.Fix
Handle primitive/
nullkeys and members unconditionally — they can only match by identity and can never match through the object comparator — so they are always resolved by direct lookup and never reachobjectComparisonStart. The collections above now compare as unequal (throwing anAssertionError, as expected) instead of throwing aTypeError. Object comparison is unchanged.Added regression cases (
nullandundefinedkeys/members, for bothMapandSet) totest/parallel/test-assert-deep.js.