After marinating for a few months, my JSConf.eu slides:
Harmony Proxies are already prototyped in Firefox 4 betas, thanks to Andreas Gal.
When I reached the “meta-level shifting” slide:
The money-shot slide in my view is:
which depicts how Proxies finally level the playing field between browser implementors using burned-into-browser-binaries C++ and web developers using downloaded JS.
It’s hard to overstate how this matters. The DOM (IE’s for sure, but all of them, back to the original I hacked in Netscape 2) suffers from its “VM territory” privileges, which have been abused to make all kinds of odd-ball “host objects”. Proxies both greatly reduce the weirdness of host objects and let JS hackers emulate and even implement such objects.
Novice JS hackers and all JS programmers happy at the base level of the language need not worry about the details of Proxies. Proxies cannot break the invariants that keep the JS lucid dream unfolding on stage. Specifically, you can’t hack traps onto an existing non-proxy object — you can only create a new proxy and start using it afresh, perhaps passing it off as a preexisting kind of object that it emulates .
But when you need to go backstage of the dream and change the rules without breaking the dreamer’s illusion, by interceding on every
construct, etc., then Proxies are indispensable.
Firefox 4 is using Proxies to implement all of its security wrappers.
Long-time SpiderMonkey fans will ask “why no
__noSuchMethod__” (or: why not also have a
invoke trap, or a flag to
get telling when it is trapping a get for the entire callee part of a call expression)? The short answer is to keep the set of handler traps minimal in terms of JS semantics (modulo scalability), which do not include “invoke-only methods”. The longer answer is on es-discuss.
 Inside the engine, a clever trick from Smalltalk called
becomes is used to swap a newborn Proxy and an existing object that has arbitrarily many live references. Thus an object requiring no behavioral intercession can avoid the overhead of traps until it escapes from a same-origin or same-thread context, and only if it does escape through a barrier will it become a trapping Proxy whose handler accesses the original object after performing access control checks or mutual exclusion.
The local jargon for such object/Proxy swapping is “brain transplants”.