Uh oh!
There was an error while loading. Please reload this page.
util: improve inspect for (Async|Generator)Function - #11210
Conversation
This allows us to use async functions.
There was a problem hiding this comment.
(async function() {}).constructor.name === 'AsyncFunction', so I’d probably want to go with that? Or just generally actually use the constructor name, if it’s available?
There was a problem hiding this comment.
Maybe. I didn't think about that. We don't do it for GeneratorFunction though. Should I extend the PR to support it too?
There was a problem hiding this comment.
I mean, if I change the code to use constructor.name, this will be semver-major. I'm OK with that.
There was a problem hiding this comment.
Style nit: indent by four spaces.
There was a problem hiding this comment.
this will be semver-major
You mean, because it changes the output for GeneratorFunction? Yeah, that’s probably for the best. And yes, I think extending it to GeneratorFunctions would be a good idea, too.
There was a problem hiding this comment.
The original uses the capitalized constructor name (Function). How about using the same format, AsyncFunction?
There was a problem hiding this comment.
Seems a bit redundant: async AsyncFunction
There was a problem hiding this comment.
Style nit: indent by four spaces.
There was a problem hiding this comment.
Seems a bit redundant: async AsyncFunction
targos
commented
Feb 7, 2017
@bnoordhuis I'm changing the PR to get this output: What do you think? |
bnoordhuis
commented
Feb 7, 2017
Seems fine to me. |
targos
commented
Feb 7, 2017
OK, updated. Marking semver-major because the output changes for generator functions. |
There was a problem hiding this comment.
There’s a getConstructorOf utility inside this file for dealing with some edge cases :)
There was a problem hiding this comment.
Sorry to comment again 😄 I’d just move the constructor variable up before the keys.length block and do the same constructor && constructor.name … check that is used elsewhere in this file. I doubt there are many people who set their functions’ prototypes to null, but I’d prefer handling these consistently…
evanlucas
commented
Feb 7, 2017
@targos with this being a semver-major change, do you have plans to open a PR to do this for async functions in v7 as well (without the generator function change)? |
targos
commented
Feb 7, 2017
@evanlucas I can do that |
addaleax
left a comment
There was a problem hiding this comment.
Thanks for bearing with me. LGTM! :)
targos
commented
Feb 7, 2017
There was a problem hiding this comment.
Maybe const it while you're here. (EDIT: nevermind, I see it's being reassigned in some places.)
There was a problem hiding this comment.
I can't make it const because the value may be changed later.
There was a problem hiding this comment.
I have an irrational dislike for the name cName. constructorName or ctorName if the former is too long?
(Applies to line 541 as well.)
Use the constructor name in the output, if present.
Use the constructor name in the output, if present. This is a backport of nodejs#11210 without the semver-major change to GeneratorFunction output.
targos
commented
Feb 7, 2017
PR to v7.x-staging: #11211 |
| 'special'); | ||
| const ctorName = constructor ? constructor.name : 'Function'; | ||
| return ctx.stylize( | ||
| `[${ctorName}${value.name ? `: ${value.name}` : ''}]`, 'special'); |
There was a problem hiding this comment.
Nested templates can be a little bit hard to read, maybe change it to use if-else? (though this LTGM too with this unchanged, now that there is a backport PR already)
This allows us to use async functions. PR-URL: #11210 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Use the constructor name in the output, if present. PR-URL: #11210 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
jasnell
commented
Feb 11, 2017
Landed in 615789b...f65aa08 |
Use the constructor name in the output, if present. This is a backport of #11210 without the semver-major change to GeneratorFunction output. PR-URL: #11211 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Use the constructor name in the output, if present. This is a backport of nodejs#11210 without the semver-major change to GeneratorFunction output. PR-URL: nodejs#11211 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This allows us to use async functions. PR-URL: nodejs#11210 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Use the constructor name in the output, if present. PR-URL: nodejs#11210 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
util