Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upShould anonymous functions get a `name` data property? #1049
Comments
ajklein
added
the
web reality
label
Dec 19, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ljharb
Dec 19, 2017
Member
What are the same eshost results for a non-arrow function, a generator function, and an async function?
|
What are the same eshost results for a non-arrow function, a generator function, and an |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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 "").
|
@ljharb all the same as the arrow function above: v8/jsc/spidermonkey all add a |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
That strongly supports making it an own property, indeed. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
@ajklein What about unnamed class expressions across the engines? I see code in SM explicitly not defining |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
@allenwb I believe the engines which return @syg That's very interesting: only JSC provides a |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ljharb
Dec 20, 2017
Member
@allenwb could you elaborate on the reasons why this is spec'ed this way?
|
@allenwb could you elaborate on the reasons why this is spec'ed this way? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
@ajklein At the time 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 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Thanks for clarifying, that's helpful. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
@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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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
|
Marginally related: In addition to merely having a |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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).
|
@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). |
ajklein commentedDec 19, 2017
ES2015 and later give a
nameproperty to named functions (whether named via declaration, expression, or name inference). Anonymous functions aren't given one, presumably with the expectation thatnamelookups will read through toFunction.prototype.name(which is an empty string).Yet engines have legacy behavior here:
I'd propose that there'd be little downside to specifying this behavior.