Save Object.observe()! (please) + make WeakMap/WeakSet observable.
Brendan Eich
brendan.eich at gmail.com
Thu Nov 5 16:32:20 UTC 2015
Read esdiscuss.org, use Google site: search, before complaining that you
don't understand why something is not "enabled". Here's a link:
https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site%3Aesdiscuss.org%20weak%20reference
It's not hard to find the full history of the discussion.
/be
On Thu, Nov 5, 2015 at 12:41 AM Romuald Quantin <romu at soundstep.com> wrote:
> 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
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151105/0245c251/attachment.html>
More information about the es-discuss
mailing list