Calling toString on function proxy throws TypeError exception

Brian Terlson Brian.Terlson at microsoft.com
Thu Oct 22 18:18:38 UTC 2015


Proxies without handlers are not indistinguishable from their targets. There are many examples, eg. `let p = new Proxy(new Map(), {}); p.set(1, 1);` also throws.

From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Thomas Greiner
Sent: Thursday, October 22, 2015 4:39 AM
To: es-discuss <es-discuss at mozilla.org>
Subject: Calling toString on function proxy throws TypeError exception

According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString<https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fdeveloper.mozilla.org%2fen-US%2fdocs%2fWeb%2fJavaScript%2fReference%2fGlobal_Objects%2fFunction%2ftoString&data=01%7c01%7cbrian.terlson%40microsoft.com%7c17838fa9a81040efef5108d2dad58478%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=GOvHpju8FRlkPatB05axAFp7P8G0iRA%2f%2fU8mj%2fqnCX4%3d> `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<https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fwww.ecma-international.org%2fecma-262%2f6.0%2f%23sec-function.prototype.tostring&data=01%7c01%7cbrian.terlson%40microsoft.com%7c17838fa9a81040efef5108d2dad58478%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=Epix453P5jAq8rLpp9sIHXY8AVXtCiP99%2bohNXmf0p0%3d> 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<https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fwww.2ality.com%2f2014%2f12%2fes6-proxies.html%23transparent_virtualization_and_handler_encapsulation&data=01%7c01%7cbrian.terlson%40microsoft.com%7c17838fa9a81040efef5108d2dad58478%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=a4sAwSPF11X28Ck082Ds%2fkFWQH%2f6I%2bgnGO6%2bURwrOM4%3d>):

> 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/6d717ffb/attachment.html>


More information about the es-discuss mailing list