<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[47914] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/47914">47914</a></dd>
<dt>Author</dt> <dd>atwilson@chromium.org</dd>
<dt>Date</dt> <dd>2009-08-31 16:40:08 -0700 (Mon, 31 Aug 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebCore: fast/workers/worker-lifecycle.html crashes intermittently on snowleopard
https://bugs.webkit.org/show_bug.cgi?id=28795

Reviewed by Alexey Proskuryakov.

Changed WorkerContext::close() to no longer stop the worker thread.
It is now the parent's responsibility to shut down the worker thread when it is notified that the context is closed.

* workers/AbstractWorker.cpp:
Updated dispatchScriptErrorEvent to pass-through the &quot;handled&quot; value from dispatchEvent(), to allow event handlers added with addEventListener() to mark events as handled.
* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerProxy::workerContextClosed):
Now shuts down the worker thread when notified that the context is closed.
(WebCore::SharedWorkerProxy::close):
Now handles being invoked when the context is already in the process of shutting down.
* workers/WorkerContext.cpp:
(WebCore::WorkerContext::close):
No longer calls WorkerThread::stop() to avoid race conditions with shutting down the thread while the parent is still interacting with it.
* workers/WorkerContext.h:
(WebCore::WorkerContext::isClosing):
isClosing() is now public so WorkerRunLoop can call it to determine whether to process tasks.
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerExceptionTask::performTask):
Error events should still be delivered even if the worker thread is closing.
Also fixed problem where error events were not dispatched if error handlers were added via addEventListener().
(WebCore::WorkerTerminateTask::create):
New task that invokes terminateWorkerContext() on the parent thread when the context is closed.
(WebCore::WorkerTerminateTask::WorkerTerminateTask):
(WebCore::WorkerTerminateTask::performTask):
(WebCore::WorkerMessagingProxy::workerContextClosed):
Now fires off a WorkerTerminateTask to shut down the thread when the context is closed.
* workers/WorkerMessagingProxy.h:
WorkerMessagingProxy now overrides workerContextClosed().
* workers/WorkerRunLoop.cpp:
(WebCore::WorkerRunLoop::runInMode):
Now drops tasks on the floor if the WorkerContext is closing.

LayoutTests: fast/workers/worker-lifecycle.html crashes intermittently on snowleopard
https://bugs.webkit.org/show_bug.cgi?id=28795

Reviewed by Alexey Proskuryakov.

Removed worker-lifecycle.html from the list of Skipped tests since it no longer crashes.
Added test for case where we capture script errors via an event listener added via addEventListener().

