-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: isDeepStrictEqual always returns false to compare WeakMap/WeakSet #18228
util: isDeepStrictEqual always returns false to compare WeakMap/WeakSet #18228
Conversation
I thought about this before and I feel like the current way is the more correct one. The comparison always relies on what is possible to detect. Since This PR will also make it impossible to distinguish differences like these: const a = new WeakMap();
const b = new WeakMap();
const c = new WeakMap();
c.isClearlyDifferent = true;
util.isDeepStrictEqual(a, b); // => false even though they are indeed equal
util.isDeepStrictEqual(a, c); // => false without distinguishing this from the former check Because of those reasons I am -1 on landing this. |
I wonder if it wouldn't be better to throw when one of the arguments is a |
@jasnell hm... I am not certain if it is a good default behavior. But there is again no definite right or wrong. |
@jasnell my ideal is so, they are not comparable then throw an Error. First I feel JavaScript engineers do not like Error so much. so I implemented this behavior, but some core members thinks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated in #18248 (comment), I don't see why WeakMap and WeakSet should be treated differently from regular objects. Thus, -1 on this PR.
Right now it is not documentated that WeakMap entries are not compared. This might result in some confusion. This adds a note about the behavior in `assert.deepStrictEqual`. This documentation is also references in `util.isDeepStrictEqual`, so we do not have to document it again for that function as the underlying algorithm is the same. PR-URL: nodejs#18248 Fixes: nodejs#18228 Refs: nodejs#18228 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Right now it is not documentated that WeakMap entries are not compared. This might result in some confusion. This adds a note about the behavior in `assert.deepStrictEqual`. This documentation is also references in `util.isDeepStrictEqual`, so we do not have to document it again for that function as the underlying algorithm is the same. Backport-PR-URL: #19230 PR-URL: #18248 Fixes: #18228 Refs: #18228 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Right now it is not documentated that WeakMap entries are not compared. This might result in some confusion. This adds a note about the behavior in `assert.deepStrictEqual`. This documentation is also references in `util.isDeepStrictEqual`, so we do not have to document it again for that function as the underlying algorithm is the same. Backport-PR-URL: #19230 PR-URL: #18248 Fixes: #18228 Refs: #18228 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Right now it is not documentated that WeakMap entries are not compared. This might result in some confusion. This adds a note about the behavior in `assert.deepStrictEqual`. This documentation is also references in `util.isDeepStrictEqual`, so we do not have to document it again for that function as the underlying algorithm is the same. PR-URL: nodejs#18248 Fixes: nodejs#18228 Refs: nodejs#18228 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
solve #18227
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
util