tc39 / test262

Official ECMAScript Conformance Test Suite
Other
2.31k stars 459 forks source link

Spec requires function names containing space, dot, [] #187

Closed smikes closed 9 years ago

smikes commented 9 years ago

Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp-@@species

The value of the name property of this function is "get[Symbol.species]".

Also per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-array-@@species

The value of the name property of this function is "get [Symbol.species]".

First issue: inconsistency between names here. I think that's just a typo.

This seems unnecessarily strict. Also, since the name property of a function is immutably constructed when the function is created, it puts a needless barrier in the way of of transpilers and non-native implementations of ES6.

Am I missing a way to set the function name? Thoughts? Is this a spec bug? /cc @bterlson @anba @rwaldron

domenic commented 9 years ago

Consider the following code:

const s = Symbol("Foo.bar");

const o = { get [s]() { return "b"; } };

console.log(Object.getOwnPropertyDescriptor(o, s).get.name); // outputs "get [Foo.bar]"

Am I missing a way to set the function name?

Well, it is configurable in ES6, although not in ES5 so that probably doesn't help transpilers.

smikes commented 9 years ago

so that probably doesn't help transpilers.

Indeed. Since the line specifying the name doesn't seem to do anything but document behavior that springs from other parts of the spec, can it be dropped?

anba commented 9 years ago

No, it cannot be dropped. From ch. 17:

Every built-in Function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, this value is the name that is given to the function in this specification. For functions that are specified as properties of objects, the name value is the property name string used to access the function. Functions that are specified as get or set accessor functions of built-in properties have "get " or "set " prepended to the property name string. The value of the name property is explicitly specified for each built-in functions whose property key is a symbol value.

Can you file a bug at bugs.ecmascript.org for the missing whitespace in "get[Symbol.species]" ?

arv commented 9 years ago

ES5 does not have a function name property. Some engines did but not all of them. ES6 adds it and makes it configurable so that we do not need to standardize (and implement) displayName.

smikes commented 9 years ago

Can you file a bug at bugs.ecmascript.org for the missing whitespace in "get[Symbol.species]" ?

Will do.

anba commented 9 years ago

Will do.

Thanks!

smikes commented 9 years ago

Related topic: Should WeakMap and WeakSet also have Symbol.species ?

domenic commented 9 years ago

Why would they?

smikes commented 9 years ago

Dumb parallelism? Because otherwise "Why does Set have Symbol.species but WeakSet does not" will wind up on a FAQ somewhere... or maybe just an IAQ.

domenic commented 9 years ago

Symbol.species is only useful for classes that create instances of themselves.

smikes commented 9 years ago
var m = WeakSet()
///
Array.prototype.map.call(m, function () {...})

will return an Array, then? Or.. hang on, throws an error, because there is no defined way to iterate over a WeakSet ? (No need to answer, clearly I have reading to do. :-)