Skip to content

util: support inspecting namespaces of unevaluated modules - #20782

Closed
devsnek wants to merge 1 commit into
nodejs:masterfrom
devsnek:fix/util-inspect-module-namespace
Closed

util: support inspecting namespaces of unevaluated modules#20782
devsnek wants to merge 1 commit into
nodejs:masterfrom
devsnek:fix/util-inspect-module-namespace

Conversation

@devsnek

Copy link
Copy Markdown
Member
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-botnodejs-github-bot added the util Issues and PRs related to the built-in util module. label May 16, 2018

@bnoordhuisbnoordhuis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM modulo nit.

Comment threadlib/util.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you s/ns/value/? All functions call it that except this one.

@guybedfordguybedford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great to see these debugging experiences made nicer.

Comment threadlib/util.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This line should rather go along with the value checks at line 571.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

i'm not quite sure how to do that, should i make another formatObject function like formatNamespaceObject?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, that would be the ideal way here. That way there is no performance impact on regular objects.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

i'll move it for consistency, but just for the record the isModuleNamespaceObject check still happens either way, there is no perf difference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure how V8 optimizes the loop in this case. I guess it could be smart to remove the isNs check but otherwise there would be a minor overhead.

Comment threadlib/util.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

array === 0 will always be true.

Comment threadlib/util.js Outdated

@BridgeARBridgeARMay 16, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am somewhat surprised that the keys are exposed even though accessing them throws. I guess that is done by design - out of curiosity: would you be so kind and point me to the reasons why this is done like that? After looking at the test again, I see why it throws.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

even though we know the export names, they aren't yet intialised (think console.log(a); const a = 1). there is no js value that can represent this state so v8 throws a reference error, which is what would happen with that example.

Comment threadlib/util.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a fan of copy pasting this part. It could easily get out of sync if anything small changes.

@addaleax

Copy link
Copy Markdown
Member

@BridgeAR

Copy link
Copy Markdown
Member

@addaleax thanks for starting the benchmark.

If they turn out to have a impact I would like to only show this when showHidden is active.

@devsnek
devsnekforce-pushed the fix/util-inspect-module-namespace branch from 83ed8df to f0644e4CompareMay 16, 2018 19:34

@BridgeARBridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with my nits addressed.

Comment threadlib/util.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to move this down to the last else because it is probably one of the least used values and does not need to be performant.

Comment threadlib/util.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do not use a default value and just explicitly pass through the value.

Comment threadlib/util.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could now be rewritten to: if (foo) return ... if (bar) return ...

@devsnek
devsnekforce-pushed the fix/util-inspect-module-namespace branch from f0644e4 to d065be3CompareMay 17, 2018 16:07
@devsnek

Copy link
Copy Markdown
MemberAuthor

@devsnek

Copy link
Copy Markdown
MemberAuthor

@devsnekdevsnek added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 17, 2018
@devsnek

Copy link
Copy Markdown
MemberAuthor

landed in 064057b

@devsnekdevsnek closed this May 19, 2018
@devsnek
devsnek deleted the fix/util-inspect-module-namespace branch May 19, 2018 01:41
@devsnekdevsnek removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 19, 2018
devsnek added a commit that referenced this pull request May 19, 2018
PR-URL: #20782
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 22, 2018
PR-URL: #20782
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleaxaddaleax mentioned this pull request May 22, 2018
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

utilIssues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@devsnek@addaleax@BridgeAR@bnoordhuis@jasnell@guybedford@nodejs-github-bot