W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2011

Re: [WebIDL] Indexed properties and [[Extensible]]

From: Jonas Sicking <jonas@sicking.cc>
Date: Wed, 25 May 2011 17:29:14 -0700
Message-ID: <BANLkTikFjjBGoDyXDpWy=OFqMFZG5gGmFg@mail.gmail.com>
To: David Flanagan <dflanagan@mozilla.com>
Cc: public-script-coord@w3.org
On Wed, May 25, 2011 at 12:15 PM, David Flanagan <dflanagan@mozilla.com> wrote:
> §4.5.2 indicates that indexed properties won't be added to an object if its
> [[Extensible]] attribute is false.  I take this to mean that conforming
> objects will work like regular JavaScript objects for
> Object.preventExtensions() as well as Object.seal() and Object.freeze().  Is
> this the intent?
> Let's take NodeList as a concrete example, keeping in mind that DOM Core
> requires that the childNodes property of a Node always returns the same
> NodeList object and that that object is live:
> var div = document.createElement("div");
> div.appendChild(document.createTextNode("test"));
> var kids = div.childNodes;  // a NodeList
> kids.freeze()                       // This should work, right?
> // I think this should succeed despite the freeze() above, right?
> div.appendChild(document.createTextNode("foo"));
> div.childNodes[0]               // => the original text node "test"
> div.childNodes[1]               // => undefined because of freeze
> div.childNodes.length;       // But this is 2, right?
> div.childNodes.item(1);      // What does this return?
> This seems like a nasty can of worms to me.  A simpler approach would be to
> require an implementation to throw a TypeError on any attempt to set
> [[Extensible]] to false on an object that has an indexed getter.  It just
> doesn't make sense to be able to freeze a live collection.
> (Does WebIDL need to make a distinction between interfaces that are live and
> those that are not?  Should there be a [Freezeable] attribute for non-live
> interfaces with indexed getters?)

How do named/indexed getters/setters interact with the prototype
chain? Are they supposed to show up as properties on the object
itself, or should they show up as "catch all" getters on an object on
the proto chain?

The latter is how we implement them in Firefox. The former might be
more javascripty since it doesn't require catch-alls.

If it's the latter, then this isn't a problem at all since when you
freeze, you only freeze the object itself. Objects on the prototype
chain aren't affected at all.

/ Jonas
Received on Thursday, 26 May 2011 00:30:14 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:44 UTC