The builtin could have weak values (i.e. Symbol instances expire when no longer referenced by JS) instead of weak keys, which is not something we can currently express in JS. This would also make it possible to use strings/integers/floats as Symbol keys without leaking those Symbol instances forever. This is not something we can express in JS either.
Both of these behaviors would not, as I understand it, be directly observable since keeping an old Symbol instance around (to compare with) would prevent the cached one from being collected. On the other hand, I think if you were to resynthesize the number/string used as a symbol key and make a new symbol, that might allow you to observe whether the symbol had been collected. This doesn't seem like a huge problem to me but I forget the exact reasoning why weak references were unacceptable in the past; maybe it still applies to this. On Mon, Jul 15, 2013 at 9:08 AM, Allen Wirfs-Brock <[email protected]>wrote: > > On Jul 15, 2013, at 6:49 AM, Jeremy Martin wrote: > > > In some (most?) cases, but not all. There's already a consensus that the > garbage collection semantics of WeakMaps aren't always appropriate [2]. By > parameterizing the Symbol constructor, developers can create custom map/set > types without the overhead of a "Symbol Factory" (as previously suggested > by Allen). I believe this would be a useful building block for interesting > and innovative custom types. > > [1]: https://en.wikipedia.org/wiki/Injective_function#Definition > [2]: http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets > > > An implementation of your proposal is going to have to have to internally > use some wort of weak-keyed table, in practice an implementation would > probably use the same GC mechanisms that are there to support WeakMap. So, > I doubt there would be much performance difference between a built-in and a > roll-your-own implementation. > > Allen > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

