-
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 would be better to return false to compare WeakMap/WeakSet #18227
Comments
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 Weap(Map|Set) entries do not provide a way to compare them, they should just be ignored. The suggested change 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 |
hm, but I think WeakMap / WeakSet are not suitable to compare the equivalence, so we would be better to return false than true. Any WeakMap and WeakSet comparison always return Anyway, we would be better to add a note on documentation. |
@yosuke-furukawa I am definitely +1 for updating the docs! That should also apply to About being right or wrong: I think there is no definite right approach. Only one way we want to decide on. So far it was the one in place right now (maybe by chance) and I personally feel it is the better one. I feel returning |
Thank you, I will send another PR. @nodejs/collaborators |
Without reading the discussion (so I stay with intuition) - I'd expect |
I ask everyone to continue discussing this in #18248. Thanks :-) @benjamingr that would be a special handling of those and not be aligned with any other object. |
/cc @nodejs/tsc |
I'm +1 to what @benjamingr proposed above. |
I am 👍 to:
We should also document the current behvior in our current/lts release lines. |
I agree with @mcollina. |
After looking into this again, I changed my mind / I agree with the suggested behavior change. |
wow. I am surprised this issue is still open. |
The PR landed |
Version:
v9.4.0
Platform:
OSX, Linux, Windows
Subsystem:
N/A
util.isDeepStrictEqual always returns true when WeakMap/WeakSet comparison.
this is because WeakMap|WeakSet.prototype.valueOf always returns empty object.
I know WeakMap / WeakSet do not have an API to show the full content, and they depends on GC so those collection comparison is very difficult.
However, this behavior (always return true) seems to be curious for me. I think it would be better to always return false.
The text was updated successfully, but these errors were encountered: