Save Object.observe()! (please) + make WeakMap/WeakSet observable.
Coroutines
coroutines at gmail.com
Wed Nov 4 22:54:59 UTC 2015
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.
More information about the es-discuss
mailing list