Uh oh!
There was an error while loading. Please reload this page.
util: improve Weak(Map|Set) support - #19259
Conversation
BridgeAR
commented
Mar 9, 2018
TimothyGu
left a comment
There was a problem hiding this comment.
Strong 👎 on being able to introspect WeakMaps and WeakSets, especially in assert, since the behavior of weak collections depends on GC and it is not good developer experience to asserting on something whose result is not guaranteed/deterministic.
I’m unhappy with adding support to util, but I can see the value of doing so.
BridgeAR
commented
Mar 9, 2018
@TimothyGu I am aware that this is GC dependend but from the former discussion this was a option that we did not discuss so far and to me it felt like the best option possible. When choosing between any alternatives and this, I think this is the best way to handle it. |
BridgeAR
commented
Mar 9, 2018
I can add a warning next to it: when using |
joyeecheung
commented
Mar 10, 2018
I can see the value of adding it to until.inspect for debugging purposes, but -1 to adding assert support as well. |
-1 to assert, +1 to util.inspect @hashseed do you know if there are any plans to add the apis we have in internal/v8 like |
BridgeAR
commented
Mar 11, 2018
Ok, I am going to remove the assert part for now. I am also fine with removing the inspect part again. What is the general opinion here: should it better stay or do you think it should be removed as well? I actually came up with the idea about comparing them after our discussion how to handle Weak(Map/Set) and when looking at the alternatives, this seemed to be the best way to go. Especially as there were people having strong opinions about any of the former ideas. @joyeecheung@TimothyGu@devsnek what do you personally think is the best way to progress there? I actually wrote the PR instead of writing a summary of the ideas but I guess that is the best to do and then to further see where that leads to? |
i'm +1 on inspect, i think its been made pretty clear to users at this point that util.inspect output isn't something to rely on, and its honestly just useful to be able to debug the contents of weakmaps/sets |
2e16308 to
4f08813CompareBridgeAR
commented
Mar 11, 2018
I just removed the third commit about the |
BridgeAR
commented
Mar 11, 2018
yosuke-furukawa
commented
Mar 13, 2018
I am also -1, same opinion of @TimothyGu . |
targos
commented
Mar 13, 2018
What about an option similar to |
yosuke-furukawa
commented
Mar 13, 2018
BridgeAR
commented
Mar 14, 2018
Ping @TimothyGu |
4f08813 to
249f427CompareBridgeAR
commented
Mar 21, 2018
Rebased due to conflicts. I also dismissed the stale review. @TimothyGu please have another look! |
There was a problem hiding this comment.
Nit: the corresponding code in formatArray() is:
Lines 771 to 772 in 982e3bd
We could do that instead.
There was a problem hiding this comment.
I do not see how that is possible. We have to explicitly enter a maximum number of entries we want. This is a upper bound and to be able to show that there are more entries, I actually get one more than requested with the regular maximum. We would have to get all entries each time (by passing through e.g. the maximum number of entries a Array may have) but that would be a significant overhead.
There was a problem hiding this comment.
I could get two more items to show "1 more item" and "more items".
There was a problem hiding this comment.
I don't believe we have used JSDoc annotations anywhere else in the code base. Maybe just use prose instead? (I.e., replace this comment block with just Clone the provided Map Iterator.)
Speaking of documentation, I think a general comment for this entire file would be good. Specifically:
- what it is, where these functions are used, maybe a half-sentence intro on V8's natives syntax, and
- how it is special compared to rest of the code base (loaded before anything else with a special flag that allows natives syntax).
BridgeAR
commented
Mar 22, 2018
Just as a heads up: I thought about the current implementation again and I actually plan on using @targos suggestion to only show the |
1) So far extra keys on an (Set|Map)Iterator were ignored. Those will now be visible. 2) Improve the performance of showing (Set|Map)Iterator by using the cloned iterator instead of copying all entries first. 3) So far the output was strictly limited to up to 100 entries. The limit will now depend on `maxArrayLength` instead (that default is set to 100 as well) and the output indicates that more entries exist than visible.
249f427 to
9a4c2f7CompareThis adds support for WeakMap and WeakSet entries in `util.inspect`. The output is limited to a maximum entry length of `maxArrayLength`. Fixes: nodejs#19001
9a4c2f7 to
f1e0752CompareBridgeAR
commented
Mar 24, 2018
Comments addressed. I also updated the docs added a note about the inspection being unreliable. PTAL. |
1) So far extra keys on an (Set|Map)Iterator were ignored. Those will now be visible. 2) Improve the performance of showing (Set|Map)Iterator by using the cloned iterator instead of copying all entries first. 3) So far the output was strictly limited to up to 100 entries. The limit will now depend on `maxArrayLength` instead (that default is set to 100 as well) and the output indicates that more entries exist than visible. PR-URL: nodejs#19259 Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This adds support for WeakMap and WeakSet entries in `util.inspect`. The output is limited to a maximum entry length of `maxArrayLength`. PR-URL: nodejs#19259Fixes: nodejs#19001: Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>

This improves our
Weak(Map|Set)support significantly.util: improve iterator inspect outpututil: show Weak(Set|Map) entries in inspect(Fixes: Console log WeakSet and WeakMap always empty #19001):3. commit: `util,assert: improve Weak(Map|Set) support` (Fixes: #18227):I would like to rework the
maxArrayLengthand used that as limiting factor. I would like to get opinions about that.I am not certain what this should be when it comes to semver. For me it feels like a semver-minor. Other opinions?
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes