[Proxies] Refactoring prototype climbing in the spec

Tom Van Cutsem tomvc.be at gmail.com
Thu Nov 10 01:26:03 PST 2011

2011/11/9 Allen Wirfs-Brock <allen at wirfs-brock.com>

> On Nov 9, 2011, at 3:53 AM, Tom Van Cutsem wrote:
> - lots of methods on Array.prototype (map, forEach, filter, some, reduce,
> reduceRight, reverse, splice, indexOf, lastIndexOf, every, shift, slice,
> sort, unshift): the only way in which these trigger proxy code is when
> |this| is a proxy, i.e. when they are called as
> Array.prototype.theMethod.call(aProxy).
> (calling aProxy.theMethod triggers the proxy's "get" trap)
> - Array.prototype.concat: [[HasProperty]] is called on a built-in Array
> only.
> the array methods are my primary concern as the HasProperty/Get
> combination is used to preserve "holes" as the algorithms iterate over
> "arrays".  On large arrays, there can be lots of these calls.
> However, I'm not sure I understand your comments about
> theMethod.call(aProxy) vs. aProxy.theMethod(). In either case when
> theMethod is actually executed the this value must be aProxy and the
> internal calls to [[HasProperty]] and [[Get]] need to trap.

You're right, I forgot the "get" trap just traps property access, not the
full method invocation.

The "get" trap could return a bound method, binding theMethod's |this| to
the wrapped array, but that would break inheritance and would forego
intercepting the individual array elements accessed by the bound function.

> - Object environment records uses [[HasProperty]] in a number of
> places. Isn't this needed only for |with|, so only triggered by |with
> (aProxy) { ... }|? Since ES.next builds on ES5/strict, this doesn't seem to
> carry much weight.
> And for global object bindings. It still has to work, consider for
> example, a proxy based DOM object that is accessed from non-Harmony code.
>  The global object, it self, might be a Proxy.

I see. So IIUC, in such a runtime environment, dereferencing a global
variable name would then first trigger the global object's "has" trap,
potentially followed by the "get" trap.

Are you sure you want to kill [[HasProperty]] entirely? If we replace it by
a conditional [[Get]], wouldn't that mean that the expression |name in obj|
might unnecessarily trigger an accessor in obj?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111110/4f217f41/attachment.html>

More information about the es-discuss mailing list