Someone made an experiment with the Mozilla “getWeakReference” apparently.
https://gist.github.com/Benvie/7123690 https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.getWeakReference I had this as granted with other languages, I still don’t understand why has this not been enabled by default in javascript. On 4 November 2015 at 22:54, Coroutines <[email protected]> wrote: > On Wed, Nov 4, 2015 at 2:36 PM, Rick Waldron <[email protected]> > wrote: > > > On Wed, Nov 4, 2015 at 8:16 AM Coroutines <[email protected]> wrote: > > >> obj[Symbol.weakValues] = true; > >> obj[Symbol.weakProperties] = true; > > > 2. For security purposes, only code that has been explicitly given > access to > > _both_ the weakmap and a key may gain access to the value stored within > the > > weakmap. This is why there is no enumeration—if there were, then any code > > that could access the weakmap could then also access all of the keys and > > values. If that's a desirable trait, then just use a Map. > > > > These things cannot be done with Proxy, because anything that Proxy does > > will inevitably be a strongly held reference. > > Well, you explained the mystery behind why WeakMap can't be iterated > over - but I was saying I would combine Proxy with a theoretical > Symbol for marking keys and/or values as weakly-referenced to create > WeakSet and WeakMap (if I wanted). I think I just prefer Lua in this > area: > > local tmp = setmetatable({ 'a', 'b', 'c' }, { __mode = 'v' }) > > for k, v in ipairs(tmp) do > print(k, v) > end > > 'a', 'b', and 'c' are weakly-referenced and can be iterated over, will > be marked by the next GC step, and will not survive the next GC > collection cycle. I wish JS let me create weak references as simply: > > var tmp = [ 'a', 'b', 'c' ] > > tmp[Symbol.weakValues] = true; > > This is what I was saying :> I understand that you need both a > reference to the WeakMap and the object you're using as a "weak key" > but I think it could be iterable if the weak references have not been > broken yet - if the objects in that WeakMap have not been collected > yet. I would not want "permanently" strong references with a Map. > -- www.soundstep.com
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

