As far as I can tell, this is a bug in Firefox / SpiderMonkey. The [[CALL]] 
internal method of Proxy objects does not impose any restriction on the type of 
the Proxy target.

The following code behaves correctly in Chromium:

```js
var proxy =  new Proxy({}, { apply(target, thisArgument, arguments) { return 
Reflect.apply(Array, thisArgument, arguments); } });

proxy(1, 2, 3); // [1, 2, 3]
```

But as you say, this throws in Firefox, and based on the specification, this 
appears to be a bug. Implementations, amirite? ¯\_(ツ)_/¯

> On Mar 2, 2016, at 9:19 AM, Claude Pache <[email protected]> wrote:
> 
>> 
>> Le 2 mars 2016 à 13:21, Олег Галабурда <[email protected] 
>> <mailto:[email protected]>> a écrit :
>> 
>> Hi!
>> 
>> I'm currently working on project that allows to manipulate objects passed 
>> from Worker.
>> https://github.com/burdiuz/js-worker-interface 
>> <https://github.com/burdiuz/js-worker-interface>
>> 
>> It creates wrapper objects that record actions applied to this object and 
>> send commands to Worker. The problem is, when request is made I cannot know 
>> what kind of object is this, so in case of function I should give ability to 
>> make calls on the wrapper object.
>> As example, this code:
>> 
>> var api = new WorkerInterface('../webworker.js');
>> api.requestTime();
>> 
>> When "requestTime" was requested, it calls "get" and immediately returns new 
>> Proxy to serve function call. But at time when Proxy is created I do not 
>> know if that is function or not. Now I passed "apply" limitation by adding 
>> wrapper function and make Proxy think it works with function.
>> https://github.com/burdiuz/js-worker-interface/blob/master/source/interface/proxy.js
>>  
>> <https://github.com/burdiuz/js-worker-interface/blob/master/source/interface/proxy.js>
> 
> If I guess correctly your issue, you would like to have something similar to:
> 
>       foo.bar // not-a-function
> 
> and:
> 
>       foo.bar() // a method call
> 
> ? Indeed, that is not possible in JavaScript (and that limitation is not 
> restricted to proxies).
> 
> 
>> I found in discussions why "call" trap was rejected, but didn't find 
>> anything about restricting "apply" trap to functions only.
>> 
> 
> Probably because "X is a function" is, by design, strictly equivalent to "X 
> is callable"?
> 
> —Claude
> 
> _______________________________________________
> es-discuss mailing list
> [email protected] <mailto:[email protected]>
> https://mail.mozilla.org/listinfo/es-discuss 
> <https://mail.mozilla.org/listinfo/es-discuss>

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to