Tech talk on proxies and traits

Faisal Vali faisalv at
Sat May 1 12:34:36 PDT 2010

---------- Forwarded message ----------
From: Faisal Vali <faisalv at>
To: "Mark S. Miller" <erights at>
Date: Sat, 1 May 2010 14:10:01 -0500
Subject: Re: Tech talk on proxies and traits
On Sat, May 1, 2010 at 12:29 PM, Mark S. Miller <erights at> wrote:
> On Sat, May 1, 2010 at 9:29 AM, Faisal Vali <faisalv at> wrote:
>> I do have one request for clarification regarding the object 'proto'
>> supplied during proxy creation:
>> (i.e. Proxy.create(handler, proto))
>> Before a proxy has been fixed, the 'proto' is invisible to all
>> accesses and mutations on proxy (i.e they are all delegated to the
>> handler). Correct?
> Oh, and yes, this is correct.
>> So It seems to me that the 'proto' object serves only two purposes -
>>  1) 'proto' is returned when one calls 'Object.getPrototypeOf(proxy)'
>>  2) When a proxy gets 'fixed', the 'proto' object is made the
>> 'fixed-proxys's prototype - and all subsequent accesses not explicitly
>> handled by the 'fixed-proxy' will be forwarded to the 'proto'

> Yes, these two. And one more thing I can think of:
> 3) proxy instanceof Foo
> uses proxy's proto to determine if proxy is an instance of Foo.

Thanks for the clarification Mark.

As I read the proposal, I do wish an invoke-like trap had been
accepted - but I understand that there were some technicalities that
proved unresolvable.

It might be useful to be able to tell when someone was accessing a
property as a function call:

str_proxy.length -vs- str_proxy.length() -vs- -vs- { filter : '....' } )

I realize that maintaining the invariant of "o.m(a) is equivalent to
var f = o.m;,a)" is advisable - but are we certain that it
should be mandatory in the setting of proxies (i.e represent a true
invariant)? In the world of proxies (or for that matter 'get'
accessors in es5) we can't even guarantee that two sequential accesses
of the same property will return the same value, object or function.
There is convenience to being able to type either proxy.length or
proxy.length() and have it do the right thing.

Since I do not have that much experience with interceptors, it is too
early for me to say that preventing the 'get' handler from
distinguishing whether a property is about to be 'called' is
definitely a loss in expressivity.  I sense it might be useful to have
that feature.  A simple solution that would allow maintaining the
above mentioned 'invariant' in most cases and allow breaking it when
necessary would involve a flag passed into the 'get' handler
indicating that the property is about to be 'called'.  What would be
the negative ramifications of such a solution (asides from the fact
that it may get abused - like the 'get' accessor in es5 ;)?


Faisal Vali
Radiation Oncology

More information about the es-discuss mailing list