[[Invoke]] vs [[Get]]

Till Schneidereit tschneidereit at gmail.com
Sat Jun 8 04:13:49 PDT 2013

I just saw that Jason identified some additional open questions in [1]:

1. What happens when we call a method on an object whose [[Prototype]] is a
proxy with an invoke trap?

    var p = new Proxy({}, {invoke: ...});
    var q = Object.create(p);

Does this trigger p's invoke trap?

2. What happens when a proxy with an invoke trap is used in a with-block?

    with (p)

3. When exactly do we check for an invoke trap, and when do we call it? How
does that affect 11.2.3?

In an expression like p.f(), do we still evaluate "p.f" as in 11.2.3 step 1?

Seems like 1. should behave as the equivalent situation with a [[Get]]
handler does. 2. makes me shudder, but also seems like it pertains to
[[Get]] in just the same way. 3. seems somewhat difficult to deal with,
indeed. Maybe a new abstract operation `GetFunction` or `GetCallable`
should be introduced, with step 1 of 11.2.3 reformulated in terms of that?
I'm not sure how best to factor that step, though. Another solution could
be to introduce the concept of a boolean `InCallingContext` to,
`GetValue` and change its step 5 like this:

b. If InCallingContext is false, then return the result of calling the
[[Get]] internal method of base passing GetReferencedName(V) and
GetThisValue(V) as the arguments.
c. Else return the result of GetMethod passing GetReferencedName(V) and
GetThisValue(V) as the arguments.

I'm not well-versed enough in reading the spec to know how well that fits
into the big picture.

[1]: https://bugzilla.mozilla.org/show_bug.cgi?id=878605#c4

On Sat, Jun 8, 2013 at 12:30 PM, Till Schneidereit
<tschneidereit at gmail.com>wrote:

> At the last TC39 meeting, an agreement was reached for proxies to support
> an Invoke trap. I'm currently implementing this trap in SpiderMonkey[1] and
> realized that there's one conceptual issue that has to be decided in the
> spec:
> Currently, the [[Get]] trap naturally handles method calls on the proxies,
> as these are gets followed by calls to the returned function value. With
> proxies also being able to trap [[Invoke]], things become less clear, with
> four possible options:
> 1. for method calls, only the [[Invoke]] trap is called
> 2. if an [[Invoke]] handler exists, it is called, otherwise a [[Get]]
> handler is called, if that exists
> 3. like 2., but additionally, if the [[Invoke]] handler doesn't return a
> callable value, the [[Get]] handler is called
> 4. like 3., but with reserved order of handler invocation: if a [[Get]]
> handler exists, it is called. If the result isn't callable, or [[Get]]
> isn't handled, an [[Invoke]] handler is called, if one exists
> The first of these options seems conceptually cleanest to me, but I do
> think that the other options (perhaps except for the last one) can be
> argued for to some extend, too: the abstract operation `Invoke`, via its
> step 5, `GetMethod`, contains a call to the [[Get]] operation, after all.
> [1]: https://bugzilla.mozilla.org/show_bug.cgi?id=878605
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130608/72dc1b67/attachment.html>

More information about the es-discuss mailing list