Cool! The getImage example seems a tricky one. I'd probably implement that as an LRU cache so as not to presume images are held as references (imagine if the consumer of getImage places the gen'd images in <img src> as data URIs). More examples of potential usage may be useful.
-
-
-
This is why we worked to provide a more detailed explainer in the proposal README as well: https://github.com/tc39/proposal-weakrefs#readme … with
@littledan,@andywingo,@mhofman,@_gsathya, and yours truly The goal of the V8 feature explainer is to give a relatively succinct explanation.
End of conversation
New conversation -
-
-
When is this shipping in Chrome?
-
Stay tuned
(We have an implementation behind a flag.)
End of conversation
New conversation -
-
-
It doesn't seem to include a link to the proposal? I found it, but it should probably be included (and the status explained) so it doesn't look like a V8-only feature.
-
Nothing on http://v8.dev/features is V8-only feature. These are all standardized language features that V8 happens to ship (or in this case, implements behind a flag). There's already a link to the proposal in the article too.
- 1 more reply
New conversation -
-
-
Great post. In one of the notes, it is mentioned that the check `The ref !== undefined` is required. Did you actually mean both the checks `ref !== undefined && ref.deref() === undefined`? Since when a same name WeakRef is added both ref and ref.deref() will be defined.
-
Thanks! Updated the post
End of conversation
New conversation -
-
-
"Note: The finalization callback does not run immediately after garbage-collecting the image object. It either runs at some point in the future, or not at all — the spec doesn’t guarantee that it runs!" Why no guarantee?
-
It can provide side-channel attacks, and not all JS engines even have a GC in the first place.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
Weak references and finalizers are (finally) coming to JavaScript!