Le 27/04/2011 21:15, Sean Eagan a écrit :
> This can also be seen by realizing that if proxyA's handler uses the
> default "get" and "set" trap implementations, and proxyB is proxyA's
> [[Prototype]], then proxyB's "get" and "set" traps will not be called
> due to property access on proxyA, but rather its
> "getPropertyDescriptor" trap.
You're right. "get" and "set" default traps were chosen to follow
closely internal methods (see [1]) and at the time when "proxy" wasn't
an argument of all traps (so a proxy's prototype wasn't reachable from
the handler).
It may be a good idea to rethink default trap implementations by
imposing the recursivity and start from there to rewrite internal methods.
I think that pretty much all proto-climbing traps could be rewritten as:
---
trap: function(/*arguments*/, proxy){
        var res = Object.ownLayerTrap(proxy);
        return satisfying(res)?
          res:
          Object.trap(Object.getPrototypeOf(proxy));
      }
---
The only exception I can think of is "set" which may me slightly more
complicated.

>
> On Wed, Apr 27, 2011 at 1:55 PM, David Bruant <david.bru...@labri.fr> wrote:
>> Oh ok, sorry. So in that case, this is something that has been discussed
>> already a couple of times. The internal object API is a bit inconsistent
>> with proxy traps intentions, especially when it comes to recursive calls
>> to traps on the prototype.
>> If I recall correctly, Allen Wirfs-Brock is working on rewriting object
>> internal methods so that they are both semantically equivalent to what
>> we know and coherent with what we expect from proxies.
>> Maybe we should start filing bugs on the topic at
>> https://bugs.ecmascript.org/ ?
> I believe in this particular case that ES5 already has the correct /
> coherent / expected behavior, the bug happens to be with the proxy
> proposal passing the "receiver" argument.  When an author creates an
> object (or proxy) x, and sets its [[Prototype]] to an object (or
> proxy) y, they are not granting access to x to y.  Since proxies are
> supposed to be as transparent as possible, if y happens to be a proxy,
> the author may not even know this, and so would be surprised to know
> that it now has leaked a reference to x.
Actually, the leak already exists. If y has a "p" property which is an
accessor, then when performing x.p, the |this| binding of "get" and
"set" accessors is x (not y). ES5 8.12.3 [[Get]]:
The descriptor /desc/ has been found *somewhere* in the prototype chain,
/getter/ is extracted from it and O is bound as the |this| value (step 13)
Same deal with [[Put]].
So, proxies do not leak more than ES5 getters/setters do.
Actually, the only place where "receiver" is used in the default get and
set trap is as an argument for desc.get.call or desc.set.call.

David

[1] http://wiki.ecmascript.org/doku.php?id=strawman:proxy_set_trap
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to