Le 11/04/2011 22:01, Brendan Eich a écrit :
> On Apr 11, 2011, at 8:58 PM, David Bruant wrote:
>
>> Le 11/04/2011 21:47, Brendan Eich a écrit :
>>> On Apr 11, 2011, at 6:36 PM, Allen Wirfs-Brock wrote:
>>>
>>>> Personally, I prefer Object.getOwnPropertyDescriptor as a property
>>>> existence test because it doesn't have the reflection the meta-circularity
>>>> concern. I would write Dave's original function as:
>>>>
>>>> function getDefiningObject(obj, key) {
>>>> var obj={}.valueOf.call(obj); // ToObject in case primitive value passed
>>>> while (obj) {
>>>> if (Object.getOwnPropertyDescriptor(obj,key)) return obj;
>>>> obj = Object.getPrototypeOf(obj);
>>>> }
>>>> throw new Error("key " + key + " not found");
>>>> }
>>> Then the only downside is the pd allocation. Any way to avoid that?
>> Could static analysis help out to detect that the object is not going to
>> be used and consequently avoid the allocation?
> Of course, but that's a bit much and unless it is adopted by all the "bigs",
> web developers won't count on it and may shy away from the allocation (based
> on real measurements or premature optimization, doesn't matter).
Actually I was wrong I think. With the introduction of proxies, ES
engines won't be able to trivially prevent pd allocation as they could
with regular objects just based on static analysis (since static
analysis will often fail at saying whether the function will be used
with regular objects or proxies as first argument)
> It's not the end of the world to have a pd allocation, of course. But an API
> that avoids it without analysis might be worth considering.
I think it could be possible if we had a native Object.hasOwnProperty
method since that's really what we need here (that's what a static
analysis optimization would do internally).
David
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss