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

Symbol key props visible in inspection by default #9726

Closed
wants to merge 5 commits into
base: master
from
View
@@ -371,10 +371,11 @@ function formatValue(ctx, value, recurseTimes) {
// Look up the keys of the object.
var keys = Object.keys(value);
var visibleKeys = arrayToHash(keys);

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

I don't fully understand what goes on with keys vs. visibleKeys, yet, this seems to work.

@mightyiam

mightyiam Nov 21, 2016

Contributor

I don't fully understand what goes on with keys vs. visibleKeys, yet, this seems to work.

var symbolKeys = Object.getOwnPropertySymbols(value);

This comment has been minimized.

@addaleax

addaleax Nov 22, 2016

Member

I haven’t run this but right now this looks like this will include even *non-*enumerable Symbol properties?

@addaleax

addaleax Nov 22, 2016

Member

I haven’t run this but right now this looks like this will include even *non-*enumerable Symbol properties?

This comment has been minimized.

@mightyiam

mightyiam Nov 22, 2016

Contributor

Yup. That is how Object.getOwnPropertySymbols works. It is like the conversation between it and Object.getOwnPropertyNames is:

  • Object.getOwnPropertyNames: Hey, Symbol. You may join. But don't expect me to list you, even if you're enumerable...
  • Symbol: 😐
  • Object.getOwnPropertySymbols: Gee, did you see that guy? Tell you what, Symbol. I'll list all of you, regardless!
  • Symbol: 😟
  • Object.getOwnPropertyNames: 😦
  • Object.getOwnPropertySymbols: 😊
  • Symbol: 😕

I wouldn't mind changing it to exclude non-enumerable symbol-keyed props. Should I?

@mightyiam

mightyiam Nov 22, 2016

Contributor

Yup. That is how Object.getOwnPropertySymbols works. It is like the conversation between it and Object.getOwnPropertyNames is:

  • Object.getOwnPropertyNames: Hey, Symbol. You may join. But don't expect me to list you, even if you're enumerable...
  • Symbol: 😐
  • Object.getOwnPropertySymbols: Gee, did you see that guy? Tell you what, Symbol. I'll list all of you, regardless!
  • Symbol: 😟
  • Object.getOwnPropertyNames: 😦
  • Object.getOwnPropertySymbols: 😊
  • Symbol: 😕

I wouldn't mind changing it to exclude non-enumerable symbol-keyed props. Should I?

This comment has been minimized.

@addaleax

addaleax Nov 22, 2016

Member

Well… it seems a bit weird to list only enumerable string properties but all Symbol properties by default?

@addaleax

addaleax Nov 22, 2016

Member

Well… it seems a bit weird to list only enumerable string properties but all Symbol properties by default?

This comment has been minimized.

@mightyiam

mightyiam Nov 22, 2016

Contributor

I just don't know the reasons for not listing non-enumerable properties. For the sake of explaining my experience with the matter, I'll testify that I:

  1. never made a property non-enumerable before examining this issue
  2. never had to examine the non-enumerable properties of an object. At least not that I know of.

So, it may help that one with experience with the topic of enumerability and non-enumerability will share his thoughts. Also, the thoughts of one who knows the intention of symbols in this regard and why this is the behavior of Object.getOwnPropertySymbols.

@mightyiam

mightyiam Nov 22, 2016

Contributor

I just don't know the reasons for not listing non-enumerable properties. For the sake of explaining my experience with the matter, I'll testify that I:

  1. never made a property non-enumerable before examining this issue
  2. never had to examine the non-enumerable properties of an object. At least not that I know of.

So, it may help that one with experience with the topic of enumerability and non-enumerability will share his thoughts. Also, the thoughts of one who knows the intention of symbols in this regard and why this is the behavior of Object.getOwnPropertySymbols.

keys = keys.concat(symbolKeys);
if (ctx.showHidden) {
keys = Object.getOwnPropertyNames(value);
keys = keys.concat(Object.getOwnPropertySymbols(value));
keys = Object.getOwnPropertyNames(value).concat(symbolKeys);

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This is the same result. The change is to not get the symbols twice.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This is the same result. The change is to not get the symbols twice.

}
// This could be a boxed primitive (new String(), etc.), check valueOf()
@@ -588,8 +588,9 @@ assert.doesNotThrow(function() {
'{ a: 123, inspect: [Function: inspect] }');
const subject = { a: 123, [util.inspect.custom]() { return this; } };
const UTC = 'util.inspect.custom';

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This trick is solely for line length.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This trick is solely for line length.

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

It seems fine because this is in a small block.

@mightyiam

mightyiam Nov 21, 2016

Contributor

It seems fine because this is in a small block.

This comment has been minimized.

@mscdex

mscdex Nov 21, 2016

Contributor

IMHO 'UTC' isn't a particularly good name. To me, it makes me think of Coordinated Universal Time, but the variable value does not hold anything date/time-related.

@mscdex

mscdex Nov 21, 2016

Contributor

IMHO 'UTC' isn't a particularly good name. To me, it makes me think of Coordinated Universal Time, but the variable value does not hold anything date/time-related.

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

Oops. Just a typo. I meant UIC for util.inspect.custom But, from Wikipedia:

UIC may refer to:

In education:

Underwood International College, a department of Yonsei University
United International College, a liberal arts college in China
University of Illinois at Chicago, a public four-year university in Chicago, Illinois
In government:

Uganda Insurance Commission, a government agency
Unit Identification Code, an alphanumeric code used by the United States Department of Defense
In organisations:

International Union of Railways (Union Internationale des Chemins de fer), an international rail transport industry body
UEFA Intertoto Cup, an association football tournament for member clubs of UEFA
Union of Islamic Courts, an armed group in Somalia, now called the "Supreme Islamic Courts Council"
United Industrial Corporation Ltd, a Singapore real estate holding company owned by JG Summit Holdings
In computing:

Uranium Information Centre, a defunct website sponsored by uranium mining companies
User identification code, the user number of the Files-11 file system in the RSX-11 operating system
In other uses:

UIC (band), a punk rock band from Canada
UIC Flames, the intercollegiate athletic program of the University of Illinois at Chicago

What is a good name?

@mightyiam

mightyiam Nov 21, 2016

Contributor

Oops. Just a typo. I meant UIC for util.inspect.custom But, from Wikipedia:

UIC may refer to:

In education:

Underwood International College, a department of Yonsei University
United International College, a liberal arts college in China
University of Illinois at Chicago, a public four-year university in Chicago, Illinois
In government:

Uganda Insurance Commission, a government agency
Unit Identification Code, an alphanumeric code used by the United States Department of Defense
In organisations:

International Union of Railways (Union Internationale des Chemins de fer), an international rail transport industry body
UEFA Intertoto Cup, an association football tournament for member clubs of UEFA
Union of Islamic Courts, an armed group in Somalia, now called the "Supreme Islamic Courts Council"
United Industrial Corporation Ltd, a Singapore real estate holding company owned by JG Summit Holdings
In computing:

Uranium Information Centre, a defunct website sponsored by uranium mining companies
User identification code, the user number of the Files-11 file system in the RSX-11 operating system
In other uses:

UIC (band), a punk rock band from Canada
UIC Flames, the intercollegiate athletic program of the University of Illinois at Chicago

What is a good name?

This comment has been minimized.

@addaleax

addaleax Nov 22, 2016

Member

@mightyiam It might be best not to give this a name at all but instead spread the string below across multiple lines?

@addaleax

addaleax Nov 22, 2016

Member

@mightyiam It might be best not to give this a name at all but instead spread the string below across multiple lines?

assert.strictEqual(util.inspect(subject),
'{ a: 123 }');
`{ a: 123,\n [Symbol(${UTC})]: [Function: [${UTC}]] }`);

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This is a fix for a seemingly unrelated test that is affected.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This is a fix for a seemingly unrelated test that is affected.

}
// util.inspect with "colors" option should produce as many lines as without it
@@ -659,7 +660,7 @@ if (typeof Symbol !== 'undefined') {
subject[Symbol('symbol')] = 42;
assert.strictEqual(util.inspect(subject), '{}');
assert.strictEqual(util.inspect(subject), '{ [Symbol(symbol)]: 42 }');

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This demonstrates the change.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This demonstrates the change.

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

Just the way I like it 😉

@mightyiam

mightyiam Nov 21, 2016

Contributor

Just the way I like it 😉

assert.strictEqual(
util.inspect(subject, options),
'{ [Symbol(symbol)]: 42 }'
@@ -668,9 +669,8 @@ if (typeof Symbol !== 'undefined') {
subject = [1, 2, 3];
subject[Symbol('symbol')] = 42;
assert.strictEqual(util.inspect(subject), '[ 1, 2, 3 ]');
assert.strictEqual(util.inspect(subject, options),
'[ 1, 2, 3, [length]: 3, [Symbol(symbol)]: 42 ]');

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This assertion is removed because we already have an assertion above that symbol key properties are visible with showHidden.

@mightyiam

mightyiam Nov 21, 2016

Contributor

This assertion is removed because we already have an assertion above that symbol key properties are visible with showHidden.

assert.strictEqual(util.inspect(subject),
'[ 1, 2, 3, [Symbol(symbol)]: 42 ]');

This comment has been minimized.

@mightyiam

mightyiam Nov 21, 2016

Contributor

So in essence, this assertion is not instead of the one in 672, but instead of the one in 671. I guess it shows that symbol key properties can coexist peacefully with other properties in inspection. Or something about the order of properties? In any case, I'm guessing that the essence is preserved.

@mightyiam

mightyiam Nov 21, 2016

Contributor

So in essence, this assertion is not instead of the one in 672, but instead of the one in 671. I guess it shows that symbol key properties can coexist peacefully with other properties in inspection. Or something about the order of properties? In any case, I'm guessing that the essence is preserved.

}
// test Set
ProTip! Use n and p to navigate between commits in a pull request.