W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2009

[whatwg] question about Web Storage setItem()'s behavior

From: Jeremy Orlow <jorlow@chromium.org>
Date: Sun, 2 Aug 2009 19:41:57 -0700
Message-ID: <5dd9e5c50908021941k2f36d92bx83e39fcd785a6ea8@mail.gmail.com>
On Sun, Aug 2, 2009 at 7:17 PM, ???? <shumpei.shiraishi at gmail.com> wrote:

> Hi,
>
> I'm implementing the HTML5 Web Storage using Gears
> (http://code.google.com/p/gear5/), so I have several questions with
> the spec.
>
> -Storage.setItem(key, val)
> --is key allowed non-string type object?


Yes, but...

--and when pass non-string object to key/value, is it automatically
> converted to string?(I'm considering to convert to use String
> constructor - String(key) )


Yes.


>
> --when value is null, should `setItem("key", null)` behave as like as
> `removeItem("key")`? (localStorage.setItem("key", null);
> alert(localStorage.length); <-- what is value displayed?)


No, it's not the same as removeItem.  It'll be set to 'null'.

Check out Safari 4's implementation if you'd like to see the correct
behavior for all of these cases.  I've been spending a lot of time with it,
and it matches the spec in every case I've tried.  (And I've tried a
lot...I'm working on it for Chromium.)  :-)

J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20090802/9c4796a8/attachment.htm>
Received on Sunday, 2 August 2009 19:41:57 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:15 UTC