-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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.inspect()
ing a Proxy [sometimes] shows defined properties as undefined
#21639
Comments
I would consider this a bug with your proxy, not a bug with node. |
A fair point (and, in fact, my workaround for this is to add E.g. What's the correct value of
Answer: Neither? Both? It's subjective. And because it's subjective, we should look at how these two cases are used. The property descriptor value is only available via an explicit call to |
it shouldn't matter which it uses. you're returning the wrong thing from one of them. if you don't conform to standard behaviour there can be no standard fix. changing util.inspect fixes your problem and breaks someone else's, because you both depart from expected behaviour. |
if you want, you can add a |
Unfortunately this is true, and we have limited options in combating this problem. One option if you have control over the global environment is that you can tweak the default In general, writing a fully consistent Proxy object is remarkably difficult, simply because of how many methods one has to override. Like @devsnek, I don't really see a good way to approach this from Node.js' end, since it's IMO unreasonable to limit the |
Tell me about it! 😄 FWIW, it seems like the use of getOwnPropertyDescriptor predates the Proxy standard by 3-4 years. f901443 'Not sure how or why that's important, other than to suggest that perhaps the current behavior isn't all that deliberate... [ducks]. |
it is still quite deliberate |
It does not look like this is something we can address properly. Using proxies has multiple side effects in a lot of code and we can not properly prevent that. So sadly it is more up to the proxy implementer to work around these things. If there is something concrete we can do, please just comment here. |
'Ran into this in the process of making virtual properties on a Proxy object enumerable.
See tc39/ecma262#367 (comment)
Briefly, customizing the enumeration of a Proxy object requires implementing both an
ownKeys()
method (to define the keys to be enumerated) andgetOwnPropertyDescriptor()
to declare those keys as enumerable. The problem here is that property values in Proxy objects are not canonically defined by a property descriptor the way they are with in a vanilla JS object; they're defined by the Proxyhandler.get()
method. This leads toutil.inspect
showing seemingly undefined values that, when referenced directly, are actually defined ...The text was updated successfully, but these errors were encountered: