[whatwg] Structured Clone of Map and Set objects

Ian Hickson ian at hixie.ch
Fri Nov 22 12:57:52 PST 2013


On Wed, 4 Sep 2013, Oliver Hunt wrote:
>
> The current structured clone algorithm does not include support for the 
> Map and Set types, so a developer would need to manually implement the 
> serialisation and deserialisation.  While this would not be impossible 
> it does seem like it is an unnecessary inconvenience for a core type in 
> ES6.
> 
> The semantics of Map and Set are stable so unless someone objects i see 
> no reason we should not amend the internal structured clone algorithm to 
> specially handle Set and Map in addition to Array.  To support cloning 
> of Map and Set we will want to recursively call the structured clone 
> algorithm on each key or key/value pair in the %SetData% or %MapData% 
> internal arrays, and maintain the order of those entries (as the Map/Set 
> ordering is well defined)

On Wed, 4 Sep 2013, Anne van Kesteren wrote:
> 
> I suggested this to TC39 a while back and I still think it's a good idea 
> even though reception was lukewarm at best (the people replying didn't 
> like to acknowledge the existence of this seemed like). They should 
> define this as a primitive of the Object type and define which objects 
> support it and how. The monkey patching we do now is not great.

I agree with Anne that it'd be better if the JS spec just defined how to 
clone the various JS types natively.

Would anyone who works on the JS spec like to work with me to move the 
relevant parts over and define an appropriate hook for the HTML spec to 
invoke in the structured clone algorithm? (All that's needed is a hook 
that takes a value, and returns a new value that's a clone of the first, 
with a different realm, if I understand it right.)

I've filed this bug to track this:

   https://www.w3.org/Bugs/Public/show_bug.cgi?id=23892

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list