Enriched Descriptors, maybe ES7 ?

Tom Van Cutsem tomvc.be at gmail.com
Mon Mar 10 00:02:48 PDT 2014

2014-03-09 21:05 GMT+01:00 Brendan Eich <brendan at mozilla.com>:

> Tom has experimented, IIRC. I don't know which implementations preserve
> extended property descriptor properties.

As Allen mentioned earlier, proxies should receive in their defineProperty
trap the full descriptor object as it was passed in by the user, including
any custom attributes. The proxy is free to store it, and return it from
any subsequent getOwnPropertyDescriptor trap (which is also specced so that
it can return a non-normalized descriptor object with custom attributes).

Normal (non-proxy) objects of course cannot store non-normalized
descriptors, so any custom attributes are lost. Changing this would
presumably have a big impact on implementations (which probably don't hang
on to descriptor objects at all).

If you want to experiment with custom attributes, my harmony-reflect shim
supports this for proxies:

var props = {};
var o = new Proxy({},{
  defineProperty: function(target, name, desc) {
    props[name] = desc;
    return true;
  getOwnPropertyDescriptor: function(target, name) {
    return props[name];
Object.defineProperty(o,"p",{value:42, configurable:true, hello:true})
// prints
// {"configurable":true,
//  "value":42,
//  "writable":false,
//  "enumerable":false,
//  "hello":true } // <- custom attribute preserved

Using Firefox's built-in direct proxies implementation I get a TypeError.
I'll investigate further and file a bug.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140310/9d8d5f50/attachment.html>

More information about the es-discuss mailing list