<!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>[212609] 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/212609">212609</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2017-02-18 15:58:57 -0800 (Sat, 18 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Recursive MessagePort.postMessage() calls causes tab to become unresponsive
https://bugs.webkit.org/show_bug.cgi?id=168548
&lt;rdar://problem/29808005&gt;

Reviewed by Darin Adler.

Source/WebCore:

MessagePort::dispatchMessages() was getting messages one by one of the
channel's MessageQueue and firing the MessageEvent for each of them.
The issue is that we can get stuck in an infinite loop if the
MessageEvent handler posts a message on the same post.

To address the issue, we now takes all messages from the queue before
iterating over them to fire the event. This way, if new messages are
added to the queue in one of the MessageEvent handlers, they will not
be processed until the next event loop iteration, as is expected.

Test: fast/events/message-port-postMessage-recursive.html

* dom/MessagePort.cpp:
(WebCore::MessagePort::dispatchMessages):
* dom/MessagePortChannel.h:
(WebCore::MessagePortChannel::EventData::EventData):
* dom/default/PlatformMessagePortChannel.cpp:
(WebCore::MessagePortChannel::postMessageToRemote):
* dom/default/PlatformMessagePortChannel.h:
(WebCore::PlatformMessagePortChannel::MessagePortQueue::takeMessage):
(WebCore::PlatformMessagePortChannel::MessagePortQueue::takeAllMessages):
(WebCore::PlatformMessagePortChannel::MessagePortQueue::appendAndCheckEmpty):

Source/WTF:

Add API to retrieve all messages in the queue at once.

* wtf/MessageQueue.h:

LayoutTests:

Add layout test coverage. The test used to time out, it now passes.
The test also passes on Firefox and Chrome.

* fast/events/message-port-postMessage-recursive-expected.txt: Added.
* fast/events/message-port-postMessage-recursive.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfMessageQueueh">trunk/Source/WTF/wtf/MessageQueue.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomMessagePortcpp">trunk/Source/WebCore/dom/MessagePort.cpp</a></li>
<li><a href="#trunkSourceWebCoredomMessagePortChannelh">trunk/Source/WebCore/dom/MessagePortChannel.h</a></li>
<li><a href="#trunkSourceWebCoredomdefaultPlatformMessagePortChannelcpp">trunk/Source/WebCore/dom/default/PlatformMessagePortChannel.cpp</a></li>
<li><a href="#trunkSourceWebCoredomdefaultPlatformMessagePortChannelh">trunk/Source/WebCore/dom/default/PlatformMessagePortChannel.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasteventsmessageportpostMessagerecursiveexpectedtxt">trunk/LayoutTests/fast/events/message-port-postMessage-recursive-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasteventsmessageportpostMessagerecursivehtml">trunk/LayoutTests/fast/events/message-port-postMessage-recursive.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (212608 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-02-18 23:08:17 UTC (rev 212608)
+++ trunk/LayoutTests/ChangeLog        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2017-02-18  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Recursive MessagePort.postMessage() calls causes tab to become unresponsive
+        https://bugs.webkit.org/show_bug.cgi?id=168548
+        &lt;rdar://problem/29808005&gt;
+
+        Reviewed by Darin Adler.
+
+        Add layout test coverage. The test used to time out, it now passes.
+        The test also passes on Firefox and Chrome.
+
+        * fast/events/message-port-postMessage-recursive-expected.txt: Added.
+        * fast/events/message-port-postMessage-recursive.html: Added.
+
</ins><span class="cx"> 2017-02-18  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed GTK+ gardening. Update expectations of a few more tests that are failing.
</span></span></pre></div>
<a id="trunkLayoutTestsfasteventsmessageportpostMessagerecursiveexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/events/message-port-postMessage-recursive-expected.txt (0 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/events/message-port-postMessage-recursive-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/events/message-port-postMessage-recursive-expected.txt        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+Tests that recursive calls to MessagePort.postMessage() do not preempt timers.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS Timer has fired.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfasteventsmessageportpostMessagerecursivehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/events/message-port-postMessage-recursive.html (0 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/events/message-port-postMessage-recursive.html                                (rev 0)
+++ trunk/LayoutTests/fast/events/message-port-postMessage-recursive.html        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -0,0 +1,50 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+description(&quot;Tests that recursive calls to MessagePort.postMessage() do not preempt timers.&quot;);
+jsTestIsAsync = true;
+
+function simulateSetImmediate()
+{
+    var channel = new MessageChannel();
+    // Use a fifo linked list to call callbacks in the right order.
+    var head = {};
+    var tail = head;
+    channel['port1'].onmessage = function() {
+        if (head.next != null) {
+            head = head.next;
+            var cb = head.cb;
+            head.cb = null;
+            cb();
+        }
+    };
+    return function(cb) {
+        tail.next = {cb: cb};
+        tail = tail.next;
+        channel['port2'].postMessage(0);
+    };
+}
+
+window.setImmediate = simulateSetImmediate();
+
+var shouldExit = false;
+
+function iterate() {
+    if (shouldExit) {
+        testPassed(&quot;Timer has fired.&quot;);
+        finishJSTest();
+        return;
+    }
+    setImmediate(iterate);
+}
+
+setImmediate(iterate);
+setTimeout(function() {
+    shouldExit = true;
+}, 10);
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (212608 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2017-02-18 23:08:17 UTC (rev 212608)
+++ trunk/Source/WTF/ChangeLog        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2017-02-18  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Recursive MessagePort.postMessage() calls causes tab to become unresponsive
+        https://bugs.webkit.org/show_bug.cgi?id=168548
+        &lt;rdar://problem/29808005&gt;
+
+        Reviewed by Darin Adler.
+
+        Add API to retrieve all messages in the queue at once.
+
+        * wtf/MessageQueue.h:
+
</ins><span class="cx"> 2017-02-16  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove EFL-specific files in Source.
</span></span></pre></div>
<a id="trunkSourceWTFwtfMessageQueueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/MessageQueue.h (212608 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/MessageQueue.h        2017-02-18 23:08:17 UTC (rev 212608)
+++ trunk/Source/WTF/wtf/MessageQueue.h        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -64,6 +64,7 @@
</span><span class="cx"> 
</span><span class="cx">         std::unique_ptr&lt;DataType&gt; waitForMessage();
</span><span class="cx">         std::unique_ptr&lt;DataType&gt; tryGetMessage();
</span><ins>+        Deque&lt;std::unique_ptr&lt;DataType&gt;&gt; takeAllMessages();
</ins><span class="cx">         std::unique_ptr&lt;DataType&gt; tryGetMessageIgnoringKilled();
</span><span class="cx">         template&lt;typename Predicate&gt;
</span><span class="cx">         std::unique_ptr&lt;DataType&gt; waitForMessageFilteredWithTimeout(MessageQueueWaitResult&amp;, Predicate&amp;&amp;, WallTime absoluteTime);
</span><span class="lines">@@ -185,6 +186,15 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     template&lt;typename DataType&gt;
</span><ins>+    inline auto MessageQueue&lt;DataType&gt;::takeAllMessages() -&gt; Deque&lt;std::unique_ptr&lt;DataType&gt;&gt;
+    {
+        LockHolder lock(m_mutex);
+        if (m_killed)
+            return { };
+        return WTFMove(m_queue);
+    }
+
+    template&lt;typename DataType&gt;
</ins><span class="cx">     inline auto MessageQueue&lt;DataType&gt;::tryGetMessageIgnoringKilled() -&gt; std::unique_ptr&lt;DataType&gt;
</span><span class="cx">     {
</span><span class="cx">         LockHolder lock(m_mutex);
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (212608 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-02-18 23:08:17 UTC (rev 212608)
+++ trunk/Source/WebCore/ChangeLog        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2017-02-18  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Recursive MessagePort.postMessage() calls causes tab to become unresponsive
+        https://bugs.webkit.org/show_bug.cgi?id=168548
+        &lt;rdar://problem/29808005&gt;
+
+        Reviewed by Darin Adler.
+
+        MessagePort::dispatchMessages() was getting messages one by one of the
+        channel's MessageQueue and firing the MessageEvent for each of them.
+        The issue is that we can get stuck in an infinite loop if the
+        MessageEvent handler posts a message on the same post.
+
+        To address the issue, we now takes all messages from the queue before
+        iterating over them to fire the event. This way, if new messages are
+        added to the queue in one of the MessageEvent handlers, they will not
+        be processed until the next event loop iteration, as is expected.
+
+        Test: fast/events/message-port-postMessage-recursive.html
+
+        * dom/MessagePort.cpp:
+        (WebCore::MessagePort::dispatchMessages):
+        * dom/MessagePortChannel.h:
+        (WebCore::MessagePortChannel::EventData::EventData):
+        * dom/default/PlatformMessagePortChannel.cpp:
+        (WebCore::MessagePortChannel::postMessageToRemote):
+        * dom/default/PlatformMessagePortChannel.h:
+        (WebCore::PlatformMessagePortChannel::MessagePortQueue::takeMessage):
+        (WebCore::PlatformMessagePortChannel::MessagePortQueue::takeAllMessages):
+        (WebCore::PlatformMessagePortChannel::MessagePortQueue::appendAndCheckEmpty):
+
</ins><span class="cx"> 2017-02-18  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove COORDINATED_GRAPHICS_MULTIPROCESS
</span></span></pre></div>
<a id="trunkSourceWebCoredomMessagePortcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/MessagePort.cpp (212608 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/MessagePort.cpp        2017-02-18 23:08:17 UTC (rev 212608)
+++ trunk/Source/WebCore/dom/MessagePort.cpp        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -146,16 +146,19 @@
</span><span class="cx">     // The HTML5 spec specifies that any messages sent to a document that is not fully active should be dropped, so this behavior is OK.
</span><span class="cx">     ASSERT(started());
</span><span class="cx"> 
</span><del>-    RefPtr&lt;SerializedScriptValue&gt; message;
-    std::unique_ptr&lt;MessagePortChannelArray&gt; channels;
-    while (m_entangledChannel &amp;&amp; m_entangledChannel-&gt;tryGetMessageFromRemote(message, channels)) {
</del><ins>+    if (!m_entangledChannel)
+        return;
</ins><span class="cx"> 
</span><ins>+    bool contextIsWorker = is&lt;WorkerGlobalScope&gt;(*m_scriptExecutionContext);
+
+    auto pendingMessages = m_entangledChannel-&gt;takeAllMessagesFromRemote();
+    for (auto&amp; message : pendingMessages) {
</ins><span class="cx">         // close() in Worker onmessage handler should prevent next message from dispatching.
</span><del>-        if (is&lt;WorkerGlobalScope&gt;(*m_scriptExecutionContext) &amp;&amp; downcast&lt;WorkerGlobalScope&gt;(*m_scriptExecutionContext).isClosing())
</del><ins>+        if (contextIsWorker &amp;&amp; downcast&lt;WorkerGlobalScope&gt;(*m_scriptExecutionContext).isClosing())
</ins><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        auto ports = MessagePort::entanglePorts(*m_scriptExecutionContext, WTFMove(channels));
-        dispatchEvent(MessageEvent::create(WTFMove(ports), WTFMove(message)));
</del><ins>+        auto ports = MessagePort::entanglePorts(*m_scriptExecutionContext, WTFMove(message-&gt;channels));
+        dispatchEvent(MessageEvent::create(WTFMove(ports), WTFMove(message-&gt;message)));
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomMessagePortChannelh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/MessagePortChannel.h (212608 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/MessagePortChannel.h        2017-02-18 23:08:17 UTC (rev 212608)
+++ trunk/Source/WebCore/dom/MessagePortChannel.h        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;SerializedScriptValue.h&quot;
</span><span class="cx"> #include &lt;memory&gt;
</span><ins>+#include &lt;wtf/Deque.h&gt;
</ins><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="lines">@@ -51,6 +52,16 @@
</span><span class="cx">     class MessagePortChannel {
</span><span class="cx">         WTF_MAKE_NONCOPYABLE(MessagePortChannel); WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx">     public:
</span><ins>+        struct EventData {
+            EventData(Ref&lt;SerializedScriptValue&gt;&amp;&amp; message, std::unique_ptr&lt;MessagePortChannelArray&gt;&amp;&amp; channels)
+                : message(WTFMove(message))
+                , channels(WTFMove(channels))
+            { }
+
+            Ref&lt;SerializedScriptValue&gt; message;
+            std::unique_ptr&lt;MessagePortChannelArray&gt; channels;
+        };
+
</ins><span class="cx">         explicit MessagePortChannel(RefPtr&lt;PlatformMessagePortChannel&gt;&amp;&amp;);
</span><span class="cx">         static void createChannel(MessagePort*, MessagePort*);
</span><span class="cx"> 
</span><span class="lines">@@ -71,11 +82,13 @@
</span><span class="cx">         bool hasPendingActivity();
</span><span class="cx"> 
</span><span class="cx">         // Sends a message and optional cloned port to the remote port.
</span><del>-        void postMessageToRemote(RefPtr&lt;SerializedScriptValue&gt;&amp;&amp;, std::unique_ptr&lt;MessagePortChannelArray&gt;);
</del><ins>+        void postMessageToRemote(Ref&lt;SerializedScriptValue&gt;&amp;&amp;, std::unique_ptr&lt;MessagePortChannelArray&gt;);
</ins><span class="cx"> 
</span><span class="cx">         // Extracts a message from the message queue for this port.
</span><del>-        bool tryGetMessageFromRemote(RefPtr&lt;SerializedScriptValue&gt;&amp;, std::unique_ptr&lt;MessagePortChannelArray&gt;&amp;);
</del><ins>+        std::unique_ptr&lt;EventData&gt; takeMessageFromRemote();
</ins><span class="cx"> 
</span><ins>+        Deque&lt;std::unique_ptr&lt;EventData&gt;&gt; takeAllMessagesFromRemote();
+
</ins><span class="cx">         // Returns the entangled port if run by the same thread (see MessagePort::locallyEntangledPort() for more details).
</span><span class="cx">         MessagePort* locallyEntangledPort(const ScriptExecutionContext*);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomdefaultPlatformMessagePortChannelcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/default/PlatformMessagePortChannel.cpp (212608 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/default/PlatformMessagePortChannel.cpp        2017-02-18 23:08:17 UTC (rev 212608)
+++ trunk/Source/WebCore/dom/default/PlatformMessagePortChannel.cpp        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -37,12 +37,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-PlatformMessagePortChannel::EventData::EventData(RefPtr&lt;SerializedScriptValue&gt;&amp;&amp; message, std::unique_ptr&lt;MessagePortChannelArray&gt; channels)
-    : m_message(WTFMove(message))
-    , m_channels(WTFMove(channels))
-{
-}
-
</del><span class="cx"> void MessagePortChannel::createChannel(MessagePort* port1, MessagePort* port2)
</span><span class="cx"> {
</span><span class="cx">     Ref&lt;PlatformMessagePortChannel::MessagePortQueue&gt; queue1 = PlatformMessagePortChannel::MessagePortQueue::create();
</span><span class="lines">@@ -86,27 +80,26 @@
</span><span class="cx">         remote-&gt;setRemotePort(nullptr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MessagePortChannel::postMessageToRemote(RefPtr&lt;SerializedScriptValue&gt;&amp;&amp; message, std::unique_ptr&lt;MessagePortChannelArray&gt; channels)
</del><ins>+void MessagePortChannel::postMessageToRemote(Ref&lt;SerializedScriptValue&gt;&amp;&amp; message, std::unique_ptr&lt;MessagePortChannelArray&gt; channels)
</ins><span class="cx"> {
</span><span class="cx">     LockHolder lock(m_channel-&gt;m_mutex);
</span><span class="cx">     if (!m_channel-&gt;m_outgoingQueue)
</span><span class="cx">         return;
</span><del>-    bool wasEmpty = m_channel-&gt;m_outgoingQueue-&gt;appendAndCheckEmpty(std::make_unique&lt;PlatformMessagePortChannel::EventData&gt;(WTFMove(message), WTFMove(channels)));
</del><ins>+    bool wasEmpty = m_channel-&gt;m_outgoingQueue-&gt;appendAndCheckEmpty(std::make_unique&lt;EventData&gt;(WTFMove(message), WTFMove(channels)));
</ins><span class="cx">     if (wasEmpty &amp;&amp; m_channel-&gt;m_remotePort)
</span><span class="cx">         m_channel-&gt;m_remotePort-&gt;messageAvailable();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool MessagePortChannel::tryGetMessageFromRemote(RefPtr&lt;SerializedScriptValue&gt;&amp; message, std::unique_ptr&lt;MessagePortChannelArray&gt;&amp; channels)
</del><ins>+auto MessagePortChannel::takeMessageFromRemote() -&gt; std::unique_ptr&lt;EventData&gt;
</ins><span class="cx"> {
</span><span class="cx">     LockHolder lock(m_channel-&gt;m_mutex);
</span><del>-    auto result = m_channel-&gt;m_incomingQueue-&gt;tryGetMessage();
-    if (!result)
-        return false;
</del><ins>+    return m_channel-&gt;m_incomingQueue-&gt;takeMessage();
+}
</ins><span class="cx"> 
</span><del>-    message = result-&gt;message();
-    channels = result-&gt;channels();
-
-    return true;
</del><ins>+auto MessagePortChannel::takeAllMessagesFromRemote() -&gt; Deque&lt;std::unique_ptr&lt;EventData&gt;&gt;
+{
+    LockHolder lock(m_channel-&gt;m_mutex);
+    return m_channel-&gt;m_incomingQueue-&gt;takeAllMessages();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MessagePortChannel::close()
</span></span></pre></div>
<a id="trunkSourceWebCoredomdefaultPlatformMessagePortChannelh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/default/PlatformMessagePortChannel.h (212608 => 212609)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/default/PlatformMessagePortChannel.h        2017-02-18 23:08:17 UTC (rev 212608)
+++ trunk/Source/WebCore/dom/default/PlatformMessagePortChannel.h        2017-02-18 23:58:57 UTC (rev 212609)
</span><span class="lines">@@ -43,31 +43,23 @@
</span><span class="cx">     // The goal of this implementation is to eliminate contention except when cloning or closing the port, so each side of the channel has its own separate mutex.
</span><span class="cx">     class PlatformMessagePortChannel : public ThreadSafeRefCounted&lt;PlatformMessagePortChannel&gt; {
</span><span class="cx">     public:
</span><del>-        class EventData {
-            WTF_MAKE_NONCOPYABLE(EventData); WTF_MAKE_FAST_ALLOCATED;
-        public:
-            EventData(RefPtr&lt;SerializedScriptValue&gt;&amp;&amp; message, std::unique_ptr&lt;MessagePortChannelArray&gt;);
-
-            RefPtr&lt;SerializedScriptValue&gt; message() { return m_message; }
-            std::unique_ptr&lt;MessagePortChannelArray&gt; channels() { return WTFMove(m_channels); }
-
-        private:
-            RefPtr&lt;SerializedScriptValue&gt; m_message;
-            std::unique_ptr&lt;MessagePortChannelArray&gt; m_channels;
-        };
-
</del><span class="cx">         // Wrapper for MessageQueue that allows us to do thread safe sharing by two proxies.
</span><span class="cx">         class MessagePortQueue : public ThreadSafeRefCounted&lt;MessagePortQueue&gt; {
</span><span class="cx">         public:
</span><span class="cx">             static Ref&lt;MessagePortQueue&gt; create() { return adoptRef(*new MessagePortQueue()); }
</span><span class="cx"> 
</span><del>-            std::unique_ptr&lt;PlatformMessagePortChannel::EventData&gt; tryGetMessage()
</del><ins>+            std::unique_ptr&lt;MessagePortChannel::EventData&gt; takeMessage()
</ins><span class="cx">             {
</span><span class="cx">                 return m_queue.tryGetMessage();
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            bool appendAndCheckEmpty(std::unique_ptr&lt;PlatformMessagePortChannel::EventData&gt; message)
</del><ins>+            Deque&lt;std::unique_ptr&lt;MessagePortChannel::EventData&gt;&gt; takeAllMessages()
</ins><span class="cx">             {
</span><ins>+                return m_queue.takeAllMessages();
+            }
+
+            bool appendAndCheckEmpty(std::unique_ptr&lt;MessagePortChannel::EventData&gt;&amp;&amp; message)
+            {
</ins><span class="cx">                 return m_queue.appendAndCheckEmpty(WTFMove(message));
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="lines">@@ -79,7 +71,7 @@
</span><span class="cx">         private:
</span><span class="cx">             MessagePortQueue() { }
</span><span class="cx"> 
</span><del>-            MessageQueue&lt;PlatformMessagePortChannel::EventData&gt; m_queue;
</del><ins>+            MessageQueue&lt;MessagePortChannel::EventData&gt; m_queue;
</ins><span class="cx">         };
</span><span class="cx"> 
</span><span class="cx">         ~PlatformMessagePortChannel();
</span></span></pre>
</div>
</div>

</body>
</html>