Save Object.observe()! (please) + make WeakMap/WeakSet observable.
Mark S. Miller
erights at google.com
Tue Nov 3 03:03:17 UTC 2015
On Mon, Nov 2, 2015 at 6:02 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:
> Not sure I've got your idea right but I think the main point of
> WeakAnything is to forget about GC and have them **not** observable "at all
That is true of WeakMap and WeakSet. But there is a separate WeakReference
proposal in which GC would be observable.
The WeakReference proposal will once again be visible if wiki.ecmascript.org
ever comes online again. What is the prognosis for that? There are many
strong references into that wiki, so it should not have been collected.
> .... unless I've misunderstood the intent itself, Object.observe as it has
> been proposed wouldn't help much anyway.
> On Mon, Nov 2, 2015 at 10:34 PM, Coroutines <coroutines at gmail.com> wrote:
>> I was referred to es-discuss after filing a feature request here to
>> support observing WeakMaps and WeakSets. (
>> https://bugzilla.mozilla.org/show_bug.cgi?id=1206584 )
>> I was linked this message:
>> Please save Object.observe().
>> When I read that above posting it sounds like O.o() is to be removed
>> because it has not been popularly used. It is proposed for ES7 - it's
>> not even part of an accepted standard yet. I think it's strange to
>> remove something because it's not used much... because it's
>> experimental. Who would depend on something non-standard? Sure
>> there's a polyfill but it polls an object for changes with timers -
>> this sounds ridiculously inefficient. If it doesn't get accepted
>> there will be no way to watch changes as they happen, instead of after
>> the fact.
>> I come from Lua. In Lua we make proxy objects with metamethods. You
>> create an empty table/object and define a metatable with a __index and
>> __newindex to catch accesses and changes when a key/property doesn't
>> exist. I would primarily use this in sandboxes where I wanted to
>> track the exact series of operations a user was performing to modify
>> their environment (the one I'd stuck them in). The important part to
>> remember is that I didn't know what properties of which objects they
>> would be accessing. I couldn't just define a static list of getters
>> and setters and hope they make use of my limited, catching interface.
>> I think Object.observe() is very important for situations where you
>> want to watch all changes, because you don't know which properties
>> will be used.
>> I have a further proposal: I wish it were possible to watch changes
>> on WeakMaps and WeakSets.
>> In Lua you can have weak references by setting the __mode = 'kv' (k
>> for key, v for value) in the object's metatable. The only way I could
>> get weak references in JS was with WeakMaps and WeakSets. Lua also
>> lets you set a __gc in the metatable to handle when a pair is
>> collected by the GC. I wanted the ability to "see" when memoized
>> function calls are forgotten, but I can't do that with just
>> Object.observe() - as you can't observe a WeakSet or WeakMap. I'd
>> love for this to be possible.
>> For debugging reasons it would be excellent to be able to watch when
>> things get collected (through weak references). Finalizers in general
>> would be nice. I mean in the sense that I want to do something
>> independent of the object being collected, not that I need to destroy
>> the object in a special way before collection. I feel like there's a
>> vague difference between finalizer and destructor.
>> Please save Object.observe(), make WeakMap/WeakSet observable, and
>> save the whales too or something.
>> Toodles ~
>> es-discuss mailing list
>> es-discuss at mozilla.org
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss