Skip to content

Commit 4451460

Browse files
BridgeARdanielleadams
authored andcommitted
assert,util: fix commutativity edge case
Verify that both objects property keys are enumerable. Fixes: #37710 PR-URL: #37711 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 8666d77 commit 4451460

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/internal/util/comparisons.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function keyCheck(val1, val2, strict, memos, iterationType, aKeys) {
282282
// Cheap key test
283283
let i = 0;
284284
for (; i < aKeys.length; i++) {
285-
if (!ObjectPrototypeHasOwnProperty(val2, aKeys[i])) {
285+
if (!ObjectPrototypePropertyIsEnumerable(val2, aKeys[i])) {
286286
return false;
287287
}
288288
}

test/parallel/test-assert-deep.js

+10
Original file line numberDiff line numberDiff line change
@@ -1194,3 +1194,13 @@ assert.throws(
11941194
Object.setPrototypeOf(b, null);
11951195
assertNotDeepOrStrict(a, b, assert.AssertionError);
11961196
}
1197+
1198+
{
1199+
// Verify commutativity
1200+
// Regression test for https://github.com/nodejs/node/issues/37710
1201+
const a = { x: 1 };
1202+
const b = { y: 1 };
1203+
Object.defineProperty(b, 'x', { value: 1 });
1204+
1205+
assertNotDeepOrStrict(a, b);
1206+
}

0 commit comments

Comments
 (0)