W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2012

Web IDL attributes and delegation

From: Colin Snover <w3.org@zetafleet.com>
Date: Wed, 12 Sep 2012 10:38:37 -0500
Message-ID: <5050AC7D.6010205@zetafleet.com>
To: public-script-coord@w3.org
Hi everyone,

It was recommended to me by Boris Zbarsky at
https://bugzilla.mozilla.org/show_bug.cgi?id=790303 that I should bring
my concerns to this list regarding using platform objects as prototypes
and the current rules for Web IDL attribute getters/setters.

As a JS author, it is important to me to be able to have a way to
augment DOM event objects and/or override certain properties (which may
be defined as readonly) in a time- and memory-efficient manner. Right
now, most script libraries end up doing a shallow copy of properties
from the native event object to a surrogate and then fix up the standard
event methods (stopPropagation, etc.) to point back to the native
object, which is quite inefficient, and can be especially bad for
performance when dealing with high-volume events (touchmove, mousemove,
etc.). Delegation via e.g. Object.create should be a more reasonable way
to accomplish this, but the latest editor’s draft of the Web IDL spec
makes it impossible by defining behaviour that requires attribute
getters to throw when |this| is not a platform object, which means any
attempt to use a platform object as the prototype of a new object fails
(http://dev.w3.org/2006/webapi/WebIDL/#es-attributes attribute getters
step 2 substep 2.2).

Ultimately I suppose that the idea is ES6 proxies will be “the”
solution, but it is burdensome how limited we are now, given that all
the pieces seem to exist in ES5 to accomplish this goal. I strongly
believe that browser vendors should be making every effort to make
host/platform objects indistinguishable from native JavaScript objects
as much as possible, but this latest, less ambiguous version of the Web
IDL spec seems to go in the opposite direction.

My first thought for an alternative proposal, were one to be
entertained, would be to fix the |this| value of platform object
getter/setters to the platform object itself, as though all the methods
were defined using Function.prototype.bind, if |this| is not a platform
object. This would ensure things like var obj = Object.create(event);
obj.stopPropagation(); would work correctly (current browser
implementations vary wildly in this scenario) whilst still allowing
read-only properties to be safely redefined on the delegate. This may
not be the best ultimate solution, since it does mean that a platform
object would be changing its own properties instead of the properties of
the true |this|, but I think it gets closer to the goal of minimising
the differences of host/platform objects than the current proposal and
enables platform objects to be used as prototypes.

Please let me know your thoughts. Thanks!

-- 
Colin Snover
http://zetafleet.com
Received on Wednesday, 12 September 2012 15:40:23 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:07 UTC