<!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>[197804] 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/197804">197804</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2016-03-08 14:22:40 -0800 (Tue, 08 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Font Loading] Crash when a single load request causes multiple fonts to fail loading
https://bugs.webkit.org/show_bug.cgi?id=155009

Reviewed by Simon Fraser.

Source/WebCore:

In JavaScript, the first promise fulfillment/failure wins. However, in C++, any
subsequent fulfillments/failures cause a crash.

Test: fast/text/font-face-set-document-multiple-failure.html

* css/CSSFontFace.cpp:
(WebCore::iterateClients): Notifying a client may cause some other client
to be destroyed, thereby modifying the clients set. This function allows
for notifying clients in a resilient manner.
(WebCore::CSSFontFace::setStyle): Update to use iterateClients().
(WebCore::CSSFontFace::setWeight): Ditto.
(WebCore::CSSFontFace::setUnicodeRange): Ditto.
(WebCore::CSSFontFace::setVariantLigatures): Ditto.
(WebCore::CSSFontFace::setVariantPosition): Ditto.
(WebCore::CSSFontFace::setVariantCaps): Ditto.
(WebCore::CSSFontFace::setVariantNumeric): Ditto.
(WebCore::CSSFontFace::setVariantAlternates): Ditto.
(WebCore::CSSFontFace::setVariantEastAsian): Ditto.
(WebCore::CSSFontFace::setFeatureSettings): Ditto.
(WebCore::CSSFontFace::setStatus): Ditto.
(WebCore::CSSFontFace::notifyClientsOfFontPropertyChange): Deleted.
* css/CSSFontFace.h: Adding a way for clients to make sure they don't register
or deregister another client.
* css/CSSFontFaceSet.cpp:
(WebCore::CSSFontFaceSet::guardAgainstClientRegistrationChanges): Simple
ref()/deref() pair.
(WebCore::CSSFontFaceSet::stopGuardingAgainstClientRegistrationChanges):
* css/CSSFontFaceSet.h:
* css/FontFace.cpp: Ditto.
(WebCore::FontFace::guardAgainstClientRegistrationChanges):
(WebCore::FontFace::stopGuardingAgainstClientRegistrationChanges):
* css/FontFace.h:
* css/FontFaceSet.cpp:
(WebCore::FontFaceSet::faceFinished): Make sure that we only fulfil or reject
a promise once.
* css/FontFaceSet.h:
* dom/Document.cpp:
(WebCore::Document::fonts): The CSSFontFaces inside the CSSFontSelector get
created during style recalc. We may be in a state where there is a style
recalc pending. In order to make sure the Javascript API sees the current
state of the world, force a style recalc here (but only if one is pending).

LayoutTests:

