<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 23, 2009, at 4:08 PM, Drew Wilson wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Oh, certainly - I just started looking at the Worker constructor code, so I definitely have no sense of ownership there, so pick away. I was just trying to understand the issues well enough to understand what the Worker code is doing before I steal it :)<div> <br></div><div>Looking at the Workers code (since that happens to be where I'm poking&nbsp;around):</div><div><br></div><div><div>JSWorkerConstructor::JSWorkerConstructor(ExecState* exec)</div><div>&nbsp;&nbsp; &nbsp;: DOMObject(JSWorkerConstructor::createStructure(exec-&gt;lexicalGlobalObject()-&gt;objectPrototype()))</div> <div>{</div><div>&nbsp;&nbsp; &nbsp;<b>putDirect(exec-&gt;propertyNames().prototype, JSWorkerPrototype::self(exec, exec-&gt;lexicalGlobalObject()), None);</b></div><div>&nbsp;&nbsp; &nbsp;putDirect(exec-&gt;propertyNames().length, jsNumber(exec, 1), ReadOnly|DontDelete|DontEnum);</div> <div>}</div><div><br></div><div>It looks like the constructor's .prototype is taken from the originating window (set at the time the constructor itself is created) - I haven't followed the construction code, but I'm guessing that results in the prototype property of new objects being attached to the chain from the original window. Is that incorrect behavior?</div></div></blockquote><br></div><div>The&nbsp;code&nbsp;above&nbsp;means&nbsp;that&nbsp;Worker.prototype&nbsp;is&nbsp;set&nbsp;at&nbsp;the&nbsp;time&nbsp;the&nbsp;Worker&nbsp;constructor&nbsp;itself&nbsp;is&nbsp;created,&nbsp;which&nbsp;is&nbsp;good.&nbsp;In&nbsp;the&nbsp;line&nbsp;you&nbsp;bolded,&nbsp;a&nbsp;fresh&nbsp;prototype&nbsp;object&nbsp;is&nbsp;created,&nbsp;and&nbsp;under&nbsp;the&nbsp;covers&nbsp;it&nbsp;will&nbsp;get&nbsp;cached.&nbsp;However,&nbsp;it&nbsp;looks&nbsp;to&nbsp;me&nbsp;like&nbsp;the&nbsp;Worker&nbsp;wrapper&nbsp;will&nbsp;use&nbsp;the&nbsp;prototype&nbsp;from&nbsp;the&nbsp;Window&nbsp;where&nbsp;the&nbsp;reference&nbsp;is&nbsp;created,&nbsp;rather&nbsp;than&nbsp;the&nbsp;one&nbsp;that&nbsp;the&nbsp;Worker&nbsp;constructor&nbsp;came&nbsp;from.&nbsp;So&nbsp;everything&nbsp;I&nbsp;said&nbsp;may&nbsp;be&nbsp;wrong.&nbsp;Short&nbsp;version:&nbsp;this&nbsp;all&nbsp;needs&nbsp;tests.</div><div><br></div><div>Also,&nbsp;there&nbsp;might&nbsp;be&nbsp;a&nbsp;subtle&nbsp;bug&nbsp;in&nbsp;the&nbsp;above&nbsp;code: what if window.Worker is first accessed from a different frame? Then the prototype of the Worker constructor itself will use the other frame's Object prototype as its prototype. I'm not sure if that is right. I think maybe JSWorkerConstructor should be passed the global object from which it is retrieved as a property, instead of using the lexical global object.</div><div><br></div><div>Regards,</div><div>Maciej</div><div><br></div></body></html>