Function.prototype.apply doesn't work on Proxys
Reported by
q...@daurnimator.com,
Mar 16 2016
|
||||
Issue description
UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
Steps to reproduce the problem:
1. Create a new proxy object:
a=new Proxy({}, {"apply":function(ob, self, args) { console.log(self, args); }});
2. Observe that it can be called normally:
a("foo", "arg2") // output: undefined ["foo", "arg2"]
3. Try to call it via Function.prototype.apply or Reflect.apply:
Reflect.apply(a, void 0, ["foo", "arg2"]) // TypeError: Function.prototype.apply was called on [object Object], which is a object and not a function(…)
What is the expected behavior?
Function is called; output of: undefined ["foo", "arg2"]
What went wrong?
A javascript TypeError was thrown
Did this work before? N/A
Chrome version: 49.0.2623.87 Channel: stable
OS Version: ArchLinux
Flash Version: Shockwave Flash 20.0 r0
Proxy is new in Chrome 49.
,
Mar 16 2016
,
Mar 17 2016
,
Mar 17 2016
This behavior is indicated by the spec. To make the proxy callable, back it by a function rather than an empty object. Chrome initially shipped Proxies with a bug which allowed this spec-violating behavior. |
||||
►
Sign in to add a comment |
||||
Comment 1 by q...@daurnimator.com
, Mar 16 2016Seems to work if you give a Proxy target that is a function: a=new Proxy(function(){}, {"apply":function(ob, self, args) { console.log("APPLY", self, args); } }); Reflect.apply(a, "foo", []) output: APPLY foo []