W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2008

[whatwg] DOM Storage feedback

From: Brady Eidson <beidson@apple.com>
Date: Mon, 28 Apr 2008 14:14:03 -0700
Message-ID: <E5A7DAB7-AB42-44F6-A81B-6C43CD7246BA@apple.com>

On Apr 27, 2008, at 5:32 PM, Ian Hickson wrote:

> On Thu, 10 Apr 2008, Brady Eidson wrote:
>>
>> In 4.10.5, the description of the properties on the StorageEvent  
>> object
>> mentions "...its newValue attribute set to the new value of the key  
>> in
>> question, or null if the key was removed..."
>>
>> So a web author can assume that when handling a StorageEvent whose
>> newValue property is null that the event was the result of a
>> removeItem(), and the key is no longer in the list.
>>
>> However in 4.10.2 in the discussion of setItem(), there is no mention
>> that null is not an allowed value.  Something like
>> sessionStorage.setItem("key", null) is not forbidden, therefore it is
>> allowed, and it would result in a StorageEvent with a null newValue.
>>
>> To resolve this case, I propose that we specify that the value in a  
>> key/value
>> pair cannot be set to null.
>> I see two clean ways to specify this:
>>
>> 1 - Throw an exception when setItem() is called with a null value.
>> 2 - Specify setItem(key, null) to have the exact same effects as
>> removeItem(key).
>>
>> I prefer #2.  Thoughts?
>
> On Fri, 11 Apr 2008, Anne van Kesteren wrote:
>>
>> Euhm, setItem() takes two strings. Therefore I'd expect null,  
>> undefined,
>> etc. to be stringified.
>
> On Thu, 10 Apr 2008, Brady Eidson wrote:
>>
>> Ugh... yup.  You're right.
>>
>> Nevermind!
>
> I'm not sure I understand why this is not an isue, but ok.

I would like to make sure that my understanding is correct here, since  
you expressed doubt.

Anne was asserting that since the interface for setItem() specifies a  
DOMString as the input, anything you pass it will be stringified.   
Therefore passing it the null value would be stringified to "null".   
This is what you currently see in all the major browsers with  
window.alert(null), for example, which is also specified as a  
DOMString input parameter.

Therefore a call to setItem("foo", null); becomes, in effect,  
setItem("foo", "null");

Is this correct?

If so, the spec is fine as-is, and removeItem() is the only way to  
remove an individual item.

~Brady

>
>
> -- 
> Ian Hickson               U+1047E                ) 
> \._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _ 
> \  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'-- 
> (,_..'`-.;.'
Received on Monday, 28 April 2008 14:14:03 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:40 UTC