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

Re: Getters establish own properties, or why is [NamedPropertiesObject] discouraged?

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Fri, 24 Feb 2012 13:45:09 -0800
Message-ID: <CAAWBYDCwVejs02KpFhiwwVUZkTCP6PqHOovq+SsJU8=1HEZztg@mail.gmail.com>
To: Cameron McCormack <cam@mcc.id.au>
Cc: public-script-coord@w3.org
On Thu, Feb 23, 2012 at 5:40 PM, Cameron McCormack <cam@mcc.id.au> wrote:
> Tab Atkins Jr.:
>> However, it was pointed out that this would produce a change in
>> behavior.  The current definition puts all the properties on the
>> prototype object, while using getter/setter instead makes them own
>> properties, which in general means they would be put on the object
>> itself.  The [NamedPropertiesObject] extended attribute makes them not
>> own properties again, but that's marked as deprecated and only to be
>> used for legacy behavior.
>
> Oh, yes, that would be a change in behaviour.  Is this a practical problem,
> though?

I have no idea.  It does make it somewhat more difficult to extend,
though.  IE and FF (and I think O) have exposed them as non-own for a
long time, while WebKit treats them as own.


>> What's the reasoning for this behavior difference between the two methods?
>
> Named properties are exposed as data properties by defining special
> behaviour for [[GetOwnProperty]], [[DefineOwnProperty]] etc. on platform
> objects.  If we move them up to the prototype, then they cannot remain as
> data properties since they won't be able to have different values depending
> on which actual CSSStyleDeclaration you performed the property lookup on.
>  If they were exposed as accessor properties, then this would work.  Now
> this is a bit more overhead, but we've already committed to this given
> that's how IDL attributes are exposed.

I'm pretty sure the CSSStyleDeclaration props are defined as accessor
properties in practice, so they can lazily generate their values when
necessary.  I'm not sure how much of that is magic vs
needs-to-be-observable behavior.

> Exposing named properties somewhere on the prototype chain like with
> [NamedPropertiesObject] also requires us to have the same set of property
> names.  For objects like HTMLCollection that's obviously not possible, but
> for CSSStyleDeclaration that would be OK, since the set is the same for
> every object.

Once impls support Variables this'll be a little different; the set is
open-ended/infinite then.


> I am however not keen on CSSStyleDeclaration using a different mechanism to
> expose named properties than other objects (ignoring Window, the only user
> of [NamedPropertiesObject] at the moment).

I would also prefer it act similar to the rest of the platform in
author-visible behavior.  I'm just not sure what that means, or how I
should go about doing it. ;_;

~TJ
Received on Friday, 24 February 2012 21:45:57 UTC

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