Skip to content
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

Console log WeakSet and WeakMap always empty #19001

Closed
anantoghosh opened this issue Feb 26, 2018 · 6 comments
Closed

Console log WeakSet and WeakMap always empty #19001

anantoghosh opened this issue Feb 26, 2018 · 6 comments
Labels
doc Issues and PRs related to the documentations. util Issues and PRs related to the built-in util module.

Comments

@anantoghosh
Copy link

  • Version: 8.9.4
  • Platform: Windows 10 x64
  • Subsystem: powershell

Currently trying to console.log WeakSet or WeakMap will always display as empty.

var set = new WeakSet([{yes: true}]);
console.log(set); // logs WeakSet{}

var map = new WeakMap([[{yes: true}, true]]);
console.log(map); // logs WeakMap{}

I believe I understand why logging them does not work, but node should display a warning and/or should document this behavior.

@vsemozhetbyt vsemozhetbyt added util Issues and PRs related to the built-in util module. doc Issues and PRs related to the documentations. labels Feb 26, 2018
@devsnek
Copy link
Member

devsnek commented Feb 26, 2018

related to #18227

@BridgeAR
Copy link
Member

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.

@anantoghosh
Copy link
Author

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.

@bnoordhuis
Copy link
Member

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 ]

@BridgeAR
Copy link
Member

@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?

BridgeAR added a commit to BridgeAR/node that referenced this issue Mar 24, 2018
This adds support for WeakMap and WeakSet entries in `util.inspect`.
The output is limited to a maximum entry length of `maxArrayLength`.

Fixes: nodejs#19001
@BridgeAR
Copy link
Member

Support for inspecting WeakMap and WeakSet was added in master. The showHidden option must be set to true and otherwise it will tell that the items were not inspected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

5 participants