[whatwg] A couple questions about the Web Storage spec

Hello all,

I have a couple questions about the storage spec (I'm reading the August 10th 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:
	localStorage[3]
and get something back (not clear if the key or the value).  Am I right in my interpretation of that paragraph?

I saw some discussion earlier about whether something like localStorage[3] was meaningful, but I didn't find the resolution.  And none of the browsers I've tried this with do this (unless, of course, there has already been a setItem('3', someValue) done earlier).  So, I'm just confused, and probably misunderstanding "indices of the supported indexed properties".  Thanks for any clarification.


(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"];
		or
	myVariable = window.localStorage.foo;
and now myVariable will have "bar".
 
If my reading is right (and it is the behavior I see in a couple browsers) this seems a bit dangerous, because I can do something like:
	window.localStorage.setItem("length", "a value we compute");
	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.

Why is this a desirable feature?

(I originally posted these questions to another list.  Jeremy Orlow mentioned this had been discussed elsewhere, but I haven't managed to locate the discussion. Happy to be pointed at it)


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


Thanks!

David Burrowes

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20100812/159f8515/attachment.htm>

Received on Thursday, 12 August 2010 20:20:44 UTC