Closed Bug 550275 Opened 14 years ago Closed 14 years ago

Implement the HTML5 structured clone algorithm

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: bent.mozilla, Assigned: bent.mozilla)

References

()

Details

(Keywords: html5)

Attachments

(2 files, 2 obsolete files)

Attached patch Rough WIP, nonrecursive version (obsolete) — Splinter Review
http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#safe-passing-of-structured-data

This will allow us to clone JS objects without using JSON for postMessage, etc.

The algorithm is recursive and I've got a recursive version of it implemented but I like the nonrecursive version better.
Keywords: html5
Hardware: x86 → All
Attached patch Patch, v1 (obsolete) — Splinter Review
This should do it, for now.
Attachment #430396 - Attachment is obsolete: true
Attachment #430789 - Flags: review?(mrbkap)
Attachment #430789 - Flags: review?(jst)
window.postMessage should be using this as well, right?  Sibling patch to the worker-specific bits, methinks.
Comment on attachment 430789 [details] [diff] [review]
Patch, v1

Looks good to me, but I do think mrbkap or someone in the JS team should look over the JS specific parts, especially the changes to the JS engine headers. I know Andreas was going through and doing a bunch of the opposite of what this patch does in the headers, so he'll probably have some thoughts on this too.
Attachment #430789 - Flags: review?(jst) → review+
Attachment #430790 - Flags: superreview?(jst)
Attachment #430790 - Flags: superreview+
Attachment #430790 - Flags: review?(jst)
Attachment #430790 - Flags: review+
(In reply to comment #4)
> (From update of attachment 430789 [details] [diff] [review])
> Looks good to me, but I do think mrbkap or someone in the JS team should look
> over the JS specific parts, especially the changes to the JS engine headers. I
> know Andreas was going through and doing a bunch of the opposite of what this
> patch does in the headers, so he'll probably have some thoughts on this too.

Andreas was removing #include "js*.h" from nsContentUtils.h and other widely included .h files. That's bad and to be avoided, but narrow #includes in a .cpp or two are ok, or at least not as bad. Seems like we could provide first-class API and avoid these, though. Followup bug?

/be
If anyone tries to include (again) non-public JS headers (anything but jsapi.h and jspubtd.h) in external header files, especially header files that get included all over the place (hi there nsContentUtils.h), I am going to get out the pitchforks. Removing a couple lines reduced my re-build time by 30 minutes (no more rebuilding SVG is you touch jsnum.h). Including stuff in .cpp files is ugly, but not that big of a deal (as far as build time is concerned). I will touch base with bent to see what proper external interface we might need here.
gal says this friend-y stuff is fine for now, I'll file a followup on exposing proper API for this.
Comment on attachment 430789 [details] [diff] [review]
Patch, v1

I talked this over with Ben and gave him some comments. He'll post a new patch.
Attachment #430789 - Flags: review?(mrbkap)
A random idea, feel free to disregard. Using proxies you could do lazy on-demand copying. You grab the root object, make a transparent proxy for it, send it over. If any parts of it are touched, it generates proxies for all of its object properties, and then fixes itself (turns itself into a regular object, fast, no trace of it being formerly a proxy). If the objects are touched, the same happens and propagates until everything has been pulled over.
Attached patch Patch, v1.1Splinter Review
This patch incorporates fixes suggested by mrbkap. Specifically, we're using auto-helpers in CloneStackFrame now, using JSVAL_IS_PRIMITIVE, JS_DefinePropertyById (instead of JS_SetPropertyById) and aborting reparenting when we see a JSObject that has a non-standard proto key.
Attachment #430789 - Attachment is obsolete: true
Attachment #433118 - Flags: review?(mrbkap)
Comment on attachment 433118 [details] [diff] [review]
Patch, v1.1

I like it! I asked bent on IRC about a few small problems that he'll fix. r=mrbkap with those fixed.
Attachment #433118 - Flags: review?(mrbkap) → review+
Blocks: 538142
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: