What are Symbols? Objects? New primitive type?
bbenvie at mozilla.com
Sat Apr 13 06:26:16 PDT 2013
On 4/13/2013 12:31 AM, Andreas Rossberg wrote:
> On 13 April 2013 00:12, Brandon Benvie <bbenvie at mozilla.com> wrote:
>> 3.) A new type of primitive along with a new type of wrapper. In this case
>> we use the String/Number/Boolean precedent where `Symbol()` and `new
>> Symbol()` produce different kinds of results. The problem here is the
>> confusion that comes with ToString/ToPropertyKey when called on a Symbol
>> wrapper. What does `obj[new Symbol] = 5` do, for example? It allows footguns
>> like `obj[key + '_ext']` to silently do the wrong thing.
> That was the consensus at the last meeting, and it's already
> implemented in V8. The decision included that
> Symbol.prototype.toString is poisoned, i.e., any attempt to implicitly
> convert a symbol or a wrapped symbol to a string will throw, including
> both of your examples. So no footgun, which I agree is important.
> (Object.prototype.toString is not on that path, however, so can treat
> symbols separately.)
> I'm a bit confused about some bits of Allen's comment on your Gist,
> though, which don't line up with what I thought we decided on. In
> particular, ToObject(symbol) should be perfectly fine and creates a
> wrapper object. Similarly, Symbol()["foo"] auto-converts to a wrapper
> object and returns undefined as usual, and new Symbol() directly
> creates a wrapper object.
This would be the reason I created this thread: there was at least two
different interpretations of the outcome of the meeting by people who
were at the meeting, and a third one (mine) that came from reading the
meeting notes. From that I surmised it would be good to, at the very
least, figure out which one of the three is an accurate reflection of
what was actually to be the final version.
More information about the es-discuss