W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2008

[whatwg] postMessage and serialization

From: Ian Hickson <ian@hixie.ch>
Date: Wed, 13 Feb 2008 00:57:51 +0000 (UTC)
Message-ID: <Pine.LNX.4.62.0802130052510.20115@hixie.dreamhostps.com>
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

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:39 UTC