Do we really need the [[HasOwnProperty]] internal method and hasOwn trap

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Nov 14 09:25:08 PST 2012


On Nov 13, 2012, at 10:35 PM, Brendan Eich wrote:

> Erik Arvidsson wrote:
>> On Tue, Nov 13, 2012 at 3:25 PM, Tom Van Cutsem <tomvc.be at gmail.com <mailto:tomvc.be at gmail.com>> wrote:
>> 
>> 
>>    So, my proposal: let's revert the fundamental traps of Handler to
>>    become abstract methods again. This forces subclasses of Handler
>>    to provide all fundamentals at once, avoiding the footgun.
>> 
>> 
>> Maybe we should skip the derived traps for ES6 and see if the extra allocation really becomes an issue in reality? This way we are keeping the API smaller and the risk of errors lower. We can always add the derived traps later, can't we?
> 
> Allocations always matter, in my experience -- even with V8.
> 
> Also Tom's point about precision counts, independent of allocations. A "hasOwn" test in the MOP should not call the same thing that Object.getOwnPropertyDescriptor calls, if we can help it -- especially without a flag argument to hint the difference, but that flag argument is blecherous anyway.
> 

A less blecherous flag might be as follows
 
getOwnPropertyDescriptor: function(target, name, populate=true) -> desc | undefined

If populate is false, the returned property descriptor doesn't need to be populated with the properties that describe attributes.  In that case it must be a frozen object.

This allows a preallocated descriptor to be used to indicate the existence of a property.  It also removes the blechiness of using an argument to steer the return type of the function.

Allen





More information about the es-discuss mailing list