Calling toString on function proxy throws TypeError exception
Thomas Greiner
thomas at adblockplus.org
Thu Oct 22 11:39:11 UTC 2015
According to
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString
`Function.prototype.toString` is supposed to throw a `TypeError` exception
when used on a function proxy. That's also consistent with how it's defined
at
http://www.ecma-international.org/ecma-262/6.0/#sec-function.prototype.tostring
but presumably only because the Proxy scenario is not explicitly mentioned.
The problem I see with that is that it makes proxies distinguishable from
their targets even if they don't specify any traps. At least in cases where
the mere existence of a proxy needs to be kept secret, this introduces a
severe limitation.
That behavior also goes against the "transparent virtualization" principle
as outlined by Axel Rauschmayer (see
http://www.2ality.com/2014/12/es6-proxies.html#transparent_virtualization_and_handler_encapsulation
):
> Proxies are shielded in two ways:
>
> - It is impossible to determine whether an object is a proxy or not
(transparent virtualization).
> - You can’t access a handler via its proxy (handler encapsulation).
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151022/855f5ad8/attachment-0001.html>
More information about the es-discuss
mailing list