Save Object.observe()! (please) + make WeakMap/WeakSet observable.
Romuald Quantin
romu at soundstep.com
Thu Nov 5 08:41:19 UTC 2015
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 <coroutines at gmail.com> wrote:
> On Wed, Nov 4, 2015 at 2:36 PM, Rick Waldron <waldron.rick at gmail.com>
> wrote:
>
> > On Wed, Nov 4, 2015 at 8:16 AM Coroutines <coroutines at gmail.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151105/9175e0ce/attachment.html>
More information about the es-discuss
mailing list