[Harmony proxies] "if a trap is missing"

David Bruant bruant.d at gmail.com
Thu Dec 8 07:10:36 PST 2011

Le 07/12/2011 21:21, Tom Van Cutsem a écrit :
> 2011/12/6 David Bruant <bruant.d at gmail.com <mailto:bruant.d at gmail.com>>
>     "All traps are optional. If missing (more precisely, if
>     handler[trapName] returns undefined), the proxy defaults to forwarding
>     the intercepted operation to its target object." [1]
>     Proxy({}, {get:undefined}).someProperty;
>     In this case, the description says that the operation is forwarded. I
>     would prefer a TypeError to be thrown in this case.
> To do this, the proxy would need to test whether the trap actually
> exists, by performing an "in" test on the handler.
> This breaks the double lifting pattern [1], which depends on the only
> interaction between the proxy and the handler being property access.

> Aside from that main issue, I think it would be odd for
> Proxy({},{}).foo to just work while Proxy({},{get:undefined}).foo
> would fail with a TypeError.
On one hand I like when the language throw errors (I'm aware I'm not a
majority with this point of view)
On the other hand, while writing handlers, it can be a very good
practice to explicitely state {trap:undefined} to be sure that the
intention of the programmer was to have the default behavior.

So yeah, undefined-as-a-value and property non-existence having the same
behavior is a good idea indeed.

> [1] See <http://wiki.ecmascript.org/doku.php?id=harmony:reflect_api>,
> last code snippet under "Forwarding".

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111208/62a8c3ad/attachment.html>

More information about the es-discuss mailing list