-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
util: restrict custom inspect function + vm.Context interaction #33690
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
Changes from 1 commit
b5bd87c
583c1bd
8544be7
7b0b27b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,7 +248,7 @@ function getUserOptions(ctx, isCrossContext) { | |
| ret.stylize = ObjectSetPrototypeOf((value, flavour) => { | ||
| let stylized; | ||
| try { | ||
| stylized = ctx.stylize(value, flavour); | ||
| stylized = `${ctx.stylize(value, flavour)}`; | ||
| } catch {} | ||
|
|
||
| if (typeof stylized !== 'string') return value; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We should probably only filter objects and functions.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn’t the purpose of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes but this function is not filtering anything in the "regular context". I would try to keep the behavior aligned (and it's not a supported function anyway).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can do this if you feel strongly about it, but imo the function is broken anyway if it does not return a string.
It’s used in examples in the documentation, so I think it qualifies as officially supported.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Also, practically speaking, I don’t think anybody is going to override this function with a custom one.)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out (even though there's no description of what it would do). I was not aware of that.
The guard here would never be triggered with the internal stylize function.
Absolutely. It would either trigger an error in such cases or it changes the printed output to the stringified value. It would therefore align the behavior more closely by using my suggestion.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
See the example above.
I can add stringification here as well, inside the try/catch. If I understand correctly, that is your main concern? I don’t see any issue with that.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I’ve implemented that. |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.