W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2011

Re: [Web Storage] A couple questions about the storage spec

From: Ian Hickson <ian@hixie.ch>
Date: Sat, 29 Jan 2011 00:18:35 +0000 (UTC)
To: Jeremy Orlow <jorlow@chromium.org>, David John Burrowes <self@davidjohnburrowes.com>, hbambas@mozilla.com
cc: public-webapps@w3.org
Message-ID: <Pine.LNX.4.64.1101282119140.26730@ps20323.dreamhostps.com>
On Tue, 17 Aug 2010, Jeremy Orlow wrote:
> On Tue, Aug 17, 2010 at 12:08 AM, Ian Hickson <ian@hixie.ch> wrote:
> > On Thu, 8 Jul 2010, David John Burrowes wrote:
> > >
> > > I have a couple questions about the storage spec (I'm reading the 
> > > June 15th version at (http://dev.w3.org/html5/webstorage/).
> > >
> > > (1) The spec says: "The object's indices of the supported indexed 
> > > properties are the numbers in the range zero to one less than the 
> > > number of key/value pairs currently present in the list associated 
> > > with the object. If the list is empty, then there are no supported 
> > > indexed properties."
> > >
> > > As far as I can tell, this seems to say I should be able to say
> > > something like:
> > >       window.localStorage[3]
> > > and get something back (not clear if the key or the value).  Am I right
> > > in my interpretation of that paragraph?
> >
> > Yes.
> >
> > > I saw some discussion earlier about whether something like 
> > > localStorage[3] was meaningful, but I didn't find the resolution.  
> > > It does seem undesirable/confusing to me.  And none of the browsers 
> > > I've tried this with do this.
> >
> > On Wed, 14 Jul 2010, Jeremy Orlow wrote:
> > >
> > > All the browsers I know of handle localStorage[3] as 
> > > localStorage.get/setItem('3', ...).  My impression is that this 
> > > behavior is pretty firmly rooted at this point.  It seems as though 
> > > the spec may need to change.
> >
> > Firefox seems to implement this correctly. It just seems to be a bug 
> > in Opera and Chrome. (I didn't test Safari or IE.)
> 
> Safari and IE act the same way as Opera and Chrome, so I would agree 
> with David's assertion that this behavior is fairly firmly rooted.  But 
> you disagree, Ian?

I do not. This does indeed seem like something that would be hard to 
change. I hate to change this on Gecko, though, since they implemented it 
correctly... This is especially problematic because IE does this wrongly 
too, and given IE's multi-year dev cycle, this means that this behaviour 
will be heavily ingrained by the time IE can ship an update.

Jan: I've changed the spec here. Please let me know if this is 
problematic, and please accept my apologies for screwing you over even 
though you were the only browser to follow the spec.


> > > If my reading is right (and it is the behavior I see in a couple
> > browsers) this makes me very nervous, because I can do something like:
> > >       window.localStorage.setItem("length", "a value we computer");
> > >       window.localStorage.setItem("clear", "something that is
> > transparent");
> > > which of course allows:
> > >       window.localStorage["length"];
> > >       window.localStorage["clear"];
> > > but in the browsers I've looked at, this (of course) also kinda messes up
> > things like:
> > >       for (index = 0; index < window.localStorage.length; index++) {
> > >               // whatever
> > >       }
> > >       window.localStorage.clear();
> > > since length is now not a number, and clear isn't a function.
> >
> > Actually length and clear don't get overrideen, because the interface 
> > is not defined as [OverrideBuiltins].
> 
> Wha?  This seems completely different than your answer in this thread: 
> http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2009-June/020349.html

Not sure if I was just wrong then or if the specs changed between my 
replies. At this point the spec seems to match implementations though.


On Sat, 21 Aug 2010, David John Burrowes wrote:
> >
> > Code like this:
> > 
> >   if (localStorage.visitedAlready) { ... }
> > 
> > ...is simpler to read than code like:
> > 
> >   if (localStorage.getItem('visitedAlready')) { ... }
> 
> I can definitely see that that is easier to read.  It also strikes me as 
> fragile to write this as localStorage.visitedAlready.  If a later 
> version of the standard adds a 'visitedAlready' function or attribute to 
> the localStorage object, my code may not behave as it did in the 
> previous version (which scares the ____ out of me as a developer :-) ).  

We're not going to be adding visitedAlready to Storage. I expect we'll 
never add anything. If we do we'll be very careful. This is the kind of 
thing we can actually do research for and make sure we never add something 
that clashes with what Web pages do, by instrumenting browsers so that 
they report the number of pages that use a particular value.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Saturday, 29 January 2011 00:19:04 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:43 GMT