[whatwg] Web Workers and postMessage(): Questions
Drew Wilson
atwilson at google.com
Mon Aug 3 10:50:56 PDT 2009
On Mon, Aug 3, 2009 at 10:34 AM, Daniel Gredler <daniel.gredler at gmail.com>wrote:
>
>> 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?
>
I've often had the same thought (that there's no reason we shouldn't handle
cycles when implementing structured clones).
That said, I'm compelled to point out that WebKit browsers only support
string messages currently (they don't yet implement the structured clone
part of the spec). And none of the currently shipping browsers support
MessagePorts or SharedWorkers (although WebKit browsers are getting these
soon). So given that there's a workaround for the lack of support for cycles
in structured clones (applications can do their own serialization) but
there's no app-level workaround for the lack of SharedWorkers, I'd rather
see vendors concentrate on implementing the current spec before adding
greater support for cloning message parameters.
>
> 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?
>
It's not clear to me how you'd clone the lexical scope of a function and
carry it over to the worker in a way that doesn't cause synchronization
issues.
Case in point:
var obj = {};
var foo = "abc";
obj.bar = function() { foo = "def"; }
sharedWorker.port.postMessage(obj);
Now, from shared worker scope, you have the ability to directly access the
variable "foo" from a different thread/process, which is not really
implementable.
-atw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20090803/3a7d14f7/attachment.htm>
More information about the whatwg
mailing list