1

We know what the global symbol registry (GSR) is.
It is global and I can access its data with Symbol.for and Symbol.keyFor.

window is global and I can access it with its name.

Is there a similar mechanism for the GSR or is it a private global registry?

Kyll
  • 7,036
  • 7
  • 41
  • 64
  • `window` is a client side JS object. GSR is not. what kind of access are you looking for? – Amit Sep 08 '15 at 20:16
  • @Amit Just wondering if one could access this registry as an object. Apparently not? – Kyll Sep 08 '15 at 20:25
  • I'm not familiar with a way to access it as an object. I don't know that it has an identifier - like `window` for example. – Amit Sep 08 '15 at 20:27
  • @Amit Me neither, I think it's probably hidden. – Kyll Sep 08 '15 at 21:27

1 Answers1

2

The window object is very different from the GSR (and less "global" of course).

No, the GSR is not represented as an object that is accessible to JS code, with properties for key-value pairs or so (or as a Map maybe). It cannot be enumerated, if that is what you are looking for. The only ways to access it are Symbol.for and Symbol.keyFor, which suffices to expose the bijective property of the relation.

This was probably (read: my speculation) done to simplify the implementation. The GSR needs to handle symbol references weakly, they should get garbage-collected when all realms that used them are terminated. Also, the multiple realms that access it might run in different threads, which adds complexity. Exposing the mapping directly to code might introduce race conditions (similar to the reason why WeakMaps are not enumerable).

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Great answer (as noted by the green polish)! Do you maybe have technical evidence, discussions, docs to back it up? – Kyll Sep 09 '15 at 11:25
  • Only the evidence that there is nothing else in the spec, sorry. – Bergi Sep 09 '15 at 11:34