* fast/workers/worker-script-error.html
* fast/workers/worker-script-error-expected.txt
Added testScriptErrorAddEventListener to test catching script errors via addEventListener().
* platform/mac-snowleopard/Skipped:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastworkersworkerscripterrorexpectedtxt">trunk/LayoutTests/fast/workers/worker-script-error-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastworkersworkerscripterrorhtml">trunk/LayoutTests/fast/workers/worker-script-error.html</a></li>
<li><a href="#trunkLayoutTestsplatformmacsnowleopardSkipped">trunk/LayoutTests/platform/mac-snowleopard/Skipped</a></li>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCoreworkersAbstractWorkercpp">trunk/WebCore/workers/AbstractWorker.cpp</a></li>
<li><a href="#trunkWebCoreworkersDefaultSharedWorkerRepositorycpp">trunk/WebCore/workers/DefaultSharedWorkerRepository.cpp</a></li>
<li><a href="#trunkWebCoreworkersWorkerContextcpp">trunk/WebCore/workers/WorkerContext.cpp</a></li>
<li><a href="#trunkWebCoreworkersWorkerContexth">trunk/WebCore/workers/WorkerContext.h</a></li>
<li><a href="#trunkWebCoreworkersWorkerMessagingProxycpp">trunk/WebCore/workers/WorkerMessagingProxy.cpp</a></li>
<li><a href="#trunkWebCoreworkersWorkerMessagingProxyh">trunk/WebCore/workers/WorkerMessagingProxy.h</a></li>
<li><a href="#trunkWebCoreworkersWorkerRunLoopcpp">trunk/WebCore/workers/WorkerRunLoop.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/LayoutTests/ChangeLog        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2009-08-31  Drew Wilson  &lt;atwilson@google.com&gt;
+
+        Reviewed by Alexey Proskuryakov.
+
+        fast/workers/worker-lifecycle.html crashes intermittently on snowleopard
+        https://bugs.webkit.org/show_bug.cgi?id=28795
+
+        Removed worker-lifecycle.html from the list of Skipped tests since it no longer crashes.
+        Added test for case where we capture script errors via an event listener added via addEventListener().
+
+        * fast/workers/worker-script-error.html
+        * fast/workers/worker-script-error-expected.txt
+        Added testScriptErrorAddEventListener to test catching script errors via addEventListener().
+        * platform/mac-snowleopard/Skipped:
+
</ins><span class="cx"> 2009-08-31  Beth Dakin  &lt;bdakin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Rubber-stamped by Mark Rowe.
</span></span></pre></div>
<a id="trunkLayoutTestsfastworkersworkerscripterrorexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/workers/worker-script-error-expected.txt (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/workers/worker-script-error-expected.txt        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/LayoutTests/fast/workers/worker-script-error-expected.txt        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -3,6 +3,7 @@
</span><span class="cx"> 
</span><span class="cx"> PASS: onerror invoked for a script that has invalid syntax.
</span><span class="cx"> PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 1.
</span><ins>+PASS: event listener invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 1.
</ins><span class="cx"> PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7.
</span><span class="cx"> PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7.
</span><span class="cx"> PASS: onerror invoked for a script that has script error 'ReferenceError: Can't find variable: foo' at line 7.
</span></span></pre></div>
<a id="trunkLayoutTestsfastworkersworkerscripterrorhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/workers/worker-script-error.html (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/workers/worker-script-error.html        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/LayoutTests/fast/workers/worker-script-error.html        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -10,6 +10,7 @@
</span><span class="cx"> var testCases = [
</span><span class="cx">     &quot;testInvalidScriptSyntax&quot;,
</span><span class="cx">     &quot;testScriptErrorUnhandled&quot;,
</span><ins>+    &quot;testScriptErrorAddEventListener&quot;,
</ins><span class="cx">     &quot;testErrorInHandlingScriptError&quot;,
</span><span class="cx">     &quot;testScriptErrorBubbledAndHandledInWorker&quot;,
</span><span class="cx">     &quot;testScriptErrorBubbledAndReportedToUser&quot;,
</span><span class="lines">@@ -59,6 +60,22 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function testScriptErrorAddEventListener()
+{
+    try {
+        var worker = new Worker(&quot;resources/worker-script-error-unhandled.js&quot;);
+        worker.addEventListener(&quot;error&quot;,
+            function(evt) {
+                log(&quot;PASS: event listener invoked for a script that has script error '&quot; + evt.message + &quot;' at line &quot; + evt.lineno + &quot;.&quot;);
+                runNextTest();
+                evt.preventDefault();
+            }, false);
+    } catch (ex) {
+        log(&quot;FAIL: unexpected exception &quot; + ex);
+        runNextTest();
+    }
+}
+
</ins><span class="cx"> function testErrorInHandlingScriptError()
</span><span class="cx"> {
</span><span class="cx">     try {
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacsnowleopardSkipped"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac-snowleopard/Skipped (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-snowleopard/Skipped        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/LayoutTests/platform/mac-snowleopard/Skipped        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -40,6 +40,3 @@
</span><span class="cx"> 
</span><span class="cx"> #&lt;rdar://problem/7144583&gt; - Intermittent failure
</span><span class="cx"> svg/css/glyph-orientation-rounding-test.xhtml
</span><del>-
-#https://bugs.webkit.org/show_bug.cgi?id=28795 - failure grabbing mutex lock
-fast/workers/worker-lifecycle.html
</del></span></pre></div>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/WebCore/ChangeLog        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2009-08-31  Drew Wilson  &lt;atwilson@google.com&gt;
+
+        Reviewed by Alexey Proskuryakov.
+
+        fast/workers/worker-lifecycle.html crashes intermittently on snowleopard
+        https://bugs.webkit.org/show_bug.cgi?id=28795
+
+        Changed WorkerContext::close() to no longer stop the worker thread.
+        It is now the parent's responsibility to shut down the worker thread when it is notified that the context is closed.
+
+        * workers/AbstractWorker.cpp:
+        Updated dispatchScriptErrorEvent to pass-through the &quot;handled&quot; value from dispatchEvent(), to allow event handlers added with addEventListener() to mark events as handled.
+        * workers/DefaultSharedWorkerRepository.cpp:
+        (WebCore::SharedWorkerProxy::workerContextClosed):
+        Now shuts down the worker thread when notified that the context is closed.
+        (WebCore::SharedWorkerProxy::close):
+        Now handles being invoked when the context is already in the process of shutting down.
+        * workers/WorkerContext.cpp:
+        (WebCore::WorkerContext::close):
+        No longer calls WorkerThread::stop() to avoid race conditions with shutting down the thread while the parent is still interacting with it.
+        * workers/WorkerContext.h:
+        (WebCore::WorkerContext::isClosing):
+        isClosing() is now public so WorkerRunLoop can call it to determine whether to process tasks.
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerExceptionTask::performTask):
+        Error events should still be delivered even if the worker thread is closing.
+        Also fixed problem where error events were not dispatched if error handlers were added via addEventListener().
+        (WebCore::WorkerTerminateTask::create):
+        New task that invokes terminateWorkerContext() on the parent thread when the context is closed.
+        (WebCore::WorkerTerminateTask::WorkerTerminateTask):
+        (WebCore::WorkerTerminateTask::performTask):
+        (WebCore::WorkerMessagingProxy::workerContextClosed):
+        Now fires off a WorkerTerminateTask to shut down the thread when the context is closed.
+        * workers/WorkerMessagingProxy.h:
+        WorkerMessagingProxy now overrides workerContextClosed().
+        * workers/WorkerRunLoop.cpp:
+        (WebCore::WorkerRunLoop::runInMode):
+        Now drops tasks on the floor if the WorkerContext is closing.
+
</ins><span class="cx"> 2009-08-31  Ojan Vafai  &lt;ojan@chromium.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Not reviewed (build fix)
</span></span></pre></div>
<a id="trunkWebCoreworkersAbstractWorkercpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/workers/AbstractWorker.cpp (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/workers/AbstractWorker.cpp        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/WebCore/workers/AbstractWorker.cpp        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -130,7 +130,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ExceptionCode ec = 0;
</span><del>-    dispatchEvent(event.release(), ec);
</del><ins>+    handled = !dispatchEvent(event.release(), ec);
</ins><span class="cx">     ASSERT(!ec);
</span><span class="cx"> 
</span><span class="cx">     return handled;
</span></span></pre></div>
<a id="trunkWebCoreworkersDefaultSharedWorkerRepositorycpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/workers/DefaultSharedWorkerRepository.cpp (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/workers/DefaultSharedWorkerRepository.cpp        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/WebCore/workers/DefaultSharedWorkerRepository.cpp        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -62,7 +62,6 @@
</span><span class="cx">     void setThread(PassRefPtr&lt;SharedWorkerThread&gt; thread) { m_thread = thread; }
</span><span class="cx">     SharedWorkerThread* thread() { return m_thread.get(); }
</span><span class="cx">     bool isClosing() const { return m_closing; }
</span><del>-    void close();
</del><span class="cx">     KURL url() const { return m_url.copy(); }
</span><span class="cx">     String name() const { return m_name.copy(); }
</span><span class="cx">     bool matches(const String&amp; name, PassRefPtr&lt;SecurityOrigin&gt; origin) const { return name == m_name &amp;&amp; origin-&gt;equal(m_origin.get()); }
</span><span class="lines">@@ -87,6 +86,8 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     SharedWorkerProxy(const String&amp; name, const KURL&amp;, PassRefPtr&lt;SecurityOrigin&gt;);
</span><ins>+    void close();
+
</ins><span class="cx">     bool m_closing;
</span><span class="cx">     String m_name;
</span><span class="cx">     KURL m_url;
</span><span class="lines">@@ -158,7 +159,9 @@
</span><span class="cx"> 
</span><span class="cx"> void SharedWorkerProxy::workerContextClosed()
</span><span class="cx"> {
</span><del>-    m_closing = true;
</del><ins>+    if (isClosing())
+        return;
+    close();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SharedWorkerProxy::workerContextDestroyed()
</span></span></pre></div>
<a id="trunkWebCoreworkersWorkerContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/workers/WorkerContext.cpp (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/workers/WorkerContext.cpp        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/WebCore/workers/WorkerContext.cpp        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -119,9 +119,8 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_closing = true;
</span><del>-    // Notify parent that this context is closed.
</del><ins>+    // Notify parent that this context is closed. Parent is responsible for calling WorkerThread::stop().
</ins><span class="cx">     thread()-&gt;workerReportingProxy().workerContextClosed();
</span><del>-    m_thread-&gt;stop();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WorkerNavigator* WorkerContext::navigator() const
</span></span></pre></div>
<a id="trunkWebCoreworkersWorkerContexth"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/workers/WorkerContext.h (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/workers/WorkerContext.h        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/WebCore/workers/WorkerContext.h        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -117,9 +117,10 @@
</span><span class="cx">         using RefCounted&lt;WorkerContext&gt;::ref;
</span><span class="cx">         using RefCounted&lt;WorkerContext&gt;::deref;
</span><span class="cx"> 
</span><ins>+        bool isClosing() { return m_closing; }
+
</ins><span class="cx">     protected:
</span><span class="cx">         WorkerContext(const KURL&amp;, const String&amp;, WorkerThread*);
</span><del>-        bool isClosing() { return m_closing; }
</del><span class="cx"> 
</span><span class="cx">     private:
</span><span class="cx">         virtual void refScriptExecutionContext() { ref(); }
</span></span></pre></div>
<a id="trunkWebCoreworkersWorkerMessagingProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/workers/WorkerMessagingProxy.cpp (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/workers/WorkerMessagingProxy.cpp        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/WebCore/workers/WorkerMessagingProxy.cpp        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -120,13 +120,14 @@
</span><span class="cx">     virtual void performTask(ScriptExecutionContext* context)
</span><span class="cx">     {
</span><span class="cx">         Worker* workerObject = m_messagingProxy-&gt;workerObject();
</span><del>-        if (!workerObject || m_messagingProxy-&gt;askedToTerminate())
</del><ins>+        if (!workerObject)
</ins><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        bool errorHandled = false;
-        if (workerObject-&gt;onerror())
-            errorHandled = workerObject-&gt;dispatchScriptErrorEvent(m_errorMessage, m_sourceURL, m_lineNumber);
</del><ins>+        // We don't bother checking the askedToTerminate() flag here, because exceptions should *always* be reported even if the thread is terminated.
+        // This is intentionally different than the behavior in MessageWorkerTask, because terminated workers no longer deliver messages (section 4.6 of the WebWorker spec), but they do report exceptions.
</ins><span class="cx"> 
</span><ins>+        bool errorHandled = workerObject-&gt;dispatchScriptErrorEvent(m_errorMessage, m_sourceURL, m_lineNumber);
+
</ins><span class="cx">         if (!errorHandled)
</span><span class="cx">             context-&gt;reportException(m_errorMessage, m_lineNumber, m_sourceURL);
</span><span class="cx">     }
</span><span class="lines">@@ -158,6 +159,27 @@
</span><span class="cx">     WorkerMessagingProxy* m_messagingProxy;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+class WorkerTerminateTask : public ScriptExecutionContext::Task {
+public:
+    static PassRefPtr&lt;WorkerTerminateTask&gt; create(WorkerMessagingProxy* messagingProxy)
+    {
+        return adoptRef(new WorkerTerminateTask(messagingProxy));
+    }
+
+private:
+    WorkerTerminateTask(WorkerMessagingProxy* messagingProxy)
+        : m_messagingProxy(messagingProxy)
+    {
+    }
+
+    virtual void performTask(ScriptExecutionContext*)
+    {
+        m_messagingProxy-&gt;terminateWorkerContext();
+    }
+
+    WorkerMessagingProxy* m_messagingProxy;
+};
+
</ins><span class="cx"> class WorkerThreadActivityReportTask : public ScriptExecutionContext::Task {
</span><span class="cx"> public:
</span><span class="cx">     static PassRefPtr&lt;WorkerThreadActivityReportTask&gt; create(WorkerMessagingProxy* messagingProxy, bool confirmingMessage, bool hasPendingActivity)
</span><span class="lines">@@ -301,6 +323,12 @@
</span><span class="cx">     // Will execute workerContextDestroyedInternal() on context's thread.
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WorkerMessagingProxy::workerContextClosed()
+{
+    // Executes terminateWorkerContext() on parent context's thread.
+    m_scriptExecutionContext-&gt;postTask(WorkerTerminateTask::create(this));
+}
+
</ins><span class="cx"> void WorkerMessagingProxy::workerContextDestroyedInternal()
</span><span class="cx"> {
</span><span class="cx">     // WorkerContextDestroyedTask is always the last to be performed, so the proxy is not needed for communication
</span></span></pre></div>
<a id="trunkWebCoreworkersWorkerMessagingProxyh"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/workers/WorkerMessagingProxy.h (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/workers/WorkerMessagingProxy.h        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/WebCore/workers/WorkerMessagingProxy.h        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx">         virtual void postConsoleMessageToWorkerObject(MessageDestination, MessageSource, MessageType, MessageLevel, const String&amp; message, int lineNumber, const String&amp; sourceURL);
</span><span class="cx">         virtual void confirmMessageFromWorkerObject(bool hasPendingActivity);
</span><span class="cx">         virtual void reportPendingActivity(bool hasPendingActivity);
</span><ins>+        virtual void workerContextClosed();
</ins><span class="cx">         virtual void workerContextDestroyed();
</span><span class="cx"> 
</span><span class="cx">         // Implementation of WorkerLoaderProxy.
</span></span></pre></div>
<a id="trunkWebCoreworkersWorkerRunLoopcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/workers/WorkerRunLoop.cpp (47913 => 47914)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/workers/WorkerRunLoop.cpp        2009-08-31 23:36:39 UTC (rev 47913)
+++ trunk/WebCore/workers/WorkerRunLoop.cpp        2009-08-31 23:40:08 UTC (rev 47914)
</span><span class="lines">@@ -173,6 +173,10 @@
</span><span class="cx">     RefPtr&lt;Task&gt; task;
</span><span class="cx">     MessageQueueWaitResult result = m_messageQueue.waitForMessageFilteredWithTimeout(task, predicate, absoluteTime);
</span><span class="cx"> 
</span><ins>+    // If the context is closing, don't dispatch any further tasks (per section 4.1.1 of the Web Workers spec).
+    if (context-&gt;isClosing())
+        return result;
+
</ins><span class="cx">     switch (result) {
</span><span class="cx">     case MessageQueueTerminated:
</span><span class="cx">         break;
</span></span></pre>
</div>
</div>

</body>
</html>