This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
Ideally, we'd move all the cloning of JS-native types to the JS spec (all the relevant text is pasted below), and add Map and Set there. But if they don't want to do that, we can add Map and Set directly to HTML. If anyone would like to work with me to do this on the JS side, please let me know. -------------------------------------------------------------------------------- If input is a Boolean object Let output be a newly constructed Boolean object with the same value as input. If input is a Number object Let output be a newly constructed Number object with the same value as input. If input is a String object Let output be a newly constructed String object with the same value as input. If input is a Date object Let output be a newly constructed Date object with the same value as input. If input is a RegExp object Let output be a newly constructed RegExp object with the same pattern and flags as input. The value of the lastIndex property is not copied. If input is an Array object Let output be a newly constructed empty Array object whose length is equal to the length of input, and set deep clone to true. This means that the length of sparse arrays is preserved. If input is an Object object Let output be a newly constructed empty Object object, and set deep clone to true. [...] If deep clone is set, then, for each enumerable own property in input, run the following steps: Let name be the name of the property. Let source value be the result of calling the [[Get]] internal method of input with the argument name. If the [[Get]] internal method of a property involved executing script, and that script threw an uncaught exception, then abort the overall structured clone algorithm, with that exception being passed through to the caller. Let cloned value be the result of invoking the internal structured cloning algorithm recursively with source value as the "input" argument and memory as the "memory" argument. If this results in an exception, then abort the overall structured clone algorithm, with that exception being passed through to the caller. Add a new property to output having the name name, and having the value cloned value. The order of the properties in the input and output objects must be the same, and any properties whose [[Get]] internal method involves running script must be processed in that same order. This does not walk the prototype chain. Property descriptors, setters, getters, and analogous features are not copied in this process. For example, the property in the input could be marked as read-only, but in the output it would just have the default state (typically read-write, though that could depend on the scripting environment). Properties of Array objects are not treated any differently than those of other Objects. In particular, this means that non-index properties of arrays are copied as well. --------------------------------------------------------------------------------
Tab mentions a desire to define cloning of FontFace objects too. Not clear if that needs a hook in JS or HTML, though. Could probably be done either way.
I think you actually need to know the new realm. I did some work a while back on starting ES-prose around this subject: https://github.com/dslomov-chromium/ecmascript-structured-clone Have not really taken the time yet to convince the rest of TC39 this needs to be done...
Anne, do you want to take this bug to own convincing TC39 to do this?
Anne says that won't happen soon, and to just put it in HTML for now. Hober mentioned: https://bugs.webkit.org/show_bug.cgi?id=120654
Checked in as WHATWG revision r8374. Check-in comment: Define structured cloning for Map and Set http://html5.org/tools/web-apps-tracker?from=8373&to=8374