Skip to content

Commit

Permalink
assert,util: fix commutativity edge case
Browse files Browse the repository at this point in the history
Verify that both objects property keys are enumerable.

Fixes: #37710

PR-URL: #37711
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
BridgeAR authored and danielleadams committed Mar 16, 2021
1 parent ea10155 commit ce8ac4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function keyCheck(val1, val2, strict, memos, iterationType, aKeys) {
// Cheap key test
let i = 0;
for (; i < aKeys.length; i++) {
if (!ObjectPrototypeHasOwnProperty(val2, aKeys[i])) {
if (!ObjectPrototypePropertyIsEnumerable(val2, aKeys[i])) {
return false;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,3 +1194,13 @@ assert.throws(
Object.setPrototypeOf(b, null);
assertNotDeepOrStrict(a, b, assert.AssertionError);
}

{
// Verify commutativity
// Regression test for https://github.com/nodejs/node/issues/37710
const a = { x: 1 };
const b = { y: 1 };
Object.defineProperty(b, 'x', { value: 1 });

assertNotDeepOrStrict(a, b);
}

0 comments on commit ce8ac4d

Please sign in to comment.