This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 14084 - Hi! Returning a null from getItem() if the key does not exist is downright semantically wrong. null is a full-fledged value which can be serialized (JSONed), and is NOT the value we get if we do: var x = myObject.someUnknownProperty; In that case we get t
Summary: Hi! Returning a null from getItem() if the key does not exist is downright se...
Status: RESOLVED WONTFIX
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: Web Storage (editor: Ian Hickson) (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: public-webapps-bugzilla
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-08 12:13 UTC by contributor
Modified: 2011-10-12 01:59 UTC (History)
7 users (show)

See Also:


Attachments

Description contributor 2011-09-08 12:13:02 UTC
Specification: http://dev.w3.org/html5/webstorage/
Multipage: http://www.whatwg.org/C#top
Complete: http://www.whatwg.org/c#top

Comment:
Hi!

Returning a null from getItem() if the key does not exist is downright
semantically wrong. null is a full-fledged value which can be serialized
(JSONed), and is NOT the value we get if we do:

var x = myObject.someUnknownProperty;

In that case we get the 'undefined' value, and that is what the return value
of getItem() _should_ be if the item is not found. undefined is not
serializable (JSONable) and is never a valid value, whereas null is sometimes
an application-/domain-valid value. Returning null from getItem() is ambiguous
in the case of an application using null as a placeholder or a "falsy" value.
Returning undefined is unambiguous.

----- stephan beal (sgbeal@googlemail.com)

Posted from: 194.246.122.11
User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.218 Safari/535.1
Comment 1 Tab Atkins Jr. 2011-09-08 15:31:30 UTC
If you store a null value, it gets serialized to the string "null".  When you pull it back out, you get the string back, not the null value.  It's impossible get an actual null value back out of a valid key.
Comment 2 Aryeh Gregor 2011-09-12 17:18:26 UTC
Also, this is how UAs behave now, and it's unlikely we can change it without breaking compat.
Comment 3 Arthur Barstow 2011-10-11 20:13:12 UTC
I think v1 of this spec should focus on current implementations and as such, the change proposed in comment 0 can be considered for the next version of the spec.
Comment 4 Anne 2011-10-12 00:31:49 UTC
Art, we cannot resolve this LATER, because at that point it would break compatibility with v1. So we have to decide now whether this is WONTFIX or not.
Comment 5 Anne 2011-10-12 01:59:01 UTC
WONTFIX per comment 2 and comment 4. If you disagree with this resolution please reopen.