<!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>[197389] 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/197389">197389</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-02-29 23:37:16 -0800 (Mon, 29 Feb 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Have parseHTMLInteger() / parseHTMLNonNegativeInteger() use WTF::Optional
https://bugs.webkit.org/show_bug.cgi?id=154845

Reviewed by Ryosuke Niwa.

Source/WebCore:

Have parseHTMLInteger() / parseHTMLNonNegativeInteger() use
WTF::Optional.

* dom/Element.cpp:
(WebCore::Element::getIntegralAttribute):
(WebCore::Element::getUnsignedIntegralAttribute):
(WebCore::Element::setUnsignedIntegralAttribute): Deleted.
* html/HTMLElement.cpp:
(WebCore::HTMLElement::parseBorderWidthAttribute):
(WebCore::HTMLElement::parseAttribute):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parseMaxLengthAttribute):
* html/HTMLInputElement.h:
* html/HTMLOListElement.cpp:
(WebCore::HTMLOListElement::parseAttribute):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::maxLength):
* html/ImageInputType.cpp:
(WebCore::ImageInputType::height):
(WebCore::ImageInputType::width):
* html/parser/HTMLParserIdioms.cpp:
(WebCore::parseHTMLIntegerInternal):
(WebCore::parseHTMLInteger):
(WebCore::parseHTMLNonNegativeInteger):
* html/parser/HTMLParserIdioms.h:
(WebCore::limitToOnlyHTMLNonNegativeNumbersGreaterThanZero):
(WebCore::limitToOnlyHTMLNonNegative):
* svg/SVGElement.cpp:
(WebCore::SVGElement::parseAttribute):

Tools:

Update API tests accordingly.

* TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp:
(TestWebKitAPI::testParseHTMLInteger):
(TestWebKitAPI::parseHTMLIntegerFails):
(TestWebKitAPI::testParseHTMLNonNegativeInteger):
(TestWebKitAPI::parseHTMLNonNegativeIntegerFails):
(TestWebKitAPI::TEST): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLElementcpp">trunk/Source/WebCore/html/HTMLElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLInputElementcpp">trunk/Source/WebCore/html/HTMLInputElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLInputElementh">trunk/Source/WebCore/html/HTMLInputElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLOListElementcpp">trunk/Source/WebCore/html/HTMLOListElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLTextAreaElementcpp">trunk/Source/WebCore/html/HTMLTextAreaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlImageInputTypecpp">trunk/Source/WebCore/html/ImageInputType.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLParserIdiomscpp">trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLParserIdiomsh">trunk/Source/WebCore/html/parser/HTMLParserIdioms.h</a></li>
<li><a href="#trunkSourceWebCoresvgSVGElementcpp">trunk/Source/WebCore/svg/SVGElement.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebCoreHTMLParserIdiomscpp">trunk/Tools/TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/ChangeLog        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-02-29  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Have parseHTMLInteger() / parseHTMLNonNegativeInteger() use WTF::Optional
+        https://bugs.webkit.org/show_bug.cgi?id=154845
+
+        Reviewed by Ryosuke Niwa.
+
+        Have parseHTMLInteger() / parseHTMLNonNegativeInteger() use
+        WTF::Optional.
+
+        * dom/Element.cpp:
+        (WebCore::Element::getIntegralAttribute):
+        (WebCore::Element::getUnsignedIntegralAttribute):
+        (WebCore::Element::setUnsignedIntegralAttribute): Deleted.
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::parseBorderWidthAttribute):
+        (WebCore::HTMLElement::parseAttribute):
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::parseMaxLengthAttribute):
+        * html/HTMLInputElement.h:
+        * html/HTMLOListElement.cpp:
+        (WebCore::HTMLOListElement::parseAttribute):
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::maxLength):
+        * html/ImageInputType.cpp:
+        (WebCore::ImageInputType::height):
+        (WebCore::ImageInputType::width):
+        * html/parser/HTMLParserIdioms.cpp:
+        (WebCore::parseHTMLIntegerInternal):
+        (WebCore::parseHTMLInteger):
+        (WebCore::parseHTMLNonNegativeInteger):
+        * html/parser/HTMLParserIdioms.h:
+        (WebCore::limitToOnlyHTMLNonNegativeNumbersGreaterThanZero):
+        (WebCore::limitToOnlyHTMLNonNegative):
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::parseAttribute):
+
</ins><span class="cx"> 2016-02-29  Zan Dobersek  &lt;zdobersek@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         TextureMapperGL: simplify TransformationMatrix copies in draw(), beginClip()
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/dom/Element.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -2765,9 +2765,7 @@
</span><span class="cx"> 
</span><span class="cx"> int Element::getIntegralAttribute(const QualifiedName&amp; attributeName) const
</span><span class="cx"> {
</span><del>-    int value = 0;
-    parseHTMLInteger(getAttribute(attributeName), value);
-    return value;
</del><ins>+    return parseHTMLInteger(getAttribute(attributeName)).valueOr(0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Element::setIntegralAttribute(const QualifiedName&amp; attributeName, int value)
</span><span class="lines">@@ -2777,9 +2775,7 @@
</span><span class="cx"> 
</span><span class="cx"> unsigned Element::getUnsignedIntegralAttribute(const QualifiedName&amp; attributeName) const
</span><span class="cx"> {
</span><del>-    unsigned value = 0;
-    parseHTMLNonNegativeInteger(getAttribute(attributeName), value);
-    return value;
</del><ins>+    return parseHTMLNonNegativeInteger(getAttribute(attributeName)).valueOr(0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Element::setUnsignedIntegralAttribute(const QualifiedName&amp; attributeName, unsigned value)
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLElement.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLElement.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/html/HTMLElement.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -133,10 +133,8 @@
</span><span class="cx"> 
</span><span class="cx"> unsigned HTMLElement::parseBorderWidthAttribute(const AtomicString&amp; value) const
</span><span class="cx"> {
</span><del>-    unsigned borderWidth = 0;
-    if (value.isEmpty() || !parseHTMLNonNegativeInteger(value, borderWidth))
-        return hasTagName(tableTag) ? 1 : borderWidth;
-    return borderWidth;
</del><ins>+    auto optionalBorderWidth = value.isEmpty() ? Nullopt : parseHTMLNonNegativeInteger(value);
+    return optionalBorderWidth.valueOr(hasTagName(tableTag) ? 1 : 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLElement::applyBorderAttributeToStyle(const AtomicString&amp; value, MutableStyleProperties&amp; style)
</span><span class="lines">@@ -451,12 +449,11 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (name == tabindexAttr) {
</span><del>-        int tabIndex = 0;
</del><span class="cx">         if (value.isEmpty())
</span><span class="cx">             clearTabIndexExplicitlyIfNeeded();
</span><del>-        else if (parseHTMLInteger(value, tabIndex)) {
</del><ins>+        else if (auto optionalTabIndex = parseHTMLInteger(value)) {
</ins><span class="cx">             // Clamp tab index to a 16-bit value to match Firefox's behavior.
</span><del>-            setTabIndexExplicitly(std::max(-0x8000, std::min(tabIndex, 0x7FFF)));
</del><ins>+            setTabIndexExplicitly(std::max(-0x8000, std::min(optionalTabIndex.value(), 0x7FFF)));
</ins><span class="cx">         }
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLInputElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLInputElement.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -89,7 +89,7 @@
</span><span class="cx"> // large. However, due to https://bugs.webkit.org/show_bug.cgi?id=14536 things
</span><span class="cx"> // get rather sluggish when a text field has a larger number of characters than
</span><span class="cx"> // this, even when just clicking in the text field.
</span><del>-const int HTMLInputElement::maximumLength = 524288;
</del><ins>+const unsigned HTMLInputElement::maximumLength = 524288;
</ins><span class="cx"> const int defaultSize = 20;
</span><span class="cx"> const int maxSavedResults = 256;
</span><span class="cx"> 
</span><span class="lines">@@ -1742,11 +1742,7 @@
</span><span class="cx"> 
</span><span class="cx"> void HTMLInputElement::parseMaxLengthAttribute(const AtomicString&amp; value)
</span><span class="cx"> {
</span><del>-    int maxLength;
-    if (!parseHTMLInteger(value, maxLength))
-        maxLength = maximumLength;
-    if (maxLength &lt; 0 || maxLength &gt; maximumLength)
-        maxLength = maximumLength;
</del><ins>+    int maxLength = std::min(parseHTMLNonNegativeInteger(value).valueOr(maximumLength), maximumLength);
</ins><span class="cx">     int oldMaxLength = m_maxLength;
</span><span class="cx">     m_maxLength = maxLength;
</span><span class="cx">     if (oldMaxLength != maxLength)
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLInputElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLInputElement.h (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLInputElement.h        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/html/HTMLInputElement.h        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -289,7 +289,7 @@
</span><span class="cx">     bool shouldUseMediaCapture() const;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    static const int maximumLength;
</del><ins>+    static const unsigned maximumLength;
</ins><span class="cx"> 
</span><span class="cx">     unsigned height() const;
</span><span class="cx">     unsigned width() const;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLOListElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLOListElement.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLOListElement.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/html/HTMLOListElement.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -80,11 +80,7 @@
</span><span class="cx"> {
</span><span class="cx">     if (name == startAttr) {
</span><span class="cx">         int oldStart = start();
</span><del>-        int parsedStart;
-        if (parseHTMLInteger(value, parsedStart))
-            m_start = parsedStart;
-        else
-            m_start = Nullopt;
</del><ins>+        m_start = parseHTMLInteger(value);
</ins><span class="cx">         if (oldStart == start())
</span><span class="cx">             return;
</span><span class="cx">         updateItemValues();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLTextAreaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -423,10 +423,10 @@
</span><span class="cx"> 
</span><span class="cx"> int HTMLTextAreaElement::maxLength() const
</span><span class="cx"> {
</span><del>-    unsigned result;
-    if (parseHTMLNonNegativeInteger(fastGetAttribute(maxlengthAttr), result))
-        return result;
-    return -1;
</del><ins>+    auto optionalMaxLength = parseHTMLNonNegativeInteger(fastGetAttribute(maxlengthAttr));
+    if (!optionalMaxLength)
+        return -1;
+    return optionalMaxLength.value();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionCode&amp; ec)
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlImageInputTypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/ImageInputType.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/ImageInputType.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/html/ImageInputType.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -176,9 +176,8 @@
</span><span class="cx"> 
</span><span class="cx">     if (!element-&gt;renderer()) {
</span><span class="cx">         // Check the attribute first for an explicit pixel value.
</span><del>-        unsigned height;
-        if (parseHTMLNonNegativeInteger(element-&gt;fastGetAttribute(heightAttr), height))
-            return height;
</del><ins>+        if (auto optionalHeight = parseHTMLNonNegativeInteger(element-&gt;fastGetAttribute(heightAttr)))
+            return optionalHeight.value();
</ins><span class="cx"> 
</span><span class="cx">         // If the image is available, use its height.
</span><span class="cx">         HTMLImageLoader* imageLoader = element-&gt;imageLoader();
</span><span class="lines">@@ -198,9 +197,8 @@
</span><span class="cx"> 
</span><span class="cx">     if (!element-&gt;renderer()) {
</span><span class="cx">         // Check the attribute first for an explicit pixel value.
</span><del>-        unsigned width;
-        if (parseHTMLNonNegativeInteger(element-&gt;fastGetAttribute(widthAttr), width))
-            return width;
</del><ins>+        if (auto optionalWidth = parseHTMLNonNegativeInteger(element-&gt;fastGetAttribute(widthAttr)))
+            return optionalWidth.value();
</ins><span class="cx"> 
</span><span class="cx">         // If the image is available, use its width.
</span><span class="cx">         HTMLImageLoader* imageLoader = element-&gt;imageLoader();
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLParserIdiomscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -153,13 +153,13 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename CharacterType&gt;
</span><del>-static bool parseHTMLIntegerInternal(const CharacterType* position, const CharacterType* end, int&amp; value)
</del><ins>+static Optional&lt;int&gt; parseHTMLIntegerInternal(const CharacterType* position, const CharacterType* end)
</ins><span class="cx"> {
</span><span class="cx">     while (position &lt; end &amp;&amp; isHTMLSpace(*position))
</span><span class="cx">         ++position;
</span><span class="cx"> 
</span><span class="cx">     if (position == end)
</span><del>-        return false;
</del><ins>+        return Nullopt;
</ins><span class="cx"> 
</span><span class="cx">     bool isNegative = false;
</span><span class="cx">     if (*position == '-') {
</span><span class="lines">@@ -169,7 +169,7 @@
</span><span class="cx">         ++position;
</span><span class="cx"> 
</span><span class="cx">     if (position == end || !isASCIIDigit(*position))
</span><del>-        return false;
</del><ins>+        return Nullopt;
</ins><span class="cx"> 
</span><span class="cx">     constexpr int intMax = std::numeric_limits&lt;int&gt;::max();
</span><span class="cx">     constexpr int base = 10;
</span><span class="lines">@@ -180,41 +180,39 @@
</span><span class="cx">         int digitValue = *position - '0';
</span><span class="cx"> 
</span><span class="cx">         if (result &gt; maxMultiplier || (result == maxMultiplier &amp;&amp; digitValue &gt; (intMax % base) + isNegative))
</span><del>-            return false;
</del><ins>+            return Nullopt;
</ins><span class="cx"> 
</span><span class="cx">         result = base * result + digitValue;
</span><span class="cx">         ++position;
</span><span class="cx">     } while (position &lt; end &amp;&amp; isASCIIDigit(*position));
</span><span class="cx"> 
</span><del>-    value = isNegative ? -result : result;
-    return true;
</del><ins>+    return isNegative ? -result : result;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-integers
</span><del>-bool parseHTMLInteger(const String&amp; input, int&amp; value)
</del><ins>+Optional&lt;int&gt; parseHTMLInteger(const String&amp; input)
</ins><span class="cx"> {
</span><span class="cx">     unsigned length = input.length();
</span><span class="cx">     if (!length)
</span><del>-        return false;
</del><ins>+        return Nullopt;
</ins><span class="cx"> 
</span><span class="cx">     if (LIKELY(input.is8Bit())) {
</span><span class="cx">         auto* start = input.characters8();
</span><del>-        return parseHTMLIntegerInternal(start, start + length, value);
</del><ins>+        return parseHTMLIntegerInternal(start, start + length);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto* start = input.characters16();
</span><del>-    return parseHTMLIntegerInternal(start, start + length, value);
</del><ins>+    return parseHTMLIntegerInternal(start, start + length);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-non-negative-integers
</span><del>-bool parseHTMLNonNegativeInteger(const String&amp; input, unsigned&amp; value)
</del><ins>+Optional&lt;unsigned&gt; parseHTMLNonNegativeInteger(const String&amp; input)
</ins><span class="cx"> {
</span><del>-    int signedValue;
-    if (!parseHTMLInteger(input, signedValue) || signedValue &lt; 0)
-        return false;
</del><ins>+    Optional&lt;int&gt; signedValue = parseHTMLInteger(input);
+    if (!signedValue || signedValue.value() &lt; 0)
+        return Nullopt;
</ins><span class="cx"> 
</span><del>-    value = signedValue;
-    return true;
</del><ins>+    return signedValue.value();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool threadSafeEqual(const StringImpl&amp; a, const StringImpl&amp; b)
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLParserIdiomsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.h (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.h        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.h        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &lt;unicode/uchar.h&gt;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><ins>+#include &lt;wtf/Optional.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -60,10 +61,10 @@
</span><span class="cx"> double parseToDoubleForNumberType(const String&amp;, double fallbackValue);
</span><span class="cx"> 
</span><span class="cx"> // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
</span><del>-WEBCORE_EXPORT bool parseHTMLInteger(const String&amp;, int&amp;);
</del><ins>+WEBCORE_EXPORT Optional&lt;int&gt; parseHTMLInteger(const String&amp;);
</ins><span class="cx"> 
</span><span class="cx"> // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers
</span><del>-WEBCORE_EXPORT bool parseHTMLNonNegativeInteger(const String&amp;, unsigned&amp;);
</del><ins>+WEBCORE_EXPORT Optional&lt;unsigned&gt; parseHTMLNonNegativeInteger(const String&amp;);
</ins><span class="cx"> 
</span><span class="cx"> // https://html.spec.whatwg.org/multipage/infrastructure.html#cors-settings-attribute
</span><span class="cx"> String parseCORSSettingsAttribute(const AtomicString&amp;);
</span><span class="lines">@@ -120,9 +121,8 @@
</span><span class="cx"> 
</span><span class="cx"> inline unsigned limitToOnlyHTMLNonNegativeNumbersGreaterThanZero(const String&amp; stringValue, unsigned defaultValue = 1)
</span><span class="cx"> {
</span><del>-    unsigned value;
-    if (!parseHTMLNonNegativeInteger(stringValue, value) || !value)
-        value = defaultValue;
</del><ins>+    auto optionalValue = parseHTMLNonNegativeInteger(stringValue);
+    unsigned value = optionalValue &amp;&amp; optionalValue.value() ? optionalValue.value() : defaultValue;
</ins><span class="cx">     ASSERT(value &gt; 0 &amp;&amp; value &lt;= maxHTMLNonNegativeInteger);
</span><span class="cx">     return value;
</span><span class="cx"> }
</span><span class="lines">@@ -135,9 +135,7 @@
</span><span class="cx"> 
</span><span class="cx"> inline unsigned limitToOnlyHTMLNonNegative(const String&amp; stringValue, unsigned defaultValue = 0)
</span><span class="cx"> {
</span><del>-    unsigned value;
-    if (!parseHTMLNonNegativeInteger(stringValue, value))
-        value = defaultValue;
</del><ins>+    unsigned value = parseHTMLNonNegativeInteger(stringValue).valueOr(defaultValue);
</ins><span class="cx">     ASSERT(value &lt;= maxHTMLNonNegativeInteger);
</span><span class="cx">     return value;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGElement.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGElement.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Source/WebCore/svg/SVGElement.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -516,12 +516,11 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (name == HTMLNames::tabindexAttr) {
</span><del>-        int tabindex = 0;
</del><span class="cx">         if (value.isEmpty())
</span><span class="cx">             clearTabIndexExplicitlyIfNeeded();
</span><del>-        else if (parseHTMLInteger(value, tabindex)) {
</del><ins>+        else if (auto optionalTabIndex = parseHTMLInteger(value)) {
</ins><span class="cx">             // Clamp tabindex to the range of 'short' to match Firefox's behavior.
</span><del>-            setTabIndexExplicitly(std::max(static_cast&lt;int&gt;(std::numeric_limits&lt;short&gt;::min()), std::min(tabindex, static_cast&lt;int&gt;(std::numeric_limits&lt;short&gt;::max()))));
</del><ins>+            setTabIndexExplicitly(std::max(static_cast&lt;int&gt;(std::numeric_limits&lt;short&gt;::min()), std::min(optionalTabIndex.value(), static_cast&lt;int&gt;(std::numeric_limits&lt;short&gt;::max()))));
</ins><span class="cx">         }
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Tools/ChangeLog        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2016-02-29  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Have parseHTMLInteger() / parseHTMLNonNegativeInteger() use WTF::Optional
+        https://bugs.webkit.org/show_bug.cgi?id=154845
+
+        Reviewed by Ryosuke Niwa.
+
+        Update API tests accordingly.
+
+        * TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp:
+        (TestWebKitAPI::testParseHTMLInteger):
+        (TestWebKitAPI::parseHTMLIntegerFails):
+        (TestWebKitAPI::testParseHTMLNonNegativeInteger):
+        (TestWebKitAPI::parseHTMLNonNegativeIntegerFails):
+        (TestWebKitAPI::TEST): Deleted.
+
</ins><span class="cx"> 2016-02-29  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove the experimental feature of antialiased font dilation
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebCoreHTMLParserIdiomscpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp (197388 => 197389)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp        2016-03-01 07:36:02 UTC (rev 197388)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/HTMLParserIdioms.cpp        2016-03-01 07:37:16 UTC (rev 197389)
</span><span class="lines">@@ -35,16 +35,14 @@
</span><span class="cx"> 
</span><span class="cx"> static int testParseHTMLInteger(const String&amp; input)
</span><span class="cx"> {
</span><del>-    int result = 0;
-    bool success = parseHTMLInteger(input, result);
-    EXPECT_TRUE(success);
-    return result;
</del><ins>+    auto optionalResult = parseHTMLInteger(input);
+    EXPECT_TRUE(!!optionalResult);
+    return optionalResult.valueOr(0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool parseHTMLIntegerFails(const String&amp; input)
</span><span class="cx"> {
</span><del>-    int result = 0;
-    return !parseHTMLInteger(input, result);
</del><ins>+    return !parseHTMLInteger(input);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST(WebCoreHTMLParserIdioms, parseHTMLInteger)
</span><span class="lines">@@ -101,16 +99,14 @@
</span><span class="cx"> 
</span><span class="cx"> static unsigned testParseHTMLNonNegativeInteger(const String&amp; input)
</span><span class="cx"> {
</span><del>-    unsigned result = 0;
-    bool success = parseHTMLNonNegativeInteger(input, result);
-    EXPECT_TRUE(success);
-    return result;
</del><ins>+    auto optionalResult = parseHTMLNonNegativeInteger(input);
+    EXPECT_TRUE(!!optionalResult);
+    return optionalResult.valueOr(0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static bool parseHTMLNonNegativeIntegerFails(const String&amp; input)
</span><span class="cx"> {
</span><del>-    unsigned result = 0;
-    return !parseHTMLNonNegativeInteger(input, result);
</del><ins>+    return !parseHTMLNonNegativeInteger(input);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST(WebCoreHTMLParserIdioms, parseHTMLNonNegativeInteger)
</span></span></pre>
</div>
</div>

</body>
</html>