Calling toString on function proxy throws TypeError exception
Tom Van Cutsem
tomvc.be at gmail.com
Wed Oct 28 19:01:21 UTC 2015
2015-10-27 12:47 GMT-04:00 Jordan Harband <ljharb at gmail.com>:
>
> Shouldn't tests in existing code that rely on `Function#toString` not
> throwing to indicate that something is callable, or throwing to indicate
> that it is not, remain true for a function proxy?
>
Excluding some host objects (as Boris pointed out), I think this does
capture the programmer's expectation in the common case.
When I wrote my Proxy shim for ES5 <
https://github.com/tvcutsem/harmony-reflect/>, I got feedback from
developers to patch F.p.toString() to please unwrap the proxy, as this
seemed to be the general expectation (just like Array.isArray should return
true for proxies-for-arrays).
I don't have a strong opinion on whether F.p.toString() should drill
through the proxy or just return "function() { [...] }", but would really
like it not to throw. A function proxy is, for all intents and purposes, a
valid function. Having F.p.toString report that it is called on an
"incompatible object" just feels wrong.
Even though just calling toString() would work fine on a membraned function
proxy, the idiom of storing built-in functions in variables and explicitly
.call()-ing those built-in functions is, to my understanding, still very
common.
Cheers,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151028/776d2008/attachment.html>
More information about the es-discuss
mailing list