W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2009

[whatwg] Web Workers and postMessage(): Questions

From: Drew Wilson <atwilson@google.com>
Date: Mon, 3 Aug 2009 10:50:56 -0700
Message-ID: <f965ae410908031050g4ccb1059g7e8dceaa94322b78@mail.gmail.com>
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>
Received on Monday, 3 August 2009 10:50:56 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:15 UTC