zloirock / core-js

Standard Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Polyfill for symbols as WeakMap keys?

matthew-dean opened this issue · comments

Is there polyfill support for this yet? https://github.com/tc39/proposal-symbols-as-weakmap-keys

On Node v16 at least I get a runtime error:

TypeError: Invalid value used as weak map key

Hi. It's a good issue, but I don't think that it can be polyfilled without memory leaks, so I don't think that it's acceptable.

I think that makes sense to add a note to this section: https://github.com/zloirock/core-js#missing-polyfills

IMO it makes some sense to me to use a Map as a polyfill when a WeakMap can’t use a symbol. Yes it won’t release memory, but it helps someone ship to older versions of Node and (current) Firefox while using symbols with WeakMaps.

The key moment of weak maps is weak semantics - it's contained in the constructor name. If you don't need weak semantics - usual maps are preferable. It's better immediately throw an error on a likely leak than allow it.