scala-js / scala-js-weakreferences

Implementation of java.lang.ref.{WeakReference,ReferenceQueue} for Scala.js
Apache License 2.0
3 stars 1 forks source link

Add java.util.WeakHashMap #5

Open jdegoes opened 5 years ago

jdegoes commented 5 years ago

Could be based on WeakMap, supported since ECMAScript 6 (2015) and on all major browsers.

sjrd commented 5 years ago

Unfortunately not. JavaScript's WeakMap lacks several fundamental features compared to Java's. In particular, it does not provide iteration of keys/entries (on purpose).

To implement java.util.WeakHashMap, we will need something more, which might be coming with a proposal for WeakRefs: https://github.com/tc39/proposal-weakrefs

tarsa commented 4 years ago

Seems that WeakRefs are now present in majority (by market share) of browsers: https://www.caniuse.com/?search=weakref https://github.com/tc39/proposal-weakrefs/pull/212/files

sjrd commented 3 years ago

WeakRefs are now at Stage 4, so we could now implement this. PR welcome.

sjrd commented 3 years ago

j.u.WeakHashMap can now be implemented in this repo, on top of WeakReference and ReferenceQueue.