[whatwg] Web Workers and postMessage(): Questions
Daniel Gredler
daniel.gredler at gmail.com
Mon Aug 3 10:34:48 PDT 2009
On Sat, Aug 1, 2009 at 4:59 PM, Ian Hickson <ian at hixie.ch> wrote:
> On Wed, 22 Jul 2009, Daniel Gredler wrote:
> >
> > First, why does the structured clone algorithm used by postMessage() [1]
> > throw an exception if it encounters cycles? It seems to me that the
> > memory-based logic which is used to catch cycles could easily be
> > modified to resolve them instead. The only possible reason I can think
> > of is to match JSON semantics, and the only reason I can think of to
> > want to match JSON semantics is to make implementers lives easier
> > (witness Firefox 3.5, which just JSONifies objects passed to
> > postMessage()). However, this is a huge limitation, and I'm not sure
> > that the correct trade-off is to make implementers lives easier at the
> > expense of making web designers lives harder.
>
> Your guess is correct. I imagine we'll lift the restriction eventually; if
> you want to make that happen quicker, then I encourage you to speak
> directly to the browser vendors implementing this, and convince them it'd
> be worth it. :-)
>
I know Anne VK (Opera) and ROC (Mozilla) appear to read this list... any
comments, guys? Should I just file bugs? Any Safari / Chrome / IE guys out
there with comments?
> > Second, why not walk the prototype chain? Similar rules regarding host
> > objects and regular objects could apply to prototypes. You would want to
> > make sure that multiple references to the same prototype instance result
> > in references to a single prototype clone in the cloned object graph.
> > Again, though, it doesn't sound too hard (though I might just be
> > optimistic). Why not make web designers' lives easier?
>
> We're definitely never going to copy function code over, so it's not clear
> that the prototype chain would be that useful. Could you elaborate on your
> use case?
>
I agree that once you've made the decision to not clone functions, cloning
the prototype chain becomes (nearly?) useless. However, I'd be interested to
know the rationale behind this decision, since Web Workers appear to follow
the same-origin policy (e.g. "If the origin of the resulting absolute URL is
not the same as the origin of the script that invoked the constructor, then
throw a security exception", etc). I assume there's a security concern
lurking somewhere?
My specific use case spits out a tree, each node having a reference to its
children and its parent (hence the issue with circular references). Each
node also has a "name" attribute and a function (in the prototype) used to
retrieve the node's "path" (based on its name and its ancestors names) -- I
don't want to precalculate each node's path and keep it in memory, given
that there are tens of thousands of nodes (or more).
> Overall, it just appears that the current web worker spec ignores the
> > class of computational problems involving results which need to be
> > modeled in a complex way.
>
> That's probably a fair criticism, yes.
>
Then I'll see if I can't raise some awareness amongst implementers ;-)
--
Daniel Gredler
http://daniel.gredler.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20090803/9b68d2d3/attachment-0001.htm>
More information about the whatwg
mailing list