Skip to content

Commit

Permalink
assert,util: revert recursive breaking change
Browse files Browse the repository at this point in the history
This commit is there to be reverted after merging. It makes it easy
to backport the overall PR and allows easy forward fixing.

Signed-off-by: Ruben Bridgewater <[email protected]>
PR-URL: #46593
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
BridgeAR authored and targos committed Mar 13, 2023
1 parent 7f85a2c commit e07c9b8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
12 changes: 2 additions & 10 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,6 @@ An alias of [`assert.ok()`][].
<!-- YAML
added: v0.1.21
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/46593
description: Recursion now stops when either side encounters a circular
reference.
- version: v18.0.0
pr-url: https://github.com/nodejs/node/pull/41020
description: Regular expressions lastIndex property is now compared as well.
Expand Down Expand Up @@ -621,7 +617,7 @@ are also recursively evaluated by the following rules.
* [Object wrappers][] are compared both as objects and unwrapped values.
* `Object` properties are compared unordered.
* [`Map`][] keys and [`Set`][] items are compared unordered.
* Recursion stops when both sides differ or either side encounters a circular
* Recursion stops when both sides differ or both sides encounter a circular
reference.
* Implementation does not test the [`[[Prototype]]`][prototype-spec] of
objects.
Expand Down Expand Up @@ -731,10 +727,6 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
<!-- YAML
added: v1.2.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/46593
description: Recursion now stops when either side encounters a circular
reference.
- version: v18.0.0
pr-url: https://github.com/nodejs/node/pull/41020
description: Regular expressions lastIndex property is now compared as well.
Expand Down Expand Up @@ -788,7 +780,7 @@ are recursively evaluated also by the following rules.
* [Object wrappers][] are compared both as objects and unwrapped values.
* `Object` properties are compared unordered.
* [`Map`][] keys and [`Set`][] items are compared unordered.
* Recursion stops when both sides differ or either side encounters a circular
* Recursion stops when both sides differ or both sides encounter a circular
reference.
* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. See
below for further details.
Expand Down
12 changes: 3 additions & 9 deletions lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,7 @@ function keyCheck(val1, val2, strict, memos, iterationType, aKeys) {
if (memos.set === undefined) {
if (memos.deep === false) {
if (memos.a === val1) {
return memos.b === val2;
}
if (memos.b === val2) {
return false;
if (memos.b === val2) return true;
}
memos.c = val1;
memos.d = val2;
Expand All @@ -366,12 +363,9 @@ function keyCheck(val1, val2, strict, memos, iterationType, aKeys) {

const originalSize = set.size;
set.add(val1);
if (originalSize === set.size) {
return set.has(val2);
}
set.add(val2);
if (originalSize === set.size - 1) {
return false;
if (originalSize === set.size) {
return true;
}

const areEq = objEquiv(val1, val2, strict, aKeys, memos, iterationType);
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ assertNotDeepOrStrict(
b.a = {};
b.a.a = a;

assertNotDeepOrStrict(a, b);
assertDeepAndStrictEqual(a, b);
}

{
Expand All @@ -435,7 +435,7 @@ assertNotDeepOrStrict(
b.a = b;
const c = {};
c.a = a;
assertNotDeepOrStrict(b, c);
assertDeepAndStrictEqual(b, c);
}

{
Expand All @@ -445,7 +445,7 @@ assertNotDeepOrStrict(
b.add(b);
const c = new Set();
c.add(a);
assertNotDeepOrStrict(b, c);
assertDeepAndStrictEqual(b, c);
}

// https://github.com/nodejs/node-v0.x-archive/pull/7178
Expand Down

0 comments on commit e07c9b8

Please sign in to comment.