util: use proper circular reference checking
Circular references are conceptually nothing that should be checked for objects (or Sets or Maps) only, but applies to recursive structures in general, so move the seen
checks into a position where it is part of the recursion itself.
Fixes: #14758 (closed)
Tests are taken from https://github.com/nodejs/node/pull/14775
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines
Affected core subsystem(s)
util
@BridgeAR @TimothyGu @not-an-aardvark @aqrln