Proxies: wrong "receiver" used in default "set" trap

Tom Van Cutsem tomvc.be at gmail.com
Thu Dec 20 02:21:09 PST 2012


2012/12/19 Allen Wirfs-Brock <allen at wirfs-brock.com>

> If we make the Option A change that seems right for  [[GetP]]/[[SetP]]
> then we will have an inconsistency between the this value used for a method
> invoked as proxy.foo() and a accessor invoked as proxy.bar
>

To clarify, if we apply the fix to [[SetP]] described in my previous
message, the following remains the default forwarding behavior of proxies:

If target.foo is a method:
proxy.foo() will call target.foo() with |this| bound to the proxy (i.e.
Lieberman-style delegation)

If target.bar is an accessor:
proxy.foo will call the target.foo getter with |this| bound to the proxy
(delegation)
proxy.foo = 42 will call the target.foo setter with |this| bound to the
proxy (delegation)

If target.baz is a writable data property
proxy.baz = 42 will eventually call Object.defineProperty(proxy, 'baz',
{value:42})
(and *not* Object.defineProperty(proxy, 'baz',
{value:42,enumerable:true,writable:true,configurable:true}) as it did
previously)
This behavior is consistent with the method and accessor case: in all
cases, the target delegates back to the proxy.

This bears repeating: the above are only defaults, and proxy authors are
free to change the policy by actually implementing traps and taking control.

One thing that I learned from all this is that it's simpler to think of the
proxy as *delegating* (as opposed to forwarding) to its target by default.
And under the semantics of invoke = get + apply, that is actually the
simplest option.

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


More information about the es-discuss mailing list