Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
util.isDeepStrictEqual would be better to return false to compare WeakMap/WeakSet #18227
util.isDeepStrictEqual always returns true when WeakMap/WeakSet comparison.
this is because WeakMap|WeakSet.prototype.valueOf always returns empty object.
However, this behavior (always return true) seems to be curious for me. I think it would be better to always return false.
referenced this issue
Jan 18, 2018
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.