Thanks Sam,<div><br></div><div>I&#39;ve sent a patch with a test.</div><div><br></div><div>Dmitry<br><br><div class="gmail_quote">On Mon, Dec 1, 2008 at 7:23 PM, Sam Weinig <span dir="ltr">&lt;<a href="mailto:sam.weinig@gmail.com">sam.weinig@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="Ih2E3d"><span style="border-collapse:collapse">Hi Dmitry,<div><br></div><div>The first example using a closure executes in the parent scope because functions execute in lexical scope regardless of where they are called from, capturing variables as required. &nbsp;The string version is simply executed as a program by the caller and has no knowledge of the scope in which it was declared. &nbsp;This is a bit strange, but follows the conventions of the language. &nbsp;As for the test, tests are always welcomed, especially for odd edges like this.</div>

<div><br></div><div>-Sam</div></span><br></div><div class="gmail_quote"><div class="Ih2E3d">On Mon, Dec 1, 2008 at 8:08 PM, Dmitry Titov <span dir="ltr">&lt;<a href="mailto:dimich@chromium.org" target="_blank">dimich@chromium.org</a>&gt;</span> wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="Wj3C7c">
<div>Hi webkit-dev,</div><div><br></div><div>I&#39;m looking at JS timeout code and found a callback behavior that seems strange. Not sure if it is intentional.&nbsp;</div><div>If timeout is set on a &#39;window&#39; object from another frame and timeout callback is specified as a JS string, it is executed &quot;inside the frame&quot;... So the context of execution is different depending how the callback is specified.&nbsp;</div>


<div><br></div><div>Here is html (also attached) that loads an empty IFRAME and sets 2 timeouts on that iframe&#39;s window - as a JS closure and as JS string. In former case, the callback runs in the main page (expected, since the JS closure &#39;captures&#39; the context in which it is defined), in the latter- inside iframe (a bit weird?). So the text goes in both &quot;body&quot; elements.&nbsp;</div>


<div><br></div><div>Is there a reason why JS string is evaluated in the inner context of the iframe? Would a test verifying this behavior be a good thing?&nbsp;Curiously, IE and FF behave the same way.&nbsp;</div><div><br></div><div>


&lt;html&gt;<br></div><div><div>&lt;script&gt;</div><div>function test() {</div><div>&nbsp;&nbsp;// Get the iframe&#39;s window.</div><div>&nbsp;&nbsp;var iframeWindow = window.frames[&quot;testIframe&quot;];</div><div><br></div><div>&nbsp;&nbsp;// setTimeout with a closure as callback.</div>


<div>&nbsp;&nbsp;iframeWindow.setTimeout(</div><div>&nbsp;&nbsp; &nbsp;function() {&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;if (!document.body)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;document.write(&#39;&lt;body&gt;&lt;/body&gt;&#39;);</div><div>&nbsp;&nbsp; &nbsp; &nbsp;document.body.appendChild(document.createTextNode(&#39;Timer 1 fired.&#39;));}, 1);</div>


<div><br></div><div>&nbsp;&nbsp;// setTimeout with a JS string containing similar code.</div><div>&nbsp;&nbsp;iframeWindow.setTimeout(</div><div>&nbsp;&nbsp; &nbsp; &quot;if (!document.body)&quot; +</div><div>&nbsp;&nbsp; &nbsp; &quot; &nbsp;document.write(&#39;&lt;body&gt;&lt;/body&gt;&#39;);&quot; +</div>


<div>&nbsp;&nbsp; &nbsp; &quot;document.body.appendChild(document.createTextNode(&#39;Timer 2 fired.&#39;));&quot;, 1);</div><div>}</div><div>&lt;/script&gt;</div><div>&lt;body onLoad=&quot;test();&quot;&gt;</div><div>&lt;iframe src=&quot;about:blank&quot; id=&quot;testIframe&quot;&gt;&lt;/iframe&gt;</div>


<div>&lt;/body&gt;</div><div>&lt;/html&gt;</div><div><br></div><div><br></div><div>Thanks,</div><div>Dmitry</div></div>
<br></div></div><div class="Ih2E3d">_______________________________________________<br>
webkit-dev mailing list<br>
<a href="mailto:webkit-dev@lists.webkit.org" target="_blank">webkit-dev@lists.webkit.org</a><br>
<a href="http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev" target="_blank">http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev</a><br>
<br></div></blockquote></div><br>
</blockquote></div><br></div>