You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: utilize Symbol.toStringTag in util.inspect #12780
Yes, the util.inspect.custom bit works, but given that Symbol.toStringTag is a language standard, it should definitely be supported. That said, given that util.inspect is primarily intended as a debug mechanism, relying solely on Symbol.toStringTag may be problematic. Perhaps a hybrid approach...
General +1 from me. I actually tinkered with this idea a few months ago in a branch that has been destroyed because of an HD failure, but I'm willing to write a new patch if needed.
Here are some of my findings:
What we currently do to find the class name is walking the prototype chain, and we use the name of the first constructor property we see that both a) is a function and b) has a non-empty name. That brings up a few questions for @@toStringTag support:
Should we should look for @@toStringTag as an own property first before walking the proto chain?
Should we prefer @@toStringTag of a parent prototype over a constructor property of a child prototype? If not, should we prefer @@toStringTag over constructor of the same prototype, or vice versa?
To 1 I'd answer yes, since that's also the choice taken by Object.prototype.toString. To 2, I'd say no to the first, and yes to the second (so that @@toStringTag overrides constructor in the same prototype object, but not child prototypes). I'm not too big of a fan of @jasnell's Foo [@@toStringTag: Bar] { } proposal. That's just a tad too busy, and I'd argue those who know of and set @@toStringTag probably know what to expect through doing that.
Weak -1. toStringTag is really meant just for Object.prototype.toString.call(), not for generic debugging output. The util hooks seem better for that.
But of course it's OK for debugging utils to take into account a large variety of signals, including ones not originally intended for debugging, so it's not a real problem.
Activity
mscdex commentedon May 1, 2017
Alternatively you can currently do:
jasnell commentedon May 1, 2017
Yes, the
util.inspect.custombit works, but given thatSymbol.toStringTagis a language standard, it should definitely be supported. That said, given thatutil.inspectis primarily intended as a debug mechanism, relying solely onSymbol.toStringTagmay be problematic. Perhaps a hybrid approach...TimothyGu commentedon May 1, 2017
General +1 from me. I actually tinkered with this idea a few months ago in a branch that has been destroyed because of an HD failure, but I'm willing to write a new patch if needed.
Here are some of my findings:
What we currently do to find the class name is walking the prototype chain, and we use the
nameof the firstconstructorproperty we see that both a) is a function and b) has a non-emptyname. That brings up a few questions for@@toStringTagsupport:@@toStringTagas an own property first before walking the proto chain?@@toStringTagof a parent prototype over aconstructorproperty of a child prototype? If not, should we prefer@@toStringTagoverconstructorof the same prototype, or vice versa?To 1 I'd answer yes, since that's also the choice taken by
Object.prototype.toString. To 2, I'd say no to the first, and yes to the second (so that@@toStringTagoverridesconstructorin the same prototype object, but not child prototypes). I'm not too big of a fan of @jasnell'sFoo [@@toStringTag: Bar] { }proposal. That's just a tad too busy, and I'd argue those who know of and set@@toStringTagprobably know what to expect through doing that.domenic commentedon May 11, 2017
Weak -1. toStringTag is really meant just for Object.prototype.toString.call(), not for generic debugging output. The util hooks seem better for that.
But of course it's OK for debugging utils to take into account a large variety of signals, including ones not originally intended for debugging, so it's not a real problem.
BridgeAR commentedon Dec 28, 2017
This got implemented in #16956. Closing.