Skip to content

Commit 92a1b67

Browse files
lib: update isDeepStrictEqual to support options and enhance strictness checks
1 parent 538186b commit 92a1b67

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/internal/util/comparisons.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ const {
127127
getOwnNonIndexProperties,
128128
} = internalBinding('util');
129129

130-
const kStrict = 1;
130+
const kStrict = 2;
131+
const kStrictWithoutPrototypes = 3;
131132
const kLoose = 0;
132-
const kPartial = 2;
133+
const kPartial = 1;
133134

134135
const kNoIterator = 0;
135136
const kIsArray = 1;
@@ -458,7 +459,7 @@ function keyCheck(val1, val2, mode, memos, iterationType, keys2) {
458459
}
459460
} else if (keys2.length !== (keys1 = ObjectKeys(val1)).length) {
460461
return false;
461-
} else if (mode === kStrict) {
462+
} else if (mode >= kStrict) {
462463
const symbolKeysA = getOwnSymbols(val1);
463464
if (symbolKeysA.length !== 0) {
464465
let count = 0;
@@ -1027,7 +1028,10 @@ module.exports = {
10271028
isDeepEqual(val1, val2) {
10281029
return detectCycles(val1, val2, kLoose);
10291030
},
1030-
isDeepStrictEqual(val1, val2) {
1031+
isDeepStrictEqual(val1, val2, options) {
1032+
if (options?.skipPrototypeComparison) {
1033+
return detectCycles(val1, val2, kStrictWithoutPrototypes);
1034+
}
10311035
return detectCycles(val1, val2, kStrict);
10321036
},
10331037
isPartialStrictEqual(val1, val2) {

lib/util.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,14 @@ module.exports = {
487487
isArray: deprecate(ArrayIsArray,
488488
'The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.',
489489
'DEP0044'),
490-
isDeepStrictEqual(a, b) {
490+
isDeepStrictEqual(a, b, options) {
491+
if (options !== undefined) {
492+
return require('internal/util/comparisons').isDeepStrictEqual(a, b, options);
493+
}
491494
if (internalDeepEqual === undefined) {
492-
internalDeepEqual = require('internal/util/comparisons')
493-
.isDeepStrictEqual;
495+
internalDeepEqual = require('internal/util/comparisons').isDeepStrictEqual;
494496
}
495-
return internalDeepEqual(a, b);
497+
return internalDeepEqual(a, b, options);
496498
},
497499
promisify,
498500
stripVTControlCharacters,

0 commit comments

Comments
 (0)