Question about Symbols and GlobalSymbolRegistry

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about Symbols and GlobalSymbolRegistry

Cyrus Najmabadi

Hi,

 

I am reading the Symbol section of the ES6 spec (19.4), and my understanding is that calling the Symbol constructor does *not* add an entry to the GlobalSymbolRegistry. Is that correct?

 

For example:

var s1 = Symbol(“foo”);

var s2 = Symbol.for(“foo”);

 

In this example, s1 and s2 would be two distinct symbols. And in the following example:

 

var s1 = Symbol(“foo”);

var s2 = Symbol.keyFor(s1);

 

In this example, s2 would be undefined.

 

Am I understanding correctly?

 

Thanks,
Jason

 


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Question about Symbols and GlobalSymbolRegistry

Axel Rauschmayer
Correct. The registry is only accessed via `Symbol.for(key)` and `Symbol.keyFor(sym)`. The parameter of `Symbol()` is a description, not a key.



On 22 Jan 2015, at 01:36, Cyrus Najmabadi <[hidden email]> wrote:

Hi,
 
I am reading the Symbol section of the ES6 spec (19.4), and my understanding is that calling the Symbol constructor does *not* add an entry to the GlobalSymbolRegistry. Is that correct?
 
For example:
var s1 = Symbol(“foo”);
var s2 = Symbol.for(“foo”);
 
In this example, s1 and s2 would be two distinct symbols. And in the following example:
 
var s1 = Symbol(“foo”);
var s2 = Symbol.keyFor(s1);
 
In this example, s2 would be undefined.
 
Am I understanding correctly?
 
Thanks,
Jason
 
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

-- 
Dr. Axel Rauschmayer
[hidden email]
rauschma.de




_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Question about Symbols and GlobalSymbolRegistry

Kevin Smith
In reply to this post by Cyrus Najmabadi


> Am I understanding correctly?

Yes. The argument to the Symbol constructor is just a descriptive string.


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

RE: Question about Symbols and GlobalSymbolRegistry

Cyrus Najmabadi

Hi esdiscuss.  A couple more questions.

 

1)      Are the built-in symbols (like ‘Symbol.iterator’) in the GlobalSymbolRegsitry?

2)      If so, what are their keys?  i.e. how would one reach Symbol.iterator using Symbol.for(…)?

 

Thanks!

 

         -- Cyrus

 

 

 

From: Kevin Smith [mailto:[hidden email]]
Sent: Wednesday, January 21, 2015 5:16 PM
To: Cyrus Najmabadi
Cc: Jason Freeman; es-discuss
Subject: Re: Question about Symbols and GlobalSymbolRegistry

 


> Am I understanding correctly?

Yes. The argument to the Symbol constructor is just a descriptive string.


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Question about Symbols and GlobalSymbolRegistry

Jordan Harband
They are not - if they were, then adding a new well-known symbol like Symbol.foo would fail if anyone had code that did `Symbol.for('foo')`. (I have no idea if that is the reason, but certainly that's a reason not to make them available via the registry)

On Tue, Jan 27, 2015 at 2:32 PM, Cyrus Najmabadi <[hidden email]> wrote:

Hi esdiscuss.  A couple more questions.

 

1)      Are the built-in symbols (like ‘Symbol.iterator’) in the GlobalSymbolRegsitry?

2)      If so, what are their keys?  i.e. how would one reach Symbol.iterator using Symbol.for(…)?

 

Thanks!

 

         -- Cyrus

 

 

 

From: Kevin Smith [mailto:[hidden email]]
Sent: Wednesday, January 21, 2015 5:16 PM
To: Cyrus Najmabadi
Cc: Jason Freeman; es-discuss
Subject: Re: Question about Symbols and GlobalSymbolRegistry

 


> Am I understanding correctly?

Yes. The argument to the Symbol constructor is just a descriptive string.


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Question about Symbols and GlobalSymbolRegistry

Axel Rauschmayer
It may make sense to add them. Their identifiers would have to be as unambiguous as possible, e.g. URIs such as "http://ecmascript.org/symbol/foo".


On 27 Jan 2015, at 23:55, Jordan Harband <[hidden email]> wrote:

They are not - if they were, then adding a new well-known symbol like Symbol.foo would fail if anyone had code that did `Symbol.for('foo')`. (I have no idea if that is the reason, but certainly that's a reason not to make them available via the registry)

On Tue, Jan 27, 2015 at 2:32 PM, Cyrus Najmabadi <[hidden email]> wrote:

Hi esdiscuss.  A couple more questions.

 

1)      Are the built-in symbols (like ‘Symbol.iterator’) in the GlobalSymbolRegsitry?

2)      If so, what are their keys?  i.e. how would one reach Symbol.iterator using Symbol.for(…)?

 

Thanks!

 

         -- Cyrus

 

 

 

From: Kevin Smith [mailto:[hidden email]]
Sent: Wednesday, January 21, 2015 5:16 PM
To: Cyrus Najmabadi
Cc: Jason Freeman; es-discuss
Subject: Re: Question about Symbols and GlobalSymbolRegistry

 


> Am I understanding correctly?

Yes. The argument to the Symbol constructor is just a descriptive string.


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

-- 
Dr. Axel Rauschmayer
[hidden email]
rauschma.de




_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Question about Symbols and GlobalSymbolRegistry

Brendan Eich-2
Axel Rauschmayer wrote:
> It may make sense to add them. Their identifiers would have to be as
> unambiguous as possible, e.g. URIs such as
> "http://ecmascript.org/symbol/foo".

Symbol.iterator and the other well-known symbols are self-same in all
connected realms. See
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-well-known-symbols.

So there's no need for this (and URLs suck for such things; plus, you
probably mean URIs, but I don't care enough to check!).

/be
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Question about Symbols and GlobalSymbolRegistry

Axel Rauschmayer
On 28 Jan 2015, at 00:06, Brendan Eich <[hidden email]> wrote:

Axel Rauschmayer wrote:
It may make sense to add them. Their identifiers would have to be as unambiguous as possible, e.g. URIs such as "http://ecmascript.org/symbol/foo".

Symbol.iterator and the other well-known symbols are self-same in all connected realms. See http://people.mozilla.org/~jorendorff/es6-draft.html#sec-well-known-symbols.

So there's no need for this

There is one use case (admittedly a rather hypothetical one): serializing the Symbol.* symbols to a text format (e.g. an encoding in JSON).

(and URLs suck for such things; plus, you probably mean URIs, but I don't care enough to check!).

Yes, I mean URIs(?)

-- 
Dr. Axel Rauschmayer
[hidden email]
rauschma.de




_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Question about Symbols and GlobalSymbolRegistry

Brendan Eich-2
Axel Rauschmayer wrote:
>> So there's no need for this
>
> There is one use case (admittedly a rather hypothetical one):
> serializing the Symbol.* symbols to a text format (e.g. an encoding in
> JSON).

Symbols that user-code puts into the registry do not serialize this way,
so why should the well-known ones?

If you want to write a JSON helper-pair (toJSON or a replacer, with a
correponding reviver, I think), then you can indeed serialize and
deserialize symbols. But there's no ES6 backstage default-wiring from
JSON to Symbol.for/keyFor.

/be
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss