Weak links are considered a security risk and, therefore, inaccessible to unprivileged code in browsers.
These problems do not apply to javascript running with privileged code or server, for example. through node.js, and therefore weak reference implementations of the platform may be available to them. firefox addons can use Components.utils.getWeakReference ()
WeakMap / WeakSet may be sufficient for certain programming patterns, but they do not allow the program to observe garbage collection, because this will require a key to examine these data structures, but holding this key will prevent the collection of objects in the first place.
An additional concern expressed by JS developers is that depending on how powerful hypothetical weak ref APIs can be. by offering notifications of completion - it can reveal significant volumes of behavior of the Civil Code, which, in turn, can limit future implementations, since a change in behavior can lead to disruption of web applications.
Update: Now it is a proposal to standardize weak references in JS, which mitigates perceived risks by linking the release of objects with low availability to JS, making the behavior more deterministic.
source share