Repository navigation
Console log WeakSet and WeakMap always empty #19001
Description
Activity
- addedutilIssues and PRs related to the built-in util module.Issues and PRs related to the built-in util module.docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.
on Feb 26, 2018 related to #18227
This is language related and it is just not possible to inspect
WeakSet/WeakMap.We did not yet come to a conclusion how to handle this on the long term and I am going to write a summary of pro / con some time this week.
@anantoghosh what kind of warning would you expect? I can not think of a good way to display a warning in this case.
what kind of warning would you expect?
Maybe a message after using console.log()
"WARNING: WeakSet/WeakMap will always appear empty. See link"Although simply mentioning this in the documentation would have been fine.
Currently, trying to google for this issue does not reveal any information.This is language related and it is just not possible to inspect WeakSet / WeakMap.
At least w.r.t. inspection it should be possible to add a V8 API to peek into them.
In fact, it already exists but not in any official capacity:
$ ./out/Release/node --allow_natives_syntax > var m = new WeakMap() undefined > m.set({x:1}, true); WeakMap {} > %GetWeakMapEntries(m, 99) [ { x: 1 }, true ]@bnoordhuis that is a very interesting point and opens new possibilities for the other discussion as well. The question for me though is: can this be implemented independent of the engine?
Support for inspecting WeakMap and WeakSet was added in master. The
showHiddenoption must be set to true and otherwise it will tell that the items were not inspected.Reacted by Ananto Ghosh, Muhammad Mufid Utomo, xyz 123 and ComplexeExquis
Currently trying to console.log WeakSet or WeakMap will always display as empty.
I believe I understand why logging them does not work, but node should display a warning and/or should document this behavior.