Direct proxies strawman

Tom Van Cutsem tomvc.be at gmail.com
Mon Oct 17 12:15:17 PDT 2011


Hi,

A couple of weeks ago, Mark and I sat together to work on a number of open
issues with proxies, in particular, how to make proxies work better with
non-configurable properties and non-extensible objects. The result is what
we call "direct proxies": in our new proposal, a proxy is always a wrapper
for another "target" object. By slightly shifting our perspective on proxies
in this way, many of the earlier open issues go away, and the overhead of
proxies may be substantially reduced in some cases.

I just finished a first draft of the strawman: <
http://wiki.ecmascript.org/doku.php?id=strawman:direct_proxies>. Feedback
welcome.

A prototype implementation that builds upon FF7 proxies is available also: <
http://code.google.com/p/es-lab/source/browse/trunk/src/proxies/DirectProxies.js
>
(note: I still need to thoroughly test this code, but it's otherwise an
accurate description of the semantics of direct proxies in terms of current
proxies.)

Mark and I will present this proposal in detail at the TC39 November
meeting. In the meantime, it may use some es-discuss eyeballs.

To whet your appetite, some advantages of direct proxies w.r.t. the current
proposal:
- Enable emulation of non-configurable properties.
- Enable emulation of non-extensible, sealed and frozen objects.
- Proxies inherit [[Class]] from target. Enables faithful wrapping of Host
objects, Arrays, etc.
- “Fixing” a proxy (i.e. stopping the handler from trapping), is decoupled
from “protecting” a proxy (making it non-extensible, sealed or frozen).
- No need to distinguish between object and function proxies anymore.
- All traps become optional.
- Wrapping an existing object using a direct proxy creates less overhead, no
need to pass through an explicit ForwardingHandler anymore.
- Proxies can't violate non-configurability / non-extensibility
invariants. This in turn enables safe transformation of regular objects into
proxies (Proxy.attach)
- The default forwarding handler becomes a stateless singleton object.

Also, thanks to David Bruant for being an early sounding board and providing
some useful API tweaks.

Cheers,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111017/8f11b4ca/attachment.html>


More information about the es-discuss mailing list