* fast/text/font-face-set-document-multiple-failure-expected.txt: Added.
* fast/text/font-face-set-document-multiple-failure.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontFacecpp">trunk/Source/WebCore/css/CSSFontFace.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontFaceh">trunk/Source/WebCore/css/CSSFontFace.h</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontFaceSetcpp">trunk/Source/WebCore/css/CSSFontFaceSet.cpp</a></li>
<li><a href="#trunkSourceWebCorecssCSSFontFaceSeth">trunk/Source/WebCore/css/CSSFontFaceSet.h</a></li>
<li><a href="#trunkSourceWebCorecssCSSSegmentedFontFaceh">trunk/Source/WebCore/css/CSSSegmentedFontFace.h</a></li>
<li><a href="#trunkSourceWebCorecssFontFaceh">trunk/Source/WebCore/css/FontFace.h</a></li>
<li><a href="#trunkSourceWebCorecssFontFaceSetcpp">trunk/Source/WebCore/css/FontFaceSet.cpp</a></li>
<li><a href="#trunkSourceWebCorecssFontFaceSeth">trunk/Source/WebCore/css/FontFaceSet.h</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttextfontfacesetdocumentmultiplefailureexpectedtxt">trunk/LayoutTests/fast/text/font-face-set-document-multiple-failure-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttextfontfacesetdocumentmultiplefailurehtml">trunk/LayoutTests/fast/text/font-face-set-document-multiple-failure.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/LayoutTests/ChangeLog        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-03-08  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        [Font Loading] Crash when a single load request causes multiple fonts to fail loading
+        https://bugs.webkit.org/show_bug.cgi?id=155009
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/font-face-set-document-multiple-failure-expected.txt: Added.
+        * fast/text/font-face-set-document-multiple-failure.html: Added.
+
</ins><span class="cx"> 2016-03-08  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Skip fast/events/prevent-default-prevents-interaction-with-scrollbars.html on ios-simulator
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextfontfacesetdocumentmultiplefailureexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/font-face-set-document-multiple-failure-expected.txt (0 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/font-face-set-document-multiple-failure-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/text/font-face-set-document-multiple-failure-expected.txt        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+PASS globalX.code is globalX.NETWORK_ERR
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextfontfacesetdocumentmultiplefailurehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/font-face-set-document-multiple-failure.html (0 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/font-face-set-document-multiple-failure.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/font-face-set-document-multiple-failure.html        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -0,0 +1,32 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+@font-face {
+        font-family: &quot;WebFont&quot;;
+        src: url(&quot;garbage&quot;);
+}
+@font-face {
+        font-family: &quot;WebFont&quot;;
+        src: url(&quot;garbage&quot;);
+        font-variant: small-caps;
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+self.jsTestIsAsync = true;
+var globalX;
+document.fonts.load(&quot;16px WebFont&quot;).then(function() {
+    testFailed(&quot;Bogus URLs should not load&quot;);
+    finishJSTest();
+}, function(x) {
+        globalX = x;
+    shouldBe(&quot;globalX.code&quot;, &quot;globalX.NETWORK_ERR&quot;);
+    finishJSTest();
+})
+&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 class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/ChangeLog        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -1,3 +1,52 @@
</span><ins>+2016-03-08  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        [Font Loading] Crash when a single load request causes multiple fonts to fail loading
+        https://bugs.webkit.org/show_bug.cgi?id=155009
+
+        Reviewed by Simon Fraser.
+
+        In JavaScript, the first promise fulfillment/failure wins. However, in C++, any
+        subsequent fulfillments/failures cause a crash.
+
+        Test: fast/text/font-face-set-document-multiple-failure.html
+
+        * css/CSSFontFace.cpp:
+        (WebCore::iterateClients): Notifying a client may cause some other client
+        to be destroyed, thereby modifying the clients set. This function allows
+        for notifying clients in a resilient manner.
+        (WebCore::CSSFontFace::setStyle): Update to use iterateClients().
+        (WebCore::CSSFontFace::setWeight): Ditto.
+        (WebCore::CSSFontFace::setUnicodeRange): Ditto.
+        (WebCore::CSSFontFace::setVariantLigatures): Ditto.
+        (WebCore::CSSFontFace::setVariantPosition): Ditto.
+        (WebCore::CSSFontFace::setVariantCaps): Ditto.
+        (WebCore::CSSFontFace::setVariantNumeric): Ditto.
+        (WebCore::CSSFontFace::setVariantAlternates): Ditto.
+        (WebCore::CSSFontFace::setVariantEastAsian): Ditto.
+        (WebCore::CSSFontFace::setFeatureSettings): Ditto.
+        (WebCore::CSSFontFace::setStatus): Ditto.
+        (WebCore::CSSFontFace::notifyClientsOfFontPropertyChange): Deleted.
+        * css/CSSFontFace.h: Adding a way for clients to make sure they don't register
+        or deregister another client.
+        * css/CSSFontFaceSet.cpp:
+        (WebCore::CSSFontFaceSet::guardAgainstClientRegistrationChanges): Simple
+        ref()/deref() pair.
+        (WebCore::CSSFontFaceSet::stopGuardingAgainstClientRegistrationChanges):
+        * css/CSSFontFaceSet.h:
+        * css/FontFace.cpp: Ditto.
+        (WebCore::FontFace::guardAgainstClientRegistrationChanges):
+        (WebCore::FontFace::stopGuardingAgainstClientRegistrationChanges):
+        * css/FontFace.h:
+        * css/FontFaceSet.cpp:
+        (WebCore::FontFaceSet::faceFinished): Make sure that we only fulfil or reject
+        a promise once.
+        * css/FontFaceSet.h:
+        * dom/Document.cpp:
+        (WebCore::Document::fonts): The CSSFontFaces inside the CSSFontSelector get
+        created during style recalc. We may be in a state where there is a style
+        recalc pending. In order to make sure the Javascript API sees the current
+        state of the world, force a style recalc here (but only if one is pending).
+
</ins><span class="cx"> 2016-03-08  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r197793 and r197799.
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontFacecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontFace.cpp (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontFace.cpp        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/css/CSSFontFace.cpp        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -48,6 +48,17 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+template&lt;typename T&gt; void iterateClients(HashSet&lt;CSSFontFace::Client*&gt;&amp; clients, T callback)
+{
+    Vector&lt;Ref&lt;CSSFontFace::Client&gt;&gt; clientsCopy;
+    clientsCopy.reserveInitialCapacity(clients.size());
+    for (auto* client : clients)
+        clientsCopy.uncheckedAppend(*client);
+
+    for (auto* client : clients)
+        callback(*client);
+}
+
</ins><span class="cx"> void CSSFontFace::appendSources(CSSFontFace&amp; fontFace, CSSValueList&amp; srcList, Document* document, bool isInitiatingElementInUserAgentShadowTree)
</span><span class="cx"> {
</span><span class="cx">     for (auto&amp; src : srcList) {
</span><span class="lines">@@ -89,15 +100,6 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CSSFontFace::notifyClientsOfFontPropertyChange()
-{
-    auto clientsCopy = m_clients;
-    for (auto* client : clientsCopy) {
-        if (m_clients.contains(client))
-            client-&gt;fontPropertyChanged(*this);
-    }
-}
-
</del><span class="cx"> bool CSSFontFace::setFamilies(CSSValue&amp; family)
</span><span class="cx"> {
</span><span class="cx">     if (!is&lt;CSSValueList&gt;(family))
</span><span class="lines">@@ -110,11 +112,9 @@
</span><span class="cx">     RefPtr&lt;CSSValueList&gt; oldFamilies = m_families;
</span><span class="cx">     m_families = &amp;familyList;
</span><span class="cx"> 
</span><del>-    auto clientsCopy = m_clients;
-    for (auto* client : clientsCopy) {
-        if (m_clients.contains(client))
-            client-&gt;fontPropertyChanged(*this, oldFamilies.get());
-    }
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this, oldFamilies.get());
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -142,7 +142,9 @@
</span><span class="cx">     if (auto mask = calculateStyleMask(style)) {
</span><span class="cx">         m_traitsMask = static_cast&lt;FontTraitsMask&gt;((static_cast&lt;unsigned&gt;(m_traitsMask) &amp; (~FontStyleMask)) | mask.value());
</span><span class="cx"> 
</span><del>-        notifyClientsOfFontPropertyChange();
</del><ins>+        iterateClients(m_clients, [&amp;](Client&amp; client) {
+            client.fontPropertyChanged(*this);
+        });
</ins><span class="cx"> 
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="lines">@@ -189,7 +191,9 @@
</span><span class="cx">     if (auto mask = calculateWeightMask(weight)) {
</span><span class="cx">         m_traitsMask = static_cast&lt;FontTraitsMask&gt;((static_cast&lt;unsigned&gt;(m_traitsMask) &amp; (~FontWeightMask)) | mask.value());
</span><span class="cx"> 
</span><del>-        notifyClientsOfFontPropertyChange();
</del><ins>+        iterateClients(m_clients, [&amp;](Client&amp; client) {
+            client.fontPropertyChanged(*this);
+        });
</ins><span class="cx"> 
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="lines">@@ -209,7 +213,9 @@
</span><span class="cx">         m_ranges.append(UnicodeRange(range.from(), range.to()));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    notifyClientsOfFontPropertyChange();
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this);
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -222,7 +228,9 @@
</span><span class="cx">     m_variantSettings.historicalLigatures = ligatures.historicalLigatures;
</span><span class="cx">     m_variantSettings.contextualAlternates = ligatures.contextualAlternates;
</span><span class="cx"> 
</span><del>-    notifyClientsOfFontPropertyChange();
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this);
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -233,7 +241,9 @@
</span><span class="cx">         return false;
</span><span class="cx">     m_variantSettings.position = downcast&lt;CSSPrimitiveValue&gt;(variantPosition);
</span><span class="cx"> 
</span><del>-    notifyClientsOfFontPropertyChange();
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this);
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -244,7 +254,9 @@
</span><span class="cx">         return false;
</span><span class="cx">     m_variantSettings.caps = downcast&lt;CSSPrimitiveValue&gt;(variantCaps);
</span><span class="cx"> 
</span><del>-    notifyClientsOfFontPropertyChange();
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this);
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -258,7 +270,9 @@
</span><span class="cx">     m_variantSettings.numericOrdinal = numeric.ordinal;
</span><span class="cx">     m_variantSettings.numericSlashedZero = numeric.slashedZero;
</span><span class="cx"> 
</span><del>-    notifyClientsOfFontPropertyChange();
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this);
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -269,7 +283,9 @@
</span><span class="cx">         return false;
</span><span class="cx">     m_variantSettings.alternates = downcast&lt;CSSPrimitiveValue&gt;(variantAlternates);
</span><span class="cx"> 
</span><del>-    notifyClientsOfFontPropertyChange();
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this);
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -281,7 +297,9 @@
</span><span class="cx">     m_variantSettings.eastAsianWidth = eastAsian.width;
</span><span class="cx">     m_variantSettings.eastAsianRuby = eastAsian.ruby;
</span><span class="cx"> 
</span><del>-    notifyClientsOfFontPropertyChange();
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this);
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -298,7 +316,9 @@
</span><span class="cx">         m_featureSettings.insert(FontFeature(feature.tag(), feature.value()));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    notifyClientsOfFontPropertyChange();
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontPropertyChanged(*this);
+    });
</ins><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -380,8 +400,9 @@
</span><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    for (auto* client : m_clients)
-        client-&gt;fontStateChanged(*this, m_status, newStatus);
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontStateChanged(*this, m_status, newStatus);
+    });
</ins><span class="cx"> 
</span><span class="cx">     m_status = newStatus;
</span><span class="cx"> }
</span><span class="lines">@@ -397,8 +418,9 @@
</span><span class="cx">     ASSERT(m_fontSelector);
</span><span class="cx">     m_fontSelector-&gt;fontLoaded();
</span><span class="cx"> 
</span><del>-    for (auto* client : m_clients)
-        client-&gt;fontLoaded(*this);
</del><ins>+    iterateClients(m_clients, [&amp;](Client&amp; client) {
+        client.fontLoaded(*this);
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> size_t CSSFontFace::pump()
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontFaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontFace.h (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontFace.h        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/css/CSSFontFace.h        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -108,9 +108,11 @@
</span><span class="cx">     class Client {
</span><span class="cx">     public:
</span><span class="cx">         virtual ~Client() { }
</span><del>-        virtual void fontLoaded(CSSFontFace&amp;) { };
-        virtual void fontStateChanged(CSSFontFace&amp;, Status oldState, Status newState) { UNUSED_PARAM(oldState); UNUSED_PARAM(newState); };
-        virtual void fontPropertyChanged(CSSFontFace&amp;, CSSValueList* oldFamilies = nullptr) { UNUSED_PARAM(oldFamilies); };
</del><ins>+        virtual void fontLoaded(CSSFontFace&amp;) { }
+        virtual void fontStateChanged(CSSFontFace&amp;, Status oldState, Status newState) { UNUSED_PARAM(oldState); UNUSED_PARAM(newState); }
+        virtual void fontPropertyChanged(CSSFontFace&amp;, CSSValueList* oldFamilies = nullptr) { UNUSED_PARAM(oldFamilies); }
+        virtual void ref() = 0;
+        virtual void deref() = 0;
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     // Pending =&gt; Loading  =&gt; TimedOut
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontFaceSetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontFaceSet.cpp (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontFaceSet.cpp        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/css/CSSFontFaceSet.cpp        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -398,13 +398,13 @@
</span><span class="cx">         return nullptr;
</span><span class="cx">     auto&amp; familyFontFaces = iterator-&gt;value;
</span><span class="cx"> 
</span><del>-    auto&amp; segmentedFontFaceCache = m_cache.add(family, HashMap&lt;unsigned, std::unique_ptr&lt;CSSSegmentedFontFace&gt;&gt;()).iterator-&gt;value;
</del><ins>+    auto&amp; segmentedFontFaceCache = m_cache.add(family, HashMap&lt;unsigned, RefPtr&lt;CSSSegmentedFontFace&gt;&gt;()).iterator-&gt;value;
</ins><span class="cx"> 
</span><span class="cx">     auto&amp; face = segmentedFontFaceCache.add(traitsMask, nullptr).iterator-&gt;value;
</span><span class="cx">     if (face)
</span><span class="cx">         return face.get();
</span><span class="cx"> 
</span><del>-    face = std::make_unique&lt;CSSSegmentedFontFace&gt;();
</del><ins>+    face = CSSSegmentedFontFace::create();
</ins><span class="cx"> 
</span><span class="cx">     Vector&lt;std::reference_wrapper&lt;CSSFontFace&gt;, 32&gt; candidateFontFaces;
</span><span class="cx">     for (int i = familyFontFaces.size() - 1; i &gt;= 0; --i) {
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSFontFaceSeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSFontFaceSet.h (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSFontFaceSet.h        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/css/CSSFontFaceSet.h        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -75,6 +75,10 @@
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;std::reference_wrapper&lt;CSSFontFace&gt;&gt; matchingFaces(const String&amp; font, const String&amp; text, ExceptionCode&amp;);
</span><span class="cx"> 
</span><ins>+    // CSSFontFace::Client needs to be able to be held in a RefPtr.
+    void ref() override { RefCounted&lt;CSSFontFaceSet&gt;::ref(); }
+    void deref() override { RefCounted&lt;CSSFontFaceSet&gt;::deref(); }
+
</ins><span class="cx"> private:
</span><span class="cx">     CSSFontFaceSet();
</span><span class="cx"> 
</span><span class="lines">@@ -95,7 +99,7 @@
</span><span class="cx">     Vector&lt;Ref&lt;CSSFontFace&gt;&gt; m_faces; // We should investigate moving m_faces to FontFaceSet and making it reference FontFaces. This may clean up the font loading design.
</span><span class="cx">     HashMap&lt;String, Vector&lt;Ref&lt;CSSFontFace&gt;&gt;, ASCIICaseInsensitiveHash&gt; m_facesLookupTable;
</span><span class="cx">     HashMap&lt;String, Vector&lt;Ref&lt;CSSFontFace&gt;&gt;, ASCIICaseInsensitiveHash&gt; m_locallyInstalledFacesLookupTable;
</span><del>-    HashMap&lt;String, HashMap&lt;unsigned, std::unique_ptr&lt;CSSSegmentedFontFace&gt;&gt;, ASCIICaseInsensitiveHash&gt; m_cache;
</del><ins>+    HashMap&lt;String, HashMap&lt;unsigned, RefPtr&lt;CSSSegmentedFontFace&gt;&gt;, ASCIICaseInsensitiveHash&gt; m_cache;
</ins><span class="cx">     size_t m_facesPartitionIndex { 0 }; // All entries in m_faces before this index are CSS-connected.
</span><span class="cx">     Status m_status { Status::Loaded };
</span><span class="cx">     HashSet&lt;CSSFontFaceSetClient*&gt; m_clients;
</span></span></pre></div>
<a id="trunkSourceWebCorecssCSSSegmentedFontFaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/CSSSegmentedFontFace.h (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/CSSSegmentedFontFace.h        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/css/CSSSegmentedFontFace.h        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -39,10 +39,13 @@
</span><span class="cx"> class CSSFontSelector;
</span><span class="cx"> class FontDescription;
</span><span class="cx"> 
</span><del>-class CSSSegmentedFontFace final : public CSSFontFace::Client {
</del><ins>+class CSSSegmentedFontFace final : public RefCounted&lt;CSSSegmentedFontFace&gt;, public CSSFontFace::Client {
</ins><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    CSSSegmentedFontFace();
</del><ins>+    static Ref&lt;CSSSegmentedFontFace&gt; create()
+    {
+        return adoptRef(*new CSSSegmentedFontFace());
+    }
</ins><span class="cx">     ~CSSSegmentedFontFace();
</span><span class="cx"> 
</span><span class="cx">     void appendFontFace(Ref&lt;CSSFontFace&gt;&amp;&amp;);
</span><span class="lines">@@ -51,7 +54,12 @@
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;Ref&lt;CSSFontFace&gt;, 1&gt;&amp; constituentFaces() { return m_fontFaces; }
</span><span class="cx"> 
</span><ins>+    // CSSFontFace::Client needs to be able to be held in a RefPtr.
+    void ref() override { RefCounted&lt;CSSSegmentedFontFace&gt;::ref(); }
+    void deref() override { RefCounted&lt;CSSSegmentedFontFace&gt;::deref(); }
+
</ins><span class="cx"> private:
</span><ins>+    CSSSegmentedFontFace();
</ins><span class="cx">     void fontLoaded(CSSFontFace&amp;) override;
</span><span class="cx"> 
</span><span class="cx">     HashMap&lt;FontDescriptionKey, FontRanges, FontDescriptionKeyHash, WTF::SimpleClassHashTraits&lt;FontDescriptionKey&gt;&gt; m_cache;
</span></span></pre></div>
<a id="trunkSourceWebCorecssFontFaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/FontFace.h (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/FontFace.h        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/css/FontFace.h        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -82,6 +82,10 @@
</span><span class="cx"> 
</span><span class="cx">     WeakPtr&lt;FontFace&gt; createWeakPtr() const;
</span><span class="cx"> 
</span><ins>+    // CSSFontFace::Client needs to be able to be held in a RefPtr.
+    void ref() override { RefCounted&lt;FontFace&gt;::ref(); }
+    void deref() override { RefCounted&lt;FontFace&gt;::deref(); }
+
</ins><span class="cx"> private:
</span><span class="cx">     FontFace(JSC::ExecState&amp;, CSSFontSelector&amp;);
</span><span class="cx">     FontFace(JSC::ExecState&amp;, CSSFontFace&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCorecssFontFaceSetcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/FontFaceSet.cpp (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/FontFaceSet.cpp        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/css/FontFaceSet.cpp        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -236,12 +236,16 @@
</span><span class="cx"> 
</span><span class="cx">     for (auto&amp; pendingPromise : iterator-&gt;value) {
</span><span class="cx">         if (newStatus == CSSFontFace::Status::Success) {
</span><del>-            if (pendingPromise-&gt;hasOneRef())
</del><ins>+            if (pendingPromise-&gt;hasOneRef() &amp;&amp; !pendingPromise-&gt;hasReachedTerminalState) {
</ins><span class="cx">                 pendingPromise-&gt;promise.resolve(pendingPromise-&gt;faces);
</span><ins>+                pendingPromise-&gt;hasReachedTerminalState = true;
+            }
</ins><span class="cx">         } else {
</span><span class="cx">             ASSERT(newStatus == CSSFontFace::Status::Failure);
</span><del>-            // The first resolution wins, so we can just reject early now.
-            pendingPromise-&gt;promise.reject(DOMCoreException::create(ExceptionCodeDescription(NETWORK_ERR)));
</del><ins>+            if (!pendingPromise-&gt;hasReachedTerminalState) {
+                pendingPromise-&gt;promise.reject(DOMCoreException::create(ExceptionCodeDescription(NETWORK_ERR)));
+                pendingPromise-&gt;hasReachedTerminalState = true;
+            }
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecssFontFaceSeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/FontFaceSet.h (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/FontFaceSet.h        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/css/FontFaceSet.h        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -101,6 +101,7 @@
</span><span class="cx">     public:
</span><span class="cx">         Vector&lt;RefPtr&lt;FontFace&gt;&gt; faces;
</span><span class="cx">         Promise promise;
</span><ins>+        bool hasReachedTerminalState { false };
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     FontFaceSet(Document&amp;, const Vector&lt;RefPtr&lt;FontFace&gt;&gt;&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (197803 => 197804)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2016-03-08 21:58:30 UTC (rev 197803)
+++ trunk/Source/WebCore/dom/Document.cpp        2016-03-08 22:22:40 UTC (rev 197804)
</span><span class="lines">@@ -6706,6 +6706,7 @@
</span><span class="cx"> 
</span><span class="cx"> Ref&lt;FontFaceSet&gt; Document::fonts()
</span><span class="cx"> {
</span><ins>+    updateStyleIfNeeded();
</ins><span class="cx">     return fontSelector().fontFaceSet();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>