Thanks Sam,<div><br></div><div>I'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"><<a href="mailto:sam.weinig@gmail.com">sam.weinig@gmail.com</a>></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. The string version is simply executed as a program by the caller and has no knowledge of the scope in which it was declared. This is a bit strange, but follows the conventions of the language. 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"><<a href="mailto:dimich@chromium.org" target="_blank">dimich@chromium.org</a>></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'm looking at JS timeout code and found a callback behavior that seems strange. Not sure if it is intentional. </div><div>If timeout is set on a 'window' object from another frame and timeout callback is specified as a JS string, it is executed "inside the frame"... So the context of execution is different depending how the callback is specified. </div>
<div><br></div><div>Here is html (also attached) that loads an empty IFRAME and sets 2 timeouts on that iframe'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 'captures' the context in which it is defined), in the latter- inside iframe (a bit weird?). So the text goes in both "body" elements. </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? Curiously, IE and FF behave the same way. </div><div><br></div><div>
<html><br></div><div><div><script></div><div>function test() {</div><div> // Get the iframe's window.</div><div> var iframeWindow = window.frames["testIframe"];</div><div><br></div><div> // setTimeout with a closure as callback.</div>
<div> iframeWindow.setTimeout(</div><div> function() { </div><div> if (!document.body)</div><div> document.write('<body></body>');</div><div> document.body.appendChild(document.createTextNode('Timer 1 fired.'));}, 1);</div>
<div><br></div><div> // setTimeout with a JS string containing similar code.</div><div> iframeWindow.setTimeout(</div><div> "if (!document.body)" +</div><div> " document.write('<body></body>');" +</div>
<div> "document.body.appendChild(document.createTextNode('Timer 2 fired.'));", 1);</div><div>}</div><div></script></div><div><body onLoad="test();"></div><div><iframe src="about:blank" id="testIframe"></iframe></div>
<div></body></div><div></html></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>