Closed Bug 369024 Opened 18 years ago Closed 17 years ago

sessionStorage does not preserve nested elements / hierarchy

Categories

(Core :: DOM: Core & HTML, defect)

1.8 Branch
x86
Windows XP
defect
Not set
minor

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: atec_post, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1

The following code doesn't work (for a depth higher than 2):
x=new Object();
x.y=new Object();
z.y.z=new Object();
z.y.z.t=new Object();
sessionStorage.x = x;
u = sessionStorage.x.y.z; // "sessionStorage.x.y has no properties" is thrown 

The "inline assignments" version also exhibits the same bug, but no exception is thrown:
sessionStorage.A=1
sessionStorage.A.B=2
sessionStorage.A.B.C=3
d = sessionStorage.A.B.C; // here: d == null

Reproducible: Always

Steps to Reproduce:
See the details and/or the two test cases.
Actual Results:  
Explained in details section

Expected Results:  
Explained in details section

Maybe the "storage" event is not properly raised...

More info at:
http://www.whatwg.org/specs/web-apps/current-work/#sessionstorage
Version: unspecified → 2.0 Branch
Assignee: nobody → general
Component: General → DOM
Product: Firefox → Core
QA Contact: general → ian
Version: 2.0 Branch → 1.8 Branch
Per http://www.whatwg.org/specs/web-apps/current-work/#storageitem a StorageItem's value is a DOMString and no Object. -> INVALID

You might want to use the following pattern to store objects as strings:
sessionStorage.x = x.toSource();
u = eval(sessionStorage.x).y.z
Status: UNCONFIRMED → RESOLVED
Closed: 17 years ago
Resolution: --- → INVALID
This code works for me, but are we breaking the javascript object model also?

Following the example, I'm not writing directly to "value" attribute, so the fix you posted shouldn't be done "inside" FFox?

Regards.
Resolution: INVALID → WORKSFORME
(In reply to comment #2)
> Following the example, I'm not writing directly to "value" attribute

You are: sessionStorage.key = value;
(both key and value are implicitly converted to a DOMString)

> so the fix you posted shouldn't be done "inside" FFox?

Only if the HTML5 spec is changed accordingly - otherwise you'll want Firefox to behave the same way as other browsers implementing HTML5 to prevent confusion when doing cross-browser development.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.