Skip to content
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

Fix async and generator function tags in REPL output #178

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lightmare
Copy link
Contributor

Previously all kinds of functions were printed as [Function: name]

This PR differentiates:
[AsyncFunction: name]
[AsyncGeneratorFunction: name]
[GeneratorFunction: name]

In the second commit I changed the getObjectTag helper function a bit. Seemed strange that it didn't return toStringTag right away, but checked constructor.name as well and used the latter if found. Or is it actually supposed to prioritize constructor.name? In that case, it'd make sense to simply swap the two try blocks.

@ExE-Boss
Copy link
Contributor

ExE-Boss commented Sep 4, 2021

@lightmare
Copy link
Contributor Author

Thanks for the context. So both constructor.name and toStringTag should show up if they differ, right?

// Node.js v16.8.0.
> f = x => x
[Function: f]
> Object.defineProperty(f, Symbol.toStringTag, { value: 'g' })
[Function: f] [g]

@lightmare
Copy link
Contributor Author

Pushed a fix for non-matching constructor.name and toStringTag, which I originally broke.

Main (before this PR):

> Object.defineProperty(x => x, Symbol.toStringTag, { value: 'barrow' });
[Function]
> Object.defineProperty(async x => x, Symbol.toStringTag, { value: 'aarrow' });
[Function]
> Object.defineProperty(function*foo() {}, Symbol.toStringTag, { value: 'gen' });
[Function: foo]
> Object.defineProperty(async function*foo() {}, Symbol.toStringTag, { value: 'agen' });
[Function: foo]
> Object.defineProperty({}, Symbol.toStringTag, { value: 'bar' });
{ }

This PR:

> Object.defineProperty(x => x, Symbol.toStringTag, { value: 'barrow' });
[Function (anonymous)] [barrow]
> Object.defineProperty(async x => x, Symbol.toStringTag, { value: 'aarrow' });
[AsyncFunction (anonymous)] [aarrow]
> Object.defineProperty(function*foo() {}, Symbol.toStringTag, { value: 'gen' });
[GeneratorFunction: foo] [gen]
> Object.defineProperty(async function*foo() {}, Symbol.toStringTag, { value: 'agen' });
[AsyncGeneratorFunction: foo] [agen]
> Object.defineProperty({}, Symbol.toStringTag, { value: 'bar' });
Object [bar] { }

Node.js:

> Object.defineProperty(x => x, Symbol.toStringTag, { value: 'barrow' });
[Function (anonymous)] [barrow]
> Object.defineProperty(async x => x, Symbol.toStringTag, { value: 'aarrow' });
[AsyncFunction (anonymous)] [aarrow]
> Object.defineProperty(function*foo() {}, Symbol.toStringTag, { value: 'gen' });
[GeneratorFunction: foo] [gen]
> Object.defineProperty(async function*foo() {}, Symbol.toStringTag, { value: 'agen' });
[AsyncGeneratorFunction: foo] [agen]
> Object.defineProperty({}, Symbol.toStringTag, { value: 'bar' });
Object [bar] {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants