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

Tom Van Cutsem tomvc.be at gmail.com
Wed Nov 14 00:33:53 PST 2012


2012/11/13 Erik Arvidsson <erik.arvidsson at gmail.com>

> On Tue, Nov 13, 2012 at 3:25 PM, Tom Van Cutsem <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?
>

I would subscribe to this point of view if only all derived traps were as
trivial to remove as the "has" or "hasOwn" traps that were brought up by
Allen in this thread.

Looking at the full list of fundamental vs derived traps <
http://wiki.ecmascript.org/doku.php?id=harmony:virtual_object_api>, it
quickly becomes apparent that there are far more derived than fundamental
traps. It'll be a challenge to try and get rid of all derived traps.

Now scroll down to the "non-normative implementation" section of that wiki
page and have a look at the default implementation of "hasOwn". It's only 3
lines, making it by far the shortest derived trap. Many of the other ones
(e.g. keys() and enumerate()), perform spurious property descriptor
allocations in a for-loop, making the allocation overhead linear instead of
constant.

As Allen mentioned himself, the "hasOwn" trap was a good case to bootstrap
the discussion because of its simplicity: it's easy to understand the
inconsistencies, it's easy to get rid of, and the extra allocation cost is
minimal. The story is not so simple for the other derived traps.

All of this is just to adjust the bias that getting rid of all derived
traps would be an easy thing to do.

Cheers,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121114/d69c0d0a/attachment-0001.html>


More information about the es-discuss mailing list