This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23892 - Add Map and Set to the Structured Clone algorithm somehow
Summary: Add Map and Set to the Structured Clone algorithm somehow
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-22 20:56 UTC by Ian 'Hixie' Hickson
Modified: 2014-01-04 00:08 UTC (History)
6 users (show)

See Also:


Attachments

Description Ian 'Hixie' Hickson 2013-11-22 20:56:30 UTC
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.
--------------------------------------------------------------------------------
Comment 1 Ian 'Hixie' Hickson 2013-11-22 22:58:20 UTC
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.
Comment 2 Anne 2013-11-25 13:49:56 UTC
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...
Comment 3 Ian 'Hixie' Hickson 2013-12-14 02:10:03 UTC
Anne, do you want to take this bug to own convincing TC39 to do this?
Comment 4 Ian 'Hixie' Hickson 2013-12-16 23:14:20 UTC
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
Comment 5 contributor 2014-01-04 00:08:38 UTC
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