[whatwg] Structured Clone of Map and Set objects

Tab Atkins Jr. jackalmage at gmail.com
Fri Nov 22 13:18:58 PST 2013


On Fri, Nov 22, 2013 at 12:57 PM, Ian Hickson <ian at hixie.ch> wrote:
> 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

I'd love this hook, as it would let me define cloning behavior of more
complex things, like FontFace objects.

~TJ



More information about the whatwg mailing list