Interruption of JavaScript functions execution
<p>I have html page with javascript:</p>

<pre><code>&lt;!DOCTYPE html&gt;

    &lt;html&gt;

        &lt;head&gt;
            &lt;script&gt;
                function doWork() {
                     console.log("\tdoWork-start");
                     var now = new Date();
                     var end = now.getTime() + 2000;
                     while(now &lt; end) {
                        now = new Date();
                     }
                     console.log("\tdoWork-end");
                }

                function handleOnClick() {
                    console.log("onclick-start");
                    console.log("onclick-end");
                }

                function handleOnchange() {
                    console.log("onchange-start");
                    window.open('', 'name', 'height=300,width=600,top=200,left=200');
                    doWork();
                    console.log("onchange-end");
                }
            &lt;/script&gt;
        &lt;/head&gt;

        &lt;body&gt;
            &lt;form&gt;
                &lt;input type="text" onchange="handleOnchange();"&gt;
                &lt;input type="button" value="ok" onclick="handleOnClick();"&gt;
            &lt;/form&gt;

        &lt;/body&gt;

    &lt;/html&gt;
</code></pre>

<p>Use case: enter some value in input control and quickly click the button.
I expect such logs in console:</p>

<pre><code>onchange-start
    doWork-start
    doWork-end
onchange-end
onclick-start
onclick-end
</code></pre>

<p>But in Firefox I've got:</p>

<pre><code>onchange-start
onclick-start
onclick-end
    doWork-start
    doWork-end
onchange-end
</code></pre>

<p>Notice, that onclick execution interrupts onchange execution. Function doWork emulates some long work. 
In Chrome it works as expected.</p>

<p>Can anybody explain how is that possible?</p>
