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

Inspected objects’ symbol key properties are hidden by default #9709

Closed
mightyiam opened this issue Nov 20, 2016 · 8 comments
Closed

Inspected objects’ symbol key properties are hidden by default #9709

mightyiam opened this issue Nov 20, 2016 · 8 comments
Labels
question Issues that look for answers. util Issues and PRs related to the built-in util module.

Comments

@mightyiam
Copy link
Contributor

  • Version: v7.1.0
  • Platform: Linux shahar-desktop 4.8.0-27-generic docs: added a the #29-Ubuntu SMP Thu Oct 20 21:03:13 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: ?

I find it useful to be able to inspect the contents of an object by by looking at it in an interactive session. I'll call this the "debug representation". What is the correct term, please?

Now that we have symbols I'm experimenting with using them as object keys. I think it should reduce chance of accidental name collisions/overwrites, if done properly.

Thing is—while inspection of objects with "normal" keys is easy:

{ foo: undefined }
// { foo: undefined }

Inspection of objects with symbol keys is hard:

let obj = { [Symbol()]: undefined }

obj
// {}

While, obviously:

Object.getOwnPropertySymbols(obj)
// [ Symbol() ]

😢

I expect this:

obj
// { Symbol(): undefined }

It makes sense, doesn't it?

We already have this, so it makes sense to expect what I'm expecting, does’t it?

Symbol()
// Symbol()
Symbol('foo')
// Symbol(foo)

Chrome DevTools seems to do the right thing:
screenshot_2016-11-20_15-52-28

@vkurchatkin vkurchatkin added the question Issues that look for answers. label Nov 20, 2016
@vkurchatkin
Copy link
Contributor

You can enable this behaviour like this:

util.inspect.defaultOptions.showHidden = true

@mightyiam
Copy link
Contributor Author

That's great advice, @vkurchatkin. Thank you.

Is there a reason why this is not default, please? This issue was closed without providing a reason.

@mightyiam mightyiam changed the title Debug representation of objects excludes symbol key properties Debug representation of objects excludes symbol key properties by default Nov 20, 2016
@mightyiam mightyiam changed the title Debug representation of objects excludes symbol key properties by default inspected object’s symbol key properties are hidden by default Nov 20, 2016
@mightyiam mightyiam changed the title inspected object’s symbol key properties are hidden by default Inspected object’s symbol key properties are hidden by default Nov 20, 2016
@mightyiam mightyiam changed the title Inspected object’s symbol key properties are hidden by default Inspected objects’ symbol key properties are hidden by default Nov 20, 2016
@addaleax addaleax added the util Issues and PRs related to the built-in util module. label Nov 20, 2016
@addaleax
Copy link
Member

@mightyiam Fyi, the docs about this are in https://nodejs.org/api/util.html#util_util_inspect_object_options

Generally util.inspect uses Object.keys() to determine which keys are to be displayed; if you think Symbols should be displayed by default, too, you can open a pull request to change it. But I wouldn’t be surprised if people have come to rely on the current behaviour or even just like it.

@bnoordhuis
Copy link
Member

I somewhat agree that the current behavior is a little inconsistent: you use showHidden to include non-enumerable properties but symbol properties are normally enumerable so why do you need showHidden=true to make them show up?

@vkurchatkin
Copy link
Contributor

symbol properties are normally enumerable

Not really, you need getOwnPropertySymbols for symbols the same way you need getOwnPropertyNames for non-enumerable properties

@bnoordhuis
Copy link
Member

Yes, but then again, no. What I mean is this:

$ node
> var o = {}, k = Symbol(); o[k] = 42
42

> Object.getOwnPropertyDescriptor(o, k)
{ value: 42,
  writable: true,
  enumerable: true,
  configurable: true }

@vkurchatkin
Copy link
Contributor

@bnoordhuis well, that's how it is in the spec, right? enumerable is true, but they are not in fact enumerable

@mightyiam
Copy link
Contributor Author

Yet, this is not about the spec, enumerability or anything like that. This is about our ability and ease when debugging is how I see it. Do you use symbol keys? If so, don't you find it unreasonable that they're not showing up in the interactive mode? I do. I find it awful. I'll make a PR if it isn't too hard.

mightyiam added a commit to mightyiam/node that referenced this issue Nov 21, 2016
I use symbol key properties. And I find it awful that they do
not show up in inspection. I can alter
`util.inspect.defaultOptions.showHidden` each time I debug. Does
that sound like fun to you? Isn't fun a core principle life?

The way I see it, it is not about the spec or about what is
enumerable/hidden, etc. When inspecting, it is about ease of
access to the information. That's how I see it. Does anyone have
any other thoughts?

Fixes nodejs#9709 (which should not have been closed so fast)
addaleax pushed a commit to addaleax/node that referenced this issue Mar 15, 2017
I use symbol key properties. And I find it awful that they do
not show up in inspection. I can alter
`util.inspect.defaultOptions.showHidden` each time I debug. Does
that sound like fun to you? Isn't fun a core principle life?

The way I see it, it is not about the spec or about what is
enumerable/hidden, etc. When inspecting, it is about ease of
access to the information. That's how I see it. Does anyone have
any other thoughts?

Fixes: nodejs#9709
addaleax pushed a commit that referenced this issue Mar 16, 2017
I use symbol key properties. And I find it awful that they do
not show up in inspection. I can alter
`util.inspect.defaultOptions.showHidden` each time I debug. Does
that sound like fun to you? Isn't fun a core principle life?

The way I see it, it is not about the spec or about what is
enumerable/hidden, etc. When inspecting, it is about ease of
access to the information. That's how I see it. Does anyone have
any other thoughts?

Fixes: #9709
PR-URL: #9726
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
jungx098 pushed a commit to jungx098/node that referenced this issue Mar 21, 2017
I use symbol key properties. And I find it awful that they do
not show up in inspection. I can alter
`util.inspect.defaultOptions.showHidden` each time I debug. Does
that sound like fun to you? Isn't fun a core principle life?

The way I see it, it is not about the spec or about what is
enumerable/hidden, etc. When inspecting, it is about ease of
access to the information. That's how I see it. Does anyone have
any other thoughts?

Fixes: nodejs#9709
PR-URL: nodejs#9726
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants