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

Should anonymous functions get a `name` data property? #1049

Open
ajklein opened this Issue Dec 19, 2017 · 13 comments

Comments

Projects
None yet
6 participants
@ajklein
Contributor

ajklein commented Dec 19, 2017

ES2015 and later give a name property to named functions (whether named via declaration, expression, or name inference). Anonymous functions aren't given one, presumably with the expectation that name lookups will read through to Function.prototype.name (which is an empty string).

Yet engines have legacy behavior here:

> eshost -e '(() => {}).hasOwnProperty("name")' // same result for function(){}
#### v8
true

#### jsc
true

#### spidermonkey
true

#### chakra
false

I'd propose that there'd be little downside to specifying this behavior.

@ajklein ajklein added the web reality label Dec 19, 2017

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Dec 19, 2017

Member

What are the same eshost results for a non-arrow function, a generator function, and an async function?

Member

ljharb commented Dec 19, 2017

What are the same eshost results for a non-arrow function, a generator function, and an async function?

@ajklein

This comment has been minimized.

Show comment
Hide comment
@ajklein

ajklein Dec 19, 2017

Contributor

@ljharb all the same as the arrow function above: v8/jsc/spidermonkey all add a name property (with the value "").

Contributor

ajklein commented Dec 19, 2017

@ljharb all the same as the arrow function above: v8/jsc/spidermonkey all add a name property (with the value "").

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Dec 19, 2017

Member

That strongly supports making it an own property, indeed.

Member

ljharb commented Dec 19, 2017

That strongly supports making it an own property, indeed.

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb Dec 20, 2017

Member

Is there an reason why implementations deviated from the spec? If so, what is it?

There was a reason for why it was spec'ed the way it is. If there is a strong implementation reason for the deviation then it would make sense to change the spec. But changing it just to match unjustified implementations deviations is bad precedent.

Member

allenwb commented Dec 20, 2017

Is there an reason why implementations deviated from the spec? If so, what is it?

There was a reason for why it was spec'ed the way it is. If there is a strong implementation reason for the deviation then it would make sense to change the spec. But changing it just to match unjustified implementations deviations is bad precedent.

@syg

This comment has been minimized.

Show comment
Hide comment
@syg

syg Dec 20, 2017

Member

@ajklein What about unnamed class expressions across the engines? I see code in SM explicitly not defining .name as an own property on unnamed class exprs.

Member

syg commented Dec 20, 2017

@ajklein What about unnamed class expressions across the engines? I see code in SM explicitly not defining .name as an own property on unnamed class exprs.

@ajklein

This comment has been minimized.

Show comment
Hide comment
@ajklein

ajklein Dec 20, 2017

Contributor

@allenwb I believe the engines which return true above all implemented a name property before it was added to ECMAScript in version 6. For V8, that's definitely the case; see the tracking bug for more background. From that point of view, ES2015 is the "unjustified" one in deviating from existing behavior.

@syg That's very interesting: only JSC provides a name property for an anonymous class.

Contributor

ajklein commented Dec 20, 2017

@allenwb I believe the engines which return true above all implemented a name property before it was added to ECMAScript in version 6. For V8, that's definitely the case; see the tracking bug for more background. From that point of view, ES2015 is the "unjustified" one in deviating from existing behavior.

@syg That's very interesting: only JSC provides a name property for an anonymous class.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Dec 20, 2017

Member

@allenwb could you elaborate on the reasons why this is spec'ed this way?

Member

ljharb commented Dec 20, 2017

@allenwb could you elaborate on the reasons why this is spec'ed this way?

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb Dec 20, 2017

Member

@ajklein At the time name was added to ES6 it non-standard and wasn't universally implemented by major browsers (at least IE did not implement it). I'm sure there was variation among those that did implement it, just as has been reported in this thread. Given that situations, TC39 evaluated the utility of the feature, decided it was useful, looked at specification alternatives, made some decisions, and wrote the spec. All the major implementations were represented in that process and ultimately voted to approved the final ES6 spec. If there were objections to ES6's choosen semantics, there were plenty of opportunity to raise objections. Given all that, this sounds to me like a set of implementation bugs where implementations have not been updated to match the approved standard.

Note, that the actual design point here is not a very big deal. It could have gone either way. But the whole point of having a standard is to pin down such design points so implementations don't just go off and follow their preferences.

@ljharb Why? Because an own name property whose value is "" is redundant since such a property is inherited from Function.prototype. Plus there are many anonymous function instances . All those redundant properties add up.

Member

allenwb commented Dec 20, 2017

@ajklein At the time name was added to ES6 it non-standard and wasn't universally implemented by major browsers (at least IE did not implement it). I'm sure there was variation among those that did implement it, just as has been reported in this thread. Given that situations, TC39 evaluated the utility of the feature, decided it was useful, looked at specification alternatives, made some decisions, and wrote the spec. All the major implementations were represented in that process and ultimately voted to approved the final ES6 spec. If there were objections to ES6's choosen semantics, there were plenty of opportunity to raise objections. Given all that, this sounds to me like a set of implementation bugs where implementations have not been updated to match the approved standard.

Note, that the actual design point here is not a very big deal. It could have gone either way. But the whole point of having a standard is to pin down such design points so implementations don't just go off and follow their preferences.

@ljharb Why? Because an own name property whose value is "" is redundant since such a property is inherited from Function.prototype. Plus there are many anonymous function instances . All those redundant properties add up.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Dec 20, 2017

Member

Thanks for clarifying, that's helpful.

Member

ljharb commented Dec 20, 2017

Thanks for clarifying, that's helpful.

@annevk

This comment has been minimized.

Show comment
Hide comment
@annevk

annevk Dec 20, 2017

Contributor

I think unless implementations were confronted with the fact that they would have to remove functionality (and bugs were filed) it's hard to hold them accountable. It's rather easy for those kind of things to go unnoticed (as seems to have happened here). When there's existing legacy behavior you have to go the extra mile to get interoperability.

Contributor

annevk commented Dec 20, 2017

I think unless implementations were confronted with the fact that they would have to remove functionality (and bugs were filed) it's hard to hold them accountable. It's rather easy for those kind of things to go unnoticed (as seems to have happened here). When there's existing legacy behavior you have to go the extra mile to get interoperability.

@allenwb

This comment has been minimized.

Show comment
Hide comment
@allenwb

allenwb Dec 20, 2017

Member

@annevk Yes, these sort of things can be missed. During the ES6 period it was really the responsibility of the TC39 representatives of various implementations to key their implementors up to date on changes and it didn't always happen.

Member

allenwb commented Dec 20, 2017

@annevk Yes, these sort of things can be missed. During the ES6 period it was really the responsibility of the TC39 representatives of various implementations to key their implementors up to date on changes and it didn't always happen.

@TimothyGu

This comment has been minimized.

Show comment
Hide comment
@TimothyGu

TimothyGu Dec 27, 2017

Member

Marginally related: In addition to merely having a name own property, at least SpiderMonkey and V8's Proxy revocation functions have a name property that is "revoke" rather than the empty string. This seems like oversights, and thus filed at

Member

TimothyGu commented Dec 27, 2017

Marginally related: In addition to merely having a name own property, at least SpiderMonkey and V8's Proxy revocation functions have a name property that is "revoke" rather than the empty string. This seems like oversights, and thus filed at

@ajklein

This comment has been minimized.

Show comment
Hide comment
@ajklein

ajklein Jan 2, 2018

Contributor

@allenwb I agree it's great to have a standard to pin down design points (and we're on the same page that this particular design choice isn't particularly important one way or the other, all things being equal). But I object to disallowing changes to those designs solely by pointing to the ratification of ES6 (especially given the size of that document and its long gestation period).

Contributor

ajklein commented Jan 2, 2018

@allenwb I agree it's great to have a standard to pin down design points (and we're on the same page that this particular design choice isn't particularly important one way or the other, all things being equal). But I object to disallowing changes to those designs solely by pointing to the ratification of ES6 (especially given the size of that document and its long gestation period).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment