assert,util: fail promise comparison in deep equal checks · nodejs/node@7c9fbc1 · GitHub
Skip to content

Commit 7c9fbc1

Browse files
authored
assert,util: fail promise comparison in deep equal checks
It is impossible to look into the content of a promise and its state. This aligns the comparison with WeakMaps and WeakSets. Only reference equal promises will pass the check in the future. Fixes #55198 PR-URL: #59448 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent 8973589 commit 7c9fbc1

3 files changed

Lines changed: 43 additions & 21 deletions

File tree

doc/api/assert.md

Lines changed: 24 additions & 10 deletions

lib/internal/util/comparisons.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,23 @@ const types = require('internal/util/types');
9999
const {
100100
isAnyArrayBuffer,
101101
isArrayBufferView,
102+
isBigIntObject,
103+
isBooleanObject,
104+
isBoxedPrimitive,
105+
isCryptoKey,
102106
isDate,
107+
isFloat16Array,
108+
isFloat32Array,
109+
isFloat64Array,
110+
isKeyObject,
103111
isMap,
104-
isRegExp,
105-
isSet,
106112
isNativeError,
107-
isBoxedPrimitive,
108113
isNumberObject,
114+
isPromise,
115+
isRegExp,
116+
isSet,
109117
isStringObject,
110-
isBooleanObject,
111-
isBigIntObject,
112118
isSymbolObject,
113-
isFloat16Array,
114-
isFloat32Array,
115-
isFloat64Array,
116-
isKeyObject,
117-
isCryptoKey,
118119
isWeakMap,
119120
isWeakSet,
120121
} = types;
@@ -409,7 +410,7 @@ function objectComparisonStart(val1, val2, mode, memos) {
409410
) {
410411
return false;
411412
}
412-
} else if (isWeakMap(val1) || isWeakSet(val1)) {
413+
} else if (isWeakMap(val1) || isWeakSet(val1) || isPromise(val1)) {
413414
return false;
414415
}
415416

test/parallel/test-assert-deep.js

Lines changed: 7 additions & 0 deletions

0 commit comments

Comments
 (0)