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: unenumerable properties should be visible #1598

Closed
silverwind opened this issue May 3, 2015 · 10 comments
Closed

util: unenumerable properties should be visible #1598

silverwind opened this issue May 3, 2015 · 10 comments
Labels
util Issues and PRs related to the built-in util module.

Comments

@silverwind
Copy link
Contributor

> var o = {}; Object.defineProperty(o, "a", {get: function(){return 1}})
{}
> var o = {}; Object.defineProperty(o, "a", {get: function(){return 1}, enumerable:true})
{ a: [Getter] }

Same in Chrome:

screenshot_49

cc: @monsanto

@silverwind silverwind added the util Issues and PRs related to the built-in util module. label May 3, 2015
@petkaantonov
Copy link
Contributor

Though these views are not equivalent. The equivalent view in chrome is when you expand the properties and in that view the unenumerable properties are greyed out. Perhaps there should be some kind of enumerability marker in the util view as well?

@silverwind
Copy link
Contributor Author

True, one could do something like [Getter/enumerable], but I think that could be too verbose.

As I see it, everything is better than {}.

@monsanto
Copy link
Contributor

monsanto commented May 3, 2015

This is intentional, unenumerable properties need the showHidden flag set to show:

> require('util').inspect(o, {showHidden: true})
'{ [a]: [Getter] }'

although I guess whether or not this is desirable is up for discussion. Keep in mind on the REPL this would get obnoxious quick since arrays would show their length attribute.

@silverwind
Copy link
Contributor Author

Interesting. This is what Firefox does:

> var o = {}; Object.defineProperty(o, "a", {get: function(){}})
Object { , 1 more… }
> var o = {}; Object.defineProperty(o, "a", {get: function(){}, enumerable:true})
Object { a: Getter }

@bnoordhuis
Copy link
Member

Ping @silverwind, what is the status of this issue?

@silverwind
Copy link
Contributor Author

I think we could change showHidden to default to true, with special handling to hide language builtin unenumerable properties. This would be pretty much what the Chrome console now does. If we agree on that, I can do a PR.

@vkurchatkin
Copy link
Contributor

-1 from me. I don't think we should try to replicate Chrome console

@chrisdickinson
Copy link
Contributor

I think we could change showHidden to default to true

I'm not opposed to either making it default to true for the REPL/console only. Where ansi colors are enabled we should probably use them to indicate non-enumerability of properties as well.

@silverwind
Copy link
Contributor Author

Yeah, would keep it REPL-only. I could see property names colored blue as normal properties and magenta as unenumerable ones. Right now, we only color the value (yellow).

@silverwind
Copy link
Contributor Author

Decided against pursuing this further because having showHidden flipped just on the REPL to make this work seems wrong. Also, blue ansi color is unreadable on Windows according to a comment. If we ever decide to add 256 color support to inspect, we might be able to revisit this issue.

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

No branches or pull requests

6 participants