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

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

From: Jeremy Orlow <jorlow@chromium.org>
Date: Wed, 14 Jul 2010 14:59:35 +0100
Message-ID: <AANLkTinWYbabK7ZIIAiDhxTcwRNdiM0o3pFARjlv8Gbu@mail.gmail.com>
To: David John Burrowes <self@davidjohnburrowes.com>
Cc: public-webapps@w3.org
I'm not sure if discussion on this normally happens on WebApps.  whatwg
might be the better place.

On Thu, Jul 8, 2010 at 5:33 PM, David John Burrowes <
self@davidjohnburrowes.com> wrote:

> Hello all,
>
> 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?
> 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.  So, I'm just confused, and probably misunderstanding "indices of
> the supported indexed properties".  Thanks for any clarification.
>

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.



> (2) The spec also says:
> "The names of the supported named properties on a Storage<http://dev.w3.org/html5/webstorage/#storage-0> 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".
>

Named properties means localStorage.foo, I believe.


> 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.
>
> Why is this a desirable feature?
>

This doesn't seem very desirable to me either.  IIRC, I brought this up a
long time ago on whatwg though.  Unfortunately, I don't remember the
resolution or rational.  Maybe look at the archives?



> (3) Real nitpicking here:
> The IDL for the Storage interface says
>
>
>   setter creator void setItem <http://dev.w3.org/html5/webstorage/#dom-storage-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.
>

I'd agree.


Thank you.  Despite my nitpicking above, I really appreciate the presence of
> this spec! :-)
>
>
> david
>
> p.s. I'm still coming up to speed on these specs, so if I'm just
> misunderstanding something basic, direct me to TFM that I should R.
>
>
Received on Wednesday, 14 July 2010 14:00:25 GMT

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