Last Comment Bug 538142 - support structured data (not just strings) in localStorage/sessionStorage
: support structured data (not just strings) in localStorage/sessionStorage
Status: VERIFIED INVALID
: html5, testcase
Product: Core
Classification: Components
Component: DOM (show other bugs)
: Trunk
: All All
: -- normal with 1 vote (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
: 572474 (view as bug list)
Depends on: 550275
Blocks:
  Show dependency treegraph
 
Reported: 2010-01-06 05:28 PST by Nickolay_Ponomarev
Modified: 2011-08-08 01:15 PDT (History)
12 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
testcase (433 bytes, text/html)
2010-01-06 05:28 PST, Nickolay_Ponomarev
no flags Details

Description Nickolay_Ponomarev 2010-01-06 05:28:01 PST
Created attachment 420308 [details]
testcase

http://www.w3.org/TR/webstorage/#the-storage-interface says "Values can be any data type supported by the structured clone algorithm."

Apparently this was changed in whatwg r3549 <http://lists.whatwg.org/pipermail/commit-watchers-whatwg.org/2009/002717.html> without anyone noticing. At least <http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage/2010948#2010948> claims that every browser implemented string-only values.

A simple testcase is attached, here's an extract:
 localStorage["test"] = {a:1};
 typeof localStorage["test"] == "string" // should be "object"
 localStorage["test"].a != 1 // should be == 1.

I couldn't find anything about this change to structured data on the web, other than people wondering what was the reason for this change. Obviously it would be more convenient for developers if all browsers consistently implemented structured values.

Either the spec should be changed to match reality or the browsers should implement structured data.
Comment 1 :Ms2ger (⌚ UTC+1/+2) 2010-06-16 12:53:04 PDT
*** Bug 572474 has been marked as a duplicate of this bug. ***
Comment 2 bugzilla33 2010-06-16 13:47:22 PDT
*** Bug 572474 has been unmarked as a duplicate of this bug. ***

because after "Clear Recent History..." sessionStorage keys/values pairs should be removed. If the key does not exist getItem method must return null.

Actual values in sessionStorage are replacing by empty strings.
Comment 3 bugzilla33 2010-06-19 14:57:49 PDT
*** Bug 572474 has been marked as a duplicate of this bug. ***
Comment 4 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2011-05-30 14:17:24 PDT
Should we consider WONTFIXing this?  I don't think WebKit does this ... and making localStorage more useful seems like a waste of time.
Comment 5 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2011-08-07 18:45:08 PDT
The spec has been changed to string values only.  See the w3.org bug, particularly comments 6, 7, 11, and 15 for the rationale.
Comment 6 Michael[tm] Smith 2011-08-07 19:32:25 PDT
(In reply to Kyle Huey [:khuey] (khuey@mozilla.com) from comment #5)
> The spec has been changed to string values only.  See the w3.org bug,
> particularly comments 6, 7, 11, and 15 for the rationale.

For the record, that bug is http://www.w3.org/Bugs/Public/show_bug.cgi?id=12111
Comment 7 Hixie (not reading bugmail) 2011-08-07 20:04:43 PDT
For the record, the rationale is "Mozilla (and the other browsers) didn't do it". The spec would change back in a second if this bug was fixed and the feature implemented.
Comment 8 Jonas Sicking (:sicking) No longer reading bugmail consistently 2011-08-07 20:43:57 PDT
You mean "it would change back in a second if all major browsers, or a significant majority thereof, decided to implement it"?
Comment 9 adam souzis 2011-08-07 20:45:47 PDT
If this is the resolution so be it, but here's use case for this that I haven't seen considered: the storage event is broadcast to all windows with that origin; this is only widely-implemented standard way to pass messages between windows that don't have references to each other's window object. In this case, localStorage is used as a message queue. IndexDB doesn't appear to have equivalent functionality.

This bug caused a bit of pain for me because I read the spec's mention of structured data and assumed my messages would work interchangablely between the storage event and window.PostMessage. 

OTOH, this functionality would be better suited as extension to PostMessage (giving it some sort of broadcast option) and once SharedWorkers are widely implemented it could be used for this too, albeit as more heavy weight solution.

Note You need to log in before you can comment on or make changes to this bug.