I&#39;m not certain what a &quot;deep copy&quot; of the function means - would you need to copy the entire lexical scope of the function? For example, let&#39;s say you do this:<div><br></div><div>var foo = 1;</div><div><br>
</div><div>function setFoo(val) { foo = val; }</div><div>function getFoo() { return foo; }</div><div><br><div>worker.postMessage(setFoo);</div><div>worker.postMessage(getFoo);</div><div><br></div><div>foo = 2;</div><div><br>
</div><div>Then, from worker code, I call the copy of getFoo() - what should it return (undefined? Does it pull over a copy of foo from the original lexical scope, in which case it&#39;s 1)? What if foo is defined in a lexical closure that is shared by both setFoo() and getFoo() - it seems like the separate copies of setFoo() and getFoo() passed to the worker would need to reconstruct a shared closure on the worker side, which seems difficult if not impossible.</div>
<div><br></div><div>I think that some variant of data URLs and/or eval() gets you most of what you really need here without requiring extensive JS VM gymnastics.</div><div><br></div><div>-atw</div><div><br><div class="gmail_quote">
On Wed, Dec 16, 2009 at 9:23 AM, Jan Fabry <span dir="ltr">&lt;<a href="mailto:jan.fabry@monkeyman.be">jan.fabry@monkeyman.be</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello,<br>
<br>
Has it been considered to pass more than JSON data to workers? I could not find a rationale behind this in the FAQ, or in other places I looked. I understand the need for separation because of concurrency issues, but aren&#39;t there other ways to accomplish this?<br>

<br>
(The following text was already posted to the forum, but &quot;zcorpan&quot; suggested I also post it here)<br>
[ <a href="http://forums.whatwg.org/viewtopic.php?t=4185" target="_blank">http://forums.whatwg.org/viewtopic.php?t=4185</a> ]<br>
<br>
I am not a Javascript VM developer, so if the following does not make sense, please don&#39;t be too hard on me. A reply of &quot;Sorry, we thought about this longer than you did, and there are still cases where this is impossible&quot; is perfectly valid, but the more I can learn from this conversation, the better.<br>

<br>
Would it be possible to do a deep copy of the function (object) you pass to the the constructor? So copy everything (or mark it for copy-on-write), but remove references to DOM elements if they exist. This way, I think you can create a parallel data structure, so the original one remains untouched (avoiding concurrency issues).<br>

<br>
The important difference between this and the usual JSON-serializing of objects that the examples talk about, is that functions can be passed through too in an easy manner. If you have to simulate this using only Javascript, you have to somehow bind the free variables, which requires some introspection, and thus is not easy (if even possible?) to simulate in &quot;user space&quot;.<br>

<br>
The Google Gears API seems to provide both createWorker(scriptText) and createWorkerFromUrl(scriptUrl). Why was only the URL variant retained in the Web Workers spec? With the script variant, there would have been at least a little basis for more dynamic programming.<br>

<br>
Greetings,<br>
<font color="#888888"><br>
Jan Fabry</font></blockquote></div><br></div></div>