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(cli/rt/console): fix inspection of Function #7930

Merged
merged 1 commit into from
Oct 11, 2020

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Oct 11, 2020

This PR fixes the inspection of functions. The current implementation gets the name of the type of the function from f.__proto__.constructor.name, and it throws when the prototype is set to null as described in #7633. This PR checks the prototype before accessing its constructor name and uses the generic name 'Function' if the prototype is not available.

fixes #7633

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @kt3k

I'll wait for @nayeemrmn approval before landing

Copy link
Collaborator

@nayeemrmn nayeemrmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju bartlomieju merged commit 265a9fb into denoland:master Oct 11, 2020
@kt3k kt3k deleted the fix/inspect-function branch October 12, 2020 02:09
Comment on lines +357 to +362
const gf = function gf() {};
Reflect.setPrototypeOf(gf, null);
assertEquals(stringify(gf), "[Function: gf]");
const agf = function agf() {};
Reflect.setPrototypeOf(agf, null);
assertEquals(stringify(agf), "[Function: agf]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is already merged, but was this intended to test generator functions and async generator functions? (function* gf() {} and async function* agf() {})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solson good catch, could you open an issue about it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function* gf() {} and async function* agf() {}

Are you saying they should have their own output? That's just declaration-side syntactic sugar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm saying they should be declared that way here in the test, as in const gf = function* gf() {}; to match async function af above, presumably to test this "set prototype to null" manipulation on all 4 of Function, AsyncFunction, GeneratorFunction, and AsyncGeneratorFunction. Currently, gf and agf are just testing the same thing as f.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

console.log dies on null prototype function
4 participants