[whatwg] Web Workers and postMessage(): Questions

Ian Hickson ian at hixie.ch
Wed Aug 12 16:28:16 PDT 2009


On Mon, 3 Aug 2009, Daniel Gredler wrote:
> On Sat, Aug 1, 2009 at 4:59 PM, Ian Hickson <ian at hixie.ch> wrote:
> > On Wed, 22 Jul 2009, Daniel Gredler wrote:
> > > 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?

Workers obey the same-origin policy for creation, but you can easily pass 
ports around so that non-same-origin code can talk to your worker.


> 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).

Serialise the tree and pass the serialised version, then reconstruct the 
objects on the other side.

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


More information about the whatwg mailing list