es7 proposal/polyfill?: base Map/WeakMap off Proxy + Weak References

Mark S. Miller erights at google.com
Fri Feb 19 09:47:13 UTC 2016


On Fri, Feb 19, 2016 at 1:17 AM, Coroutines <coroutines at gmail.com> wrote:

> Hi - I hope I am not suggesting something that has been said before ~
>
> Having Proxy and eventual Weak References makes it possible to build
> Map/WeakMap in plain JS - nothing in hidden, 'native code' (C++).
>

Not quite. This is why ephemeron collection makes such a difference. It can
collect cycles that no arrangement of maps and weak references can collect.
In particular, ephemerons are *essential* to build identity-preserving
membranes with both necessary gc properties:

* While the membrane is up, collect across the membrane transparently, as
if the membrane were not there.
* When the membrane is revoked, sever the reachability of all links
crossing the membrane. A compartment fully inside the membrane can then be
fully collected.

If you don't use ephemeron collection and you use the non-transposed
representation, you will fail to collect membrane crossing cycles.
If you don't use ephemeron collection and do use the transposed
representation (as MS Edge currently does) then you will fail to sever
reachability on revocation, failing to collect logically unreachable
compartments.

Since collection across the membrane needs to happen much more often than
cleaning up after revocation, best is ephemeron collection with the
(Edge-like) transposed representation. Ephemeron collection without the
transposed representation (as I think everyone but Edge currently does)
makes normal collection across the membrane boundary much more expensive.
But at least it does eventually clean up both kinds of garbage.



>
> I'd like to propose basing them off of these when Weak References are a
> 'thing'.
>
> Map's API could just go away and follow traditional Object assignment
> and existence checks:
>
> map[key] = value;
>
> // wish JS had a null-coalescing `?` operator like Coffeescript..
> if (map[key] !== undefined || map[key] !== null) { ... }
>
> It's totally legal in non-Node JS to have Objects as keys in other
> Objects, right? (I forget)
>
> So that's my idea.  Toodles ~
>
> PS: And build Set off of a Proxy + Array.  Just stop being weird. :P
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160219/9ae8a3db/attachment.html>


More information about the es-discuss mailing list