This is the bocoup web log with posts from Al, Boaz, Rick, Sam, Nate, Nick & Pete. You should also make sure to checkout code.bocoup.com, where we keep the finished versions of ideas we kick around here.


May 26, 2010

Javascript Web Workers: Chrome 5 Now Supports Complex Messages

After updating to Chrome 5 (specifically 5.0.375.55) last night I immediately ran some tests to see if the Web Worker API had been updated to support postMessage() arguments of types other than string.


Turns out, it had.


Here’s the test, plus the results:
http://gist.github.com/414901




I did small bit of research and could only come up with this ticket:

Issues in passing parameters to HTML5 worker threads

*Edit*
In the time since this was originally published, Chrome, Safari & Opera now support complex JSON messages.



Comments:

6 Comments

  1. Posted May 26, 2010 at 4:25 pm | Permalink

    first and second posts are both json’s non of it is an object.

  2. Rick Waldron
    Posted May 26, 2010 at 5:30 pm | Permalink

    @Irakli I checked out your site and you have a really impressive portfolio of work, so I’m not sure why you’ve left a comment like this.

    All JSON is an object. All Objects are not JSON.

    I’ve added an additional test, that used the new Object constructor… is that acceptable for you? I don’t think you can argue that a variable created with new Object() is not an object.

    Thanks for the feedback.

  3. Posted May 27, 2010 at 3:13 am | Permalink

    I am brand new to web workers but I’m already loving them. Especially seeing as you can now return more than e.g. ‘I is tha hello world str’.

    Are there (m)any examples of hooking up to the web sql(lite) db using a worker?

    Let’s hope my brain doesn’t melt and my eyes don’t bleed out of their sockets before I get all of this new information in :)

  4. Posted May 27, 2010 at 3:15 pm | Permalink

    Hey, great, nice to see Chrome catching up to Firefox on supporting this.

  5. Posted June 2, 2010 at 5:17 am | Permalink

    Hi,

    Great post, great information. Arrived here via an Ajaxian post. Web workers is great news, and the browser support for it is very exciting!

    I am curious about your first example code, however. Specifically, the line that assigns obj.resultOf to an anonymous function. Because the closure is immediately executed, it would appear that the typeof the obj.resultOf property would be === string, since the result of the immediate function is also === string. I haven’t tested to see if simply obj.resultOf = function (){ return “string”;}; works as expected, but that would be the assignment of a function, as otherwise it’s simply an obfuscated way to assign a string value to the variable.

    Or perhaps I missed the point entirely? ;-)

  6. Rick Waldron
    Posted June 7, 2010 at 3:44 pm | Permalink

    The closure is supposed to evaluate, hence it’s returned value saying so…

    obj.resultOf = function (){ return “string”;}

    is not thread safe and would not work, which is why I didn’t use it as an example

One Trackback

  1. [...] This post was mentioned on Twitter by rick waldron, rick waldron and jen strickland ★, nexus11. nexus11 said: RT @rwaldronBlog: Javascript Web Workers: Chrome 5 Now Supports Complex Messages http://gul.ly/6y #html5 #webkit #v8: Blog: Javascript… [...]




Please send your questions to this address or call Bocoup at 617-379-2752
This web page is proudly maintained by Bocoup and hosted by (mt) Media Temple
All code on this website is Open Source