Are Private name and Weak Map the same feature? and the Assoc API

Herby Vojčík herby at mailbox.sk
Mon Dec 19 09:14:38 PST 2011


Hello,

I'd say this is not specialty of get trap. If you don’t know the private 
name itself (and the scenario where you don’t know it but you want to 
forward it is the interesting scenario), you cannot use any API since you 
simply don’t have the name which you could pass. If nothing more, this is 
true for set handler as well (and delete, too, ..., any one that has to deal 
with private name).

Isn’t it?

Herby

-----Pôvodná správa----- 
From: Tom Van Cutsem
Sent: Monday, December 19, 2011 4:50 PM
To: Herby Vojčík
Cc: David Bruant ; Brendan Eich ; es-discuss
Subject: Re: Are Private name and Weak Map the same feature? and the Assoc 
API


2011/12/19 Tom Van Cutsem <tomvc.be at gmail.com>

Calling the trap and catching a special exception is something that we have 
avoided in the proxy design thus far. One possibility is to have the 
"getPrivate" trap return a boolean. If the trap returns false, the proxy 
will forward the private name access. This would allow the getPrivate trap 
to check whether the "public" argument corresponds to one of its own private 
names. If not, it just returns false (no throwing exceptions or calling 
special Proxy.getDefault methods needed).


Sorry, this doesn't work. The getPrivate trap already uses its return value 
to indicate the value of the private name.
So yes, if the getPrivate trap wants to trigger the "default behavior" it 
either has to throw a special exception or return a special unique value to 
indicate this. It's an interesting difference with all other traps, which 
can just perform the default forwarding behavior by calling one of the 
Reflect.* methods. Obviously, we can't provide a Reflect.getPrivate(target, 
public) since that breaks the entire point of the private/public 
distinction. 



More information about the es-discuss mailing list