[Proxies] Refactoring prototype climbing in the spec

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

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

> On Nov 10, 2011, at 1:36 AM, Tom Van Cutsem wrote:
> - Object.getProperty and Object.setProperty built-ins that call
> [[GetProperty]] and [[SetProperty]]
> Also, to fully reify property manipulation I think we also need to factor
> [[Delete]] in a similar manner and provide an Object.deleteProperty
> built-in that calls the DeleteProperty abstraction operations.
> I touch upon this in
> http://wiki.ecmascript.org/doku.php?id=strawman:object_model_reformation#a_side_note_on_reflective_property_access (note
> that this stawman is still under construction)
> the basic reason is that just like with Get/Put a handler may want to
> invoke the primitive behavior of Delete upon the target object without
> going through the delete operator (which could retrigger a trap).

Actually I was mistaken: the above quoted line should read:

- Object.getProperty and Object.setProperty built-ins that call the [[Get]]
and [[Set]] methods

In other words: it's important that Object.getProperty(aProxy, name)
triggers that proxy's "get" trap rather than performing the Object
algorithm and calling the getOwnPropertyDescriptor trap.
Otherwise, proxies would not compose well (think of a proxy p1 wrapping
another proxy p2: if p1 forwards a property access to its target (p2), p2's
"get" trap should be triggered).
(+ we could end up with duplicated getOwnPropertyDescriptor calls, as
pointed out by David earlier)

If the goal is to intentionally avoid proxy traps, one can write up the
algorithm in Javascript itself (as I have done on the strawman page). But I
think it's important that Object.getProperty does trigger proxy traps (if
only for consistency: Object.getOwnPropertyDescriptor et al. also trigger
proxy traps).

Regarding property deletion: if an object is implemented as a proxy, and
you would want to delete a property from that object, I'm not sure why you
would want to circumvent triggering the delete trap?

> - [[Get]] and [[Set]] methods on Objects that call [[GetProperty]] and
> [[SetProperty]]
> - [[Get]] and [[Set]] methods on Proxies that trigger "get" and "set" traps
> Yes, although I prefer to think of [[Get]] and [[Set]] consistently for
> both Proxy and "normal" objects.  They are polymorphic "traps" that
> dispatch to a handler that is determined by the nature of the object.  For
> native objects [[Get]] and [[Set]] dispatch to handlers that just call
> GetProperty or SetProperty

Do you mean that the direction you would like to go is to look at normal
ES5 objects as proxies with a special, built-in handler?

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

More information about the es-discuss mailing list