Skip to content

Fix async and generator function tags in REPL output#178

Open
lightmare wants to merge 4 commits into
engine262:mainfrom
lightmare:fix-inspect-async-function
Open

Fix async and generator function tags in REPL output#178
lightmare wants to merge 4 commits into
engine262:mainfrom
lightmare:fix-inspect-async-function

Conversation

@lightmare

Copy link
Copy Markdown
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

ExE-Boss commented Sep 4, 2021

Copy link
Copy Markdown
Contributor

@lightmare

Copy link
Copy Markdown
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
Copy Markdown
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.

3 participants