Skip to content

Console log WeakSet and WeakMap always empty #19001

Description

@anantoghosh
  • 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.

Activity

  1. added
    utilIssues and PRs related to the built-in util module.
    docIssues and PRs related to Node.js documentation.
    on Feb 26, 2018
  2. devsnek commented on Feb 26, 2018

    @devsnek
    Member

    related to #18227

  3. BridgeAR commented on Feb 26, 2018

    @BridgeAR
    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.

  4. anantoghosh commented on Feb 26, 2018

    @anantoghosh
    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.

  5. bnoordhuis commented on Feb 26, 2018

    @bnoordhuis
    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 ]
    
  6. BridgeAR commented on Feb 26, 2018

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

  7. BridgeAR commented on Mar 25, 2018

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions