-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add prototype support for function inspection #27227
Conversation
This comment has been minimized.
This comment has been minimized.
Doesn't this make them appear identical to anonymous functions now? |
@mscdex that is correct. The same will almost always be assigned and anonymous functions are rare for things to inspect. What about highlighting anonymous functions with either a different color or by explicitly mentioning that it's anonymous? That way the average would be less verbose and less duplication. If anyone has some further suggestions how to improve it further by reducing the overhead, that would be great! :-) |
@nodejs/util PTAL |
This could use some reviews. |
@nodejs/util @mscdex @joyeecheung I thought about distinguishing anonymous functions and other functions again and the best I could think of is switching the brackets. We could just use Any opinions on that? |
To me it seems like anonymous functions as property values would be more common (especially when considering object literal declarations), so keeping things the way they are now is more ideal IMO. |
@mscdex anonymous functions as property values are normally using the property name as function name:
|
Can we use (anonymous) like how it’s used in the inspector? |
4983898
to
835c19f
Compare
I updated the branch with my suggestions. That is now a somewhat more involved change than before, since I also added null prototype support and made functions more tampering proof besides just marking anonymous functions as such. @joyeecheung PTAL. Using |
The first commit is the original one. I did not change that during the rebase. The first two commits should be squashed later but I thought I keep it around for easier reviews. |
This comment has been minimized.
This comment has been minimized.
Yes, that’s what I meant, because the first part is supposed to be the type isn’t it? I think it’s fine to use it even though the name can be set using defineProperty, Chrome still does this way so this is a format people are familiar with. With the Anonymous prefix and the brackets it’s less obvious without docs. |
I also agree that putting |
Thanks for your review! I updated it to the suggestion. |
This is definitely semver-major, btw. We’ve even had issues when the function name display changed during a semver-minor V8 upgrade in the past. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think people get a good intuition for what the difference between <…>
and […]
mean, respectively, when inspecting values.
I also don’t personally see the issue with always printing the function name, even if that is a bit verbose/redundant – it seems more consistent than what this PR does, and consistency in util.inspect()
is important for intuitive understanding.
But that was about
I agree due to the change of the brackets. Without that, I don't think that it would have to be semver-major.
Since I also added |
No, I was talking about
I think this is semver-major either way, it changes
I would prefer that, yes.
I mean, still, in the end it seems like this PR removes redundancy in one way and adds it in another way, and gives up consistency during that? I don’t have strong opinions about this besides that I find the different brackets confusing, so I’d defer to others… |
I just looked through a lot of issues but I could not find anything related. Do you have a reference for it for me?
This is actually a combination of multiple minor changes. Should I maybe just move a few changes out in a separate PR? For example everything besides the
OK, but this will conflict with older Node.js versions in that case. So if we have another solution / idea, I would rather do that.
It adds the redundancy for CITGM https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1830/ ✔️ |
278a0ac
to
72f1086
Compare
This comment has been minimized.
This comment has been minimized.
@BridgeAR 9940766 is essentially what I was referring to, but I also remember something this impacting outside projects. (I vaguely remember it being one of @bcoe’s projects that was affected by
Fwiw, I’d think that anonymous function are generally more common than objects with enumerable function properties. |
I understand what change you meant but I can't find any issues or comments about trouble due to this change.
I guess in general that might be correct but those are normally not logged, are they? (I can mostly think of functions logged as object value or in case the function is assigned directly to a variable. Both of these cases infer the function name in almost all cases.) |
Isn't naming a function |
It's not possible to name a function like that when creating them but it's possible to change the name later on by using |
This commit contains the following changes: 1) Add null prototype support for functions. 2) Safely detect async and generator functions. 3) Mark anonymous functions as such instead of just leaving out the name. PR-URL: nodejs#27227 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
@BridgeAR Yes, I think so. |
This commit contains the following changes: 1) Add null prototype support for functions. 2) Safely detect async and generator functions. 3) Mark anonymous functions as such instead of just leaving out the name. PR-URL: nodejs#27227 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This makes sure that nodejs#27227 may be backported as semver-patch instead of semver-major.
I just added the backport for #27522 to the same PR. |
This commit contains the following changes: 1) Add null prototype support for functions. 2) Safely detect async and generator functions. 3) Mark anonymous functions as such instead of just leaving out the name. PR-URL: #27227 Backport-PR-URL: #27570 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This prevents function names being printed if the function is partof an object and the property it's attached to has the same name as
the function.
This adds prototype support for functions when using
util.inspect()
and marks anonymous functions explicitly as such.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes