W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2010

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

From: Ian Hickson <ian@hixie.ch>
Date: Mon, 16 Aug 2010 23:08:26 +0000 (UTC)
To: David John Burrowes <self@davidjohnburrowes.com>, Jeremy Orlow <jorlow@chromium.org>
cc: public-webapps@w3.org
Message-ID: <Pine.LNX.4.64.1008162258260.19416@ps20323.dreamhostps.com>
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.)

This is the kind of thing that will shake out when we have a test suite.


On Thu, 8 Jul 2010, David John Burrowes wrote:
> 
> (2) The spec also says:
> "The names of the supported named properties on a Storage object are the 
> keys of each key/value pair currently present in the list associated 
> with the object."
> I read that (possibly/probably wrongly) as saying I should be able to say
> 	window.localStorage.setItem("foo", "bar");
> 	myVariable = window.localStorage["foo"];
> and now myVariable will have "bar".

Yes.


> 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].


> Why is this a desirable feature?

Code like this:

   if (localStorage.visitedAlready) { ... }

...is simpler to read than code like:

   if (localStorage.getItem('visitedAlready')) { ... }


> (3) Real nitpicking here:
> The IDL for the Storage interface says
>   setter creator void setItem(in DOMString key, in any data);
> but the text says
> 	The setItem(key, value) method
> Note the name of the second parameter is different between these.

Fixed IDL.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Monday, 16 August 2010 23:08:56 GMT

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