Closed
Bug 551225
Opened 15 years ago
Closed 14 years ago
Make pushState use structured clone
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
People
(Reporter: justin.lebar+bug, Assigned: justin.lebar+bug)
References
Details
(Keywords: dev-doc-complete)
Attachments
(1 file, 4 obsolete files)
51.68 KB,
patch
|
Details | Diff | Splinter Review |
Right now, pushState and replaceState serialize their state objects to JSON. We should use structured clone to be compliant with the spec.
Assignee | ||
Comment 1•15 years ago
|
||
On the other hand, JSON serialization is convenient because it lets us easily serialize state objects for session restore.
Right, what we need here is not the structured clone code developed over in bug 550275. What we need is code to serialize and deserialize such that
obj1 --serialize--> ser --deserialize--> obj2
obj2 is a structured clone of obj1. We'll need this code both for pushState and for localStorage.
Assignee | ||
Comment 3•15 years ago
|
||
Did a quick experiment and it appears that WebKit is doing something similar to us: If you create a state object which contains a function, the function doesn't exist when you get the state object back on popstate.
I like the fact that we can serialize state objects to disk, so I'm not sure we even want to do this. But if we don't, maybe we should get the spec changed.
We should definitely serialize. Everything supported by the structured clone algorithm is serializable. The user-visible effect of fixing this bug is that you can pushState objects that contain things like ImageData, dates and regexps (the latter not being terribly important obviously).
Assignee | ||
Comment 5•14 years ago
|
||
For my reference, it looks like the JSAPI functions are JS_WriteStructuredClone and JS_ReadStructuredClone. When we write out to storage, we can Base64-encode the value. And when we read back in, we'll have to convert any JSON-encoded state objects to the new format.
Assignee | ||
Comment 6•14 years ago
|
||
I'll ask for review here once I push to try and verify that this works.
Comment 7•14 years ago
|
||
(In reply to comment #4)
> We should definitely serialize. Everything supported by the structured clone
> algorithm is serializable. The user-visible effect of fixing this bug is that
> you can pushState objects that contain things like ImageData, dates and regexps
Most importantly, File. Once structured clones support them, it should be possible to store Files that the user has opened to the history, and to restore them from a serialized session, so users don't have to reopen files each time they restart their browser.
Assignee | ||
Comment 8•14 years ago
|
||
Attachment #527605 -
Flags: review?(jonas)
Assignee | ||
Updated•14 years ago
|
Attachment #525039 -
Attachment is obsolete: true
Comment 9•14 years ago
|
||
Is there a reason why nsIStructuredCloneContainer need to live under docshell/ ?
It looks like a very useful interface/class for other use too.
Maybe it could be under dom/intefaces/base ?
Assignee | ||
Comment 10•14 years ago
|
||
Patch is ready for review. I fixed the one bug from my last try push, so things *should* be green, but I'll push again to be sure.
I'd originally used JS_AutoStructuredClone inside nsIStructuredCloneContainer, but I was getting strange memory management errors. (I know you don't have to JS_free with the same cx you JS_malloc'ed with, so I'm not exactly sure what I was doing wrong.) In any case, I think malloc'ing and free'ing manually is sufficiently simple not to worry about this.
Assignee | ||
Comment 11•14 years ago
|
||
(In reply to comment #9)
> Is there a reason why nsIStructuredCloneContainer need to live under docshell/
>
> Maybe it could be under dom/intefaces/base ?
That's fine with me!
Assignee | ||
Comment 12•14 years ago
|
||
Moved nsIContentUtils, per Smaug's suggestion.
Attachment #527617 -
Flags: review?(jonas)
Assignee | ||
Updated•14 years ago
|
Attachment #527605 -
Attachment is obsolete: true
Attachment #527605 -
Flags: review?(jonas)
Assignee | ||
Comment 13•14 years ago
|
||
er...I moved nsIStructuredCloneContainer (and kin), not nsIContentUtils (which hopefully will cease to exist soon).
Assignee | ||
Comment 14•14 years ago
|
||
(In reply to comment #10)
> Patch is ready for review. I fixed the one bug from my last try push, so
> things *should* be green, but I'll push again to be sure.
Looks good.
Paul, can you have a look at the sessionstore changes?
Assignee | ||
Updated•14 years ago
|
Attachment #527617 -
Flags: review?(paul)
Assignee | ||
Comment 15•14 years ago
|
||
I should mention that this change will cause a one-time loss of state objects upon session restore; I make no attempt to read the old JSON state objects and convert them to the new format. I think this isn't a big deal, since persisting state across session restore didn't even work properly until we fixed bug 647028 yesterday.
Comment 16•14 years ago
|
||
Comment on attachment 527617 [details] [diff] [review]
Patch v2.1
Can I assume that since there are no tests here, this is covered under some of the other tests you've written? r=me assuming that, but I'll take it back if you tell me I'm wrong.
I'm ok with the one-time data loss. pushState isn't that widely used yet that most people wouldn't even notice.
Attachment #527617 -
Flags: review?(paul) → review+
Assignee | ||
Comment 17•14 years ago
|
||
Although I think we get decent coverage with the other tests I wrote, it would be trivial to add a test specifically for session restore to browser_500328.js. I'll definitely add this.
Assignee | ||
Comment 18•14 years ago
|
||
Added session restore test.
Attachment #530390 -
Flags: review?(jonas)
Assignee | ||
Updated•14 years ago
|
Attachment #527617 -
Attachment is obsolete: true
Attachment #527617 -
Flags: review?(jonas)
Comment on attachment 530390 [details] [diff] [review]
Patch v2.2
Wow, this looks great
Attachment #530390 -
Flags: review?(jonas) → review+
Assignee | ||
Comment 20•14 years ago
|
||
I forgot to update nsIDocument's CID and check the return value of JSAutoEnterCompartment::Enter in nsStructuredCloneContainer::InitFromVariant.
Assignee | ||
Updated•14 years ago
|
Attachment #530390 -
Attachment is obsolete: true
Assignee | ||
Updated•14 years ago
|
Keywords: dev-doc-needed
Assignee | ||
Comment 21•14 years ago
|
||
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Updated•14 years ago
|
Assignee: nobody → justin.lebar+bug
Comment 22•14 years ago
|
||
Documentation updated:
https://developer.mozilla.org/en/DOM/window.history
https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history
Added:
https://developer.mozilla.org/en/DOM/The_structured_clone_algorithm
Also mentioned on Firefox 6 for developers.
Keywords: dev-doc-needed → dev-doc-complete
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•