[whatwg] Serialization of expandos on String / Boolean / Number objects

Ian Hickson ian at hixie.ch
Thu Aug 23 14:07:44 PDT 2012

On Thu, 23 Aug 2012, Dumez, Christophe wrote:
> The latest specification of the structured clone algorithm [1] does not 
> indicate that we are supposed to serialize expandos on objects such as 
> String, Boolean or Number.
> For example:
> var str = new String("test");
> str.foo = 3;
> window.postMessage(str, "*");
> Isn't str.foo property supposed to be serialized? If I read the
> specification correctly, it is not:
> """
> If input is a String object
>          Let output be a newly constructed String object with the same
> value as input.
> """
> Is this behavior really intended? I think it would make sense to
> serialize the properties attached to such objects.

On Thu, 23 Aug 2012, Tab Atkins Jr. wrote:
> As far as I can tell, the Structured Clone algorithm has mostly bottomed 
> out into JSON, so the loss of expandos on those builtins is intentional 
> - keeping them would mean serializing them as objects, rather than as 
> literals.

This is correct. With some exceptions (like Blobs and supporting cycles), 
we are trying to be close to JSON in terms of the basic data structure.

Supporting things like Strings as primitive types would also make 
conversion to other languages much more complicated (most languages don't 
have a concept of "object whose value is a string plus a dictionary").

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