views:

302

answers:

1

I know its part of the HTML5 spec, but sometimes WebKit doesn't conform to the latest draft of the spec.

+1  A: 

Alas WebKit's worker postMessage implementation doesn't currently serialise objects as it was written to an earlier version of the spec, and hasn't yet been updated to match the "final" version.

It's not actually JSON either -- it's the internal structured cloning algorithm in html5, which is more efficient (it doesn't need to convert to and from string) and actually somewhat richer than JSON, however no one currently implements that :-(

olliej
Interesting, so it sounds like its pretty much as I suspected. Given this, I have an app with two web workers, and they pass js objects around just fine now in >= fox 3.5, but not in Chrome. So how would I fix this?
gmiernicki
Your best bet would be to add a small test to check to see whether postMessage serialises, and if it does not just do JSON.stringify and JSON.parse manually. It's best to do it this way so that it works on all webkit ports -- chrome is just another port of apple's webkit and you don't want to break all of the others (esp. Safari)
olliej
Sounds cool, I'll try this out next week when I get back from vacation :)
gmiernicki