Type of property names, as seen by proxy traps

David Bruant david.bruant at labri.fr
Thu Jul 7 06:09:44 PDT 2011


Le 07/07/2011 14:40, Andreas Rossberg a écrit :
> On 7 July 2011 14:32, David Bruant<david.bruant at labri.fr>  wrote:
>> However, if we assume that the getOwnPropertyNames trap is able to do type
>> coercion on its output, there is no reason for the keys trap to not do that
>> too, regardless of how it was implemented.
> Yes, that's what I would propose, too. It's just a bit ugly that we
> have to do that in two places now.
Three if counting the "enumerate" trap for for-in loops. Regardless of 
ugliness, it's necessary. keys and enumerate are derived traps. They 
have a default implementation for developer convenience, however, 
developers could decide to reimplement the trap and the proxy engine 
implementation have to enforce types anyway. Each trap has to be guarded 
independently.
Derived traps as showed are written in JS for expository purposes. 
Engines will be free to optimize as they wish internally as long as the 
observed behavior is the same. Specifically, I think that type inference 
engines can be of a great help in ensuring that types are correct 
without having to pay the price of looking at every single element 
independently.

David


More information about the es-discuss mailing list