Proxy forwarding handlers and accessor properties

David Flanagan dflanagan at mozilla.com
Thu Jun 16 23:42:40 PDT 2011


On 6/16/11 5:20 PM, David Bruant wrote:
> Le 17/06/2011 01:54, David Flanagan a écrit :
>>
>> // When we create a proxy with a forwarding handler, though, the this
>> value
>> // is different in the two cases.
>> var handler = {
>>      target: o,
>>      get: function(receiver, name) {
>>          return this.target[name];  // Same as Proxy.Handler.prototype.get
>>      }
>> }
> If you get rid of the "get" trap (you need a getOwnPropertyDescriptor
> trap though), the default get (derived) trap will be called instead and
> basically do what you do afterward (call to getOwnPropertyDescriptor
> trap which will call Object.getOwnPropertyDescriptor(this.target,
> name)+d.get.call(receiver)). The 'this' binding is performed by the
> engine (with the receiver as value) after the property descriptor has
> been returned (as explained in strawman:proxy_drop_receiver).
>
Thanks.  I didn't realize that the default get behavior was to do what I 
put in my second handler.

Still, my basic question remains, though: is it a bug that a forwarding 
proxy created with Proxy.Handler behaves differently in this way (this 
value in methods is different than the this value for accessors) than 
the object to which it forwards?

(Originally I had a second question about the proposed removal of the 
receiver argument, but now I understand that that strawman is contingent 
on the addition of a proxy argument to the handler methods, so let's 
disregard that second question...)

     David
> I've come across a similar issue (it was a set VS defineProperty issue,
> but basically used the same solution). One suggested solution is written
> down on the wiki at strawman:derived_traps_forwarding_handler
>
> Cheers,
>
> David
>



More information about the es-discuss mailing list