[whatwg] postMessage and serialization

On Mon, 11 Feb 2008, Aaron Boodman wrote:
>
> Has the topic of automatic serialization and deserialization of objects 
> passed across postMessage() come up already? It seems like boolean, 
> number, string, arrays, and objects should be supported.
> 
> I realize that you can just use a json library, but I wonder why we 
> should force every application that wants to use postMessage() to 
> include a json library when the browser can just do the right thing 
> automatically.

This was originally how the DOM Storage API worked, but there was 
significant pushback on this, resulting in the current string-only 
approach. When I came to writing the postMessage API, I considered that 
feedback and decided not to bother even trying.

Passing booleans, numbers and strings is trivial using the current API. 
Passing arrays of booleans and numbers is trivial too.

Passing objects, or arrays of strings, arrays, or objects, is more 
complex, but as you point out, it can be done using JSON libraries. Since 
it is likely that JSON will be supported natively by UAs in due course, it 
seems better to wait for that support rather than adding type support to 
postMessage().

It seems that most messages will consist either of simple strings, or of 
complex data structures (objects). Reconstructing JS objects is not a 
trivial operation; you have to worry about references into other parts of 
the structure, getters and setters that hang or throw or return infinite 
arrays, functions, members that aren't enumerable, etc. I'd rather not go 
down that rat hole with v1.

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

Received on Tuesday, 12 February 2008 16:57:51 UTC