Enriched Descriptors, maybe ES7 ?

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Mar 10 08:45:23 PDT 2014

Thanks Tom, I see what you mean but using proxies is a performance killer,
while I am trying to propose something that theoretically could also give a
performance boost.

I am not proposing custom descriptor attributes here, I am proposing
`type`, `arguments` (or `parameters`) and `returns` as specified/extra
descriptor properties capable to bring "typed properties" to, maybe, ES7

My repository already does this and it works even copying objects, if this
is done through `getOwnPropertyDescriptor`

So, custom descriptor properties a part, would ES7 consider to implement
types not only for `StructType` but also for runtime defined shapes so that
`Object.defineProperty({}, 'num', {value: 123, writable: true, type:
int32})` works same as my polyfill does already?


On Mon, Mar 10, 2014 at 12:02 AM, Tom Van Cutsem <tomvc.be at gmail.com> wrote:

> 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})
> JSON.stringify(Object.getOwnPropertyDescriptor(o,"p"))
> // 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.
> Regards,
> Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140310/07885a66/attachment.html>

More information about the es-discuss mailing list