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

util: improve display of iterators and weak entries #20961

Closed
wants to merge 1 commit into from

Conversation

BridgeAR
Copy link
Member

This is based on #20831 and I am going to rebase when that lands.

This patch changes the way how map iterator entries are displayed by
using the same style as for regular maps. It also improves iterators
in general as well as WeakSets and WeakMaps by indicating how many
entries in total exist. This information was not available before but
due to the new preview implementation it is now available and should
be displayed as well.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@BridgeAR BridgeAR requested a review from addaleax May 25, 2018 10:21
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. console Issues and PRs related to the console subsystem. util Issues and PRs related to the built-in util module. labels May 25, 2018
@BridgeAR
Copy link
Member Author

@BridgeAR BridgeAR added the blocked PRs that are blocked by other issues or PRs. label May 25, 2018
@TimothyGu
Copy link
Member

TimothyGu commented May 25, 2018

I like the change that adds the number of omitted items, but I feel inspection need to display what is to come from the iterator (i.e., what will be returned the next time one calls it.next()), not what is in the Map backing the iterator. As such I prefer the original array styling for .entries().

You might also want to do the same change to URLSearchParams.

@BridgeAR
Copy link
Member Author

@TimothyGu the styling for .entries() here is coherent with the way Chrome does it.

Currently there is no special handling for URLSearchParams but I can check how they currently look like.

@TimothyGu
Copy link
Member

TimothyGu commented May 25, 2018

I don't think we have an obligation to always follow what Chrome does, or at least I feel consistency in showing what's returned from .next() should be posited at a higher level of importance than copying Chrome's behavior.

URLSearchParams Iterator class has a custom inspection function, but I'd be more than okay to leave it out for another PR.

@BridgeAR
Copy link
Member Author

@TimothyGu I gave it another thought and I agree with you. As soon as this PR is unblocked, I'll rebase and undo the changes to the inspection of Map#entries.

@BridgeAR BridgeAR force-pushed the improve-util-inspect-output branch from 4b92277 to 61cd6ba Compare July 14, 2018 15:05
@BridgeAR BridgeAR removed the blocked PRs that are blocked by other issues or PRs. label Jul 14, 2018
@BridgeAR BridgeAR force-pushed the improve-util-inspect-output branch 2 times, most recently from fc452f9 to acd59c3 Compare July 16, 2018 12:59
This adds the number of not visible elements when inspecting iterators
while exceeding `maxArrayLength`.
It also fixes a edge case with `maxArrayLength` and the map.entries()
iterator. Now the whole entry will be visible instead of only the key
but not the value of the first entry.
Besides that it uses a slighly better algorithm that improves the
performance by skipping unnecessary steps.
@BridgeAR BridgeAR force-pushed the improve-util-inspect-output branch from acd59c3 to 591923b Compare July 16, 2018 13:11
@BridgeAR
Copy link
Member Author

CI https://ci.nodejs.org/job/node-test-pull-request/15894/

This is unblocked since the other PR landed.

@TimothyGu I switched it back to the array notation for map entries and fixes a edge case that prevented the whole first entry from being visible in combination with maxArrayLength.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Are you confident in this being a patch?

@BridgeAR
Copy link
Member Author

BridgeAR commented Jul 16, 2018

@mcollina I'd say it is a fix. It was never meant to only visualize the key in combination with maxArrayLength: 1 and the only reason it did not yet show the number of missing properties is that this information was not available with the original implementation. Besides that we have a doc note that says that no one should rely on the output programmatically due to changes like these.

@BridgeAR BridgeAR requested a review from TimothyGu July 17, 2018 17:44
@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 18, 2018
@BridgeAR
Copy link
Member Author

It would be nice to get another review before this lands.

BridgeAR added a commit to BridgeAR/node that referenced this pull request Jul 18, 2018
This adds the number of not visible elements when inspecting iterators
while exceeding `maxArrayLength`.
It also fixes a edge case with `maxArrayLength` and the map.entries()
iterator. Now the whole entry will be visible instead of only the key
but not the value of the first entry.
Besides that it uses a slighly better algorithm that improves the
performance by skipping unnecessary steps.

PR-URL: nodejs#20961
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@BridgeAR
Copy link
Member Author

Landed in 81bc23f 🎉

@BridgeAR BridgeAR closed this Jul 18, 2018
@targos targos added backport-requested-v10.x and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Jul 19, 2018
@targos
Copy link
Member

targos commented Jul 19, 2018

Should this be backported to v10.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

@targos targos mentioned this pull request Jul 31, 2018
4 tasks
rvagg pushed a commit that referenced this pull request Aug 13, 2018
This adds the number of not visible elements when inspecting iterators
while exceeding `maxArrayLength`.
It also fixes a edge case with `maxArrayLength` and the map.entries()
iterator. Now the whole entry will be visible instead of only the key
but not the value of the first entry.
Besides that it uses a slighly better algorithm that improves the
performance by skipping unnecessary steps.

PR-URL: #20961
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@BridgeAR BridgeAR deleted the improve-util-inspect-output branch January 20, 2020 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. console Issues and PRs related to the console subsystem. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants