3 ms·
Basically, looking at the target of a WeakRef makes it ineligible for collection until at least the next await, which the spec mandates by way of the [[KeptAliv
by pwdisswordfish9 5y ago
Basically, looking at the target of a WeakRef makes it ineligible for collection until at least the next await, which the spec mandates by way of the [[KeptAlive]] list. This is meant to prevent TOCTOU bugs by foolish programmers doing this:
if (weakref.deref()) {
/* garbage collection here */
use(weakref.deref());
}
- josefx 5y agoIsn't that a rather narrow case? What happens on the following, is that protected? if (weakref.deref()) { /* garbage collection here */ use(heavyComputations(), weakref.deref()); }
- pwdisswordfish9 5y agoYes, as long as there is no intervening suspension (await, or the script otherwise exiting to the event loop).