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
doc: document asserts Weak(Map|Set) behavior #18248
Right now it is not documentated that WeakMap entries are not
Affected core subsystem(s)
Please note that this applies to both:
I personally also think that WeakMap and WeakSet should be treated as any other regular object. The only reason why I would be OK with throwing is that many people seem to be confused about the behavior and that might clarify it right away. It might of course also lead to some trouble.
Documenting is definitely something we should land in 8 and 9.
I disagree, people look at the docs when they see an exception or undocumented behavior. However this will be mostly silent. I compare two things that I expect to contain the same keys, but they are not and the test will not fail. Comparing the attached properties of a WeakMap is definitely not the behavior a user is looking for.
this situation is similar to
However, util.isDeepStrictEqual returns
If we define
but i feel it is not """strict equal""" ...
According to the api docs,
If we follow the sentence, I think we would be better to return
If we could change this function behavior drastically, throw an Error on uncomparable object like (NaN, WeakMap, WeakSet).
Anyway, we need to add some documentation for this function.
@yosuke-furukawa I am not sure in what way
And I already tried to point out that using
referenced this pull request
Jan 22, 2018
Ok, it still seems highly controversial what to do and what not. The only relatively clear thing is that always returning false / always failing the check in case
So either we should document the behavior or throw.
@nodejs/tsc I think this is something for your agenda. Please read the arguments closely.
But we could change this function behavior to truly
firstly I think this is the better behavior than current behavior. Because most JS engineer using WeakMap and WeakSet know that they do not have a list API and those collections are depends on GC. WeakCollection has non-determinism. The strict compare is impossible, so false.
IMO It is not weird, cause WeakMap|Set are special collection about comparison, we need special handles.
This is a kind of type error. it means "we do not support WeakMap|WeakSet on this function".
Returning undefined is a compromised plan. It means "no answer (neither true nor false)".