Property descriptors as ES6 Maps

David Bruant bruant.d at
Wed Oct 31 02:40:10 PDT 2012


I've recently filed a spec bug [1] and given more thoughts about it that
goes beyond the suggested restructuring so I'm bringing it up here. This
posts ends up with an unresolved issue, but I hope a solution can be found.

Let's talk about property descriptors. Currently, in the spec, property
descriptors have their own type (with "fields" and accessing things in
these fields). It's a type that matches very well with objects, so the
mapping with Object.defineProperty input and
Object.getOwnPropertyDescriptor is rather obvious.
However, when we think about proxy traps, the proxy traps can't have
access to an abstract data structure, so the proxy spec uses regular
objects for trap communication.

My bug was about making the use of objects official in the spec
internals... until I realized that ES6 has maps.
I'm writing to propose a change which is to make property descriptor ES6
maps both inside the traps and to the external interface. There is no
problem for traps (except maybe that it changes the current Firefox
implementation...). A backward compatibility may exist for ES5 code:
* Object.defineProperty using maps
=> For legacy reason, it would keep accepting plain old objects, but
when passed a map, it would use the map get/set/has protocol.

* Object.getOwnPropertyDescriptor returning maps
=> That part is a bit trickier, because current code has a ridiculous
amount of 'desc.configurable', 'desc.enumerable', etc. in it and this
must keep working.
I'm not sure I have found an acceptable idea for this part. One major
issue I see is the naming conflict between Map.prototype.get/set and the
'get' and 'set' attributes of property descriptors.

In the hope it will inspire someone who'll be able to find a solution.



More information about the es-discuss mailing list