[Harmony Proxies] Proposal: Property fixing

Tom Van Cutsem tomvc.be at gmail.com
Wed Jun 15 13:38:38 PDT 2011

2011/6/15 Brendan Eich <brendan at mozilla.com>

> On Jun 15, 2011, at 8:51 AM, Allen Wirfs-Brock wrote:
> > More generally, for better or worse, Cameron McCormack is right now
> busily working to publish the last call draft of a Web IDL specification
> that includes rules for what the attribute settings must be for all DOM
> properties.  If those rules don't match up with what proxies can express
> then there will be issues with implementing the DOM in ECMAScript.

Aside from the configurable attribute (which we are now discussing), proxies
are able to emulate all other attribute values, so I can't immediately think
of any other use cases that proxies currently cannot deal with.

> Paging Dr. Van Cutsem!
> To emulate length as non-configurable but magically changing its value as a
> data property may be possible with proxies. It is after all writable.

Ah, good suggestion. The fixed properties strawman would indeed allow this.
First, one defines "length" as a non-configurable property on a fresh
arrayProxy, thereby fixing the property:

Object.defineProperty(arrayProxy, "length",
  { value: 0,
    writable: true,
    enumerable: false,
    configurable: false });

Given that we provide all traps with a reference to the proxy they're
currently servicing (as per one of the pending strawmen), the handler for
arrayProxy can then update the fixed "length" property within a trap by

Object.defineProperty(arrayProxy, "length", { value: newValue });

This will modify the fixed property, which is legal since it is writable.
It may not be very elegant, but at least it's doable.

To be clear: what the strawman still doesn't allow is that a proxy would be
able to emulate a non-writable, non-configurable data property whose value
can still change.

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

More information about the es-discuss mailing list