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

Brandon Benvie brandon at
Mon Nov 12 15:10:08 PST 2012

A better trap than getOwnPropertyDescriptor would be something like "query"
which is used to look up the attributes of a property and its existence.
 JS shies away from constants generally, and especially numeric ones, but
this is a place I have found really benefits from a bitfield.

const ENUMERABLE = 0x01,
      CONFIGURABLE = 0x02,
      WRITABLE = 0x04
      ACCESSOR = 0x08;

const E__ = 1,
      _C_ = 2,
      EC_ = 3,
      __W = 4,
      E_W = 5,
      _CW = 6,
      ECW = 7,
      ___A = 8,
      E__A = 9,
      _CA = 10,
      ECA = 11;
function query(target, property){
  // returns a value corresponding to the own property attributes, or
undefined if no own property

"has" is removed in favor of hasOwn and proto walking
"hasOwn" is then replaced with query, where undefined means false and any
value corresponding to a flag is true
"getOwnPropertyDescriptor" becomes a "query" followed by "get" or "set" if
the query result isn't undefined

The one loss is this prevents custom descriptor attributes. That seems like
a fringe use case to me though. The benefit is the removal of all the
traffic back and forth allocating objects and internal descriptors. It also
reduces the number of traps and separates the concerns of property values
from property attributes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list