[[Invoke]] and implicit method calls

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Sep 10 09:11:55 PDT 2013


On Sep 10, 2013, at 8:20 AM, Jason Orendorff wrote:

> On Tue, Sep 10, 2013 at 6:31 AM, Domenic Denicola
> <domenic at domenicdenicola.com> wrote:
>> Note that determining desired pattern is relevant to the new DOM promises design (tracking this at https://github.com/domenic/promises-unwrapping/issues/25). Omitting a few steps not relevant to the issue under discussion, currently we do:
>> 
>> - Let `then` be `Get(potentialThenable, "then")`.
>> - If `IsCallable(then)`, call `then.[[Call]](potentialThenable, (resolve, reject))`.
>> 
>> It seems like we'd want to apply the same logic here as we do to `valueOf` etc., which is what I tried to model this after.
> 
> I think the simplest thing would be to replace [[Invoke]] with a
> [[GetMethod]] trap, and the idiom would then be exactly as above, but
> change `Get` to `GetMethod`.
> 
> The last step of Invoke(O, P, args) would be replaced with:
> 
>  6. Let method = O.[[GetMethod]](P, O).
>  7. ReturnIfAbrupt(method).
>  8. If IsCallable(method) is false, throw a TypeError.
>  9. Return method.[[Call]](O, args).

Having to create a new bound function on every method call seems too expensive.  But what about:

 6. Let method = O.[[Get]](P).
 7. ReturnIfAbrupt(method).
 8. If IsCallable(method) is false, throw a TypeError.
 9. Return O.[[InvokeFunction]](method,O, args).

Using [[InvokeFunction]] the Proxy still mediates the [[Call]] to method but it is assume the [[Get]] step has already been performed and has produced method.

Allen




More information about the es-discuss mailing list