-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 can throw when passed a Proxy #18036
Comments
Node.js 10 will have a > util.inspect(new Proxy({}, {ownKeys() {}}), {showProxy: true})
'Proxy [ {}, { ownKeys: [Function: ownKeys] } ]' In general though, what you have there is a buggy proxy. Throwing an exception when it doesn't honor the contract is the right thing to do. |
IMO this new option should be the default for
Right. But how do I track down the bug? By printing the proxy (and things that may contain it)... For other issues related to proxys this is a good answer. But I also think it's bad that such a buggy Proxy can act as a "poison pill" for trying to debug any surrounding code by default. |
I don't think we've ever made any throw-safety guarantees about // crash inspect
util.inspect({ [util.inspect.custom]() { throw '^_^'; } }) Is an easy example of how someone might do it. I think the point of proxies is to be able to override behavior like this - and if someone is using them they should know what they're doing when they override a hook like Since this is |
The exception message could be better but that's a V8 issue. I took a quick look and it's probably not hard to fix but I don't have time. If anyone wants to work on that and needs some pointers, let me know. Re: switching to Barring further movement, I'll close this in a few days. |
One problem with I also think that the current behaviour is correct to throw a error. |
Ironically, this has already been done by you on master in #16485.
I agree. Hence, #16485 (review). |
@TimothyGu Only in the repl, not console.log.
Does it? Not saying it doesn't but I haven't noticed it. |
It does call into a C++ runtime function. But on the other hand, calling Proxy hooks isn’t too fast either. I’m not sure which one is faster, depends on the circumstances probably. |
No further movement. I'll go ahead and close this out. |
As util.inspect is used by
console.log
in a recursive manner, such a proxy object acts as a "poison pill" for printing an object.The text was updated successfully, but these errors were encountered: