<!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>[197449] trunk/Source/WebCore</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/197449">197449</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-03-02 09:12:37 -0800 (Wed, 02 Mar 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 Darin Adler.

Take into consideration review comments made after landing <a href="http://trac.webkit.org/projects/webkit/changeset/197389">r197389</a>.

* html/HTMLElement.cpp:
(WebCore::HTMLElement::parseBorderWidthAttribute):
(WebCore::HTMLElement::parseAttribute):
* html/HTMLInputElement.cpp:
* html/HTMLInputElement.h:
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::maxLength):
* html/ImageInputType.cpp:
(WebCore::ImageInputType::height):
(WebCore::ImageInputType::width):
* html/parser/HTMLParserIdioms.cpp:
(WebCore::parseHTMLNonNegativeInteger):
* html/parser/HTMLParserIdioms.h:
(WebCore::limitToOnlyHTMLNonNegativeNumbersGreaterThanZero):
(WebCore::limitToOnlyHTMLNonNegative):
* svg/SVGElement.cpp:
(WebCore::SVGElement::parseAttribute):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</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="#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>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/ChangeLog        2016-03-02 17:12:37 UTC (rev 197449)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2016-03-02  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Have parseHTMLInteger() / parseHTMLNonNegativeInteger() use WTF::Optional
+        https://bugs.webkit.org/show_bug.cgi?id=154845
+
+        Reviewed by Darin Adler.
+
+        Take into consideration review comments made after landing r197389.
+
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::parseBorderWidthAttribute):
+        (WebCore::HTMLElement::parseAttribute):
+        * html/HTMLInputElement.cpp:
+        * html/HTMLInputElement.h:
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::maxLength):
+        * html/ImageInputType.cpp:
+        (WebCore::ImageInputType::height):
+        (WebCore::ImageInputType::width):
+        * html/parser/HTMLParserIdioms.cpp:
+        (WebCore::parseHTMLNonNegativeInteger):
+        * html/parser/HTMLParserIdioms.h:
+        (WebCore::limitToOnlyHTMLNonNegativeNumbersGreaterThanZero):
+        (WebCore::limitToOnlyHTMLNonNegative):
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::parseAttribute):
+
</ins><span class="cx"> 2016-03-01  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Remove the &quot;Partial Support&quot; status from web components since shadow DOM and custom elements
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLElement.cpp (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLElement.cpp        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/html/HTMLElement.cpp        2016-03-02 17:12:37 UTC (rev 197449)
</span><span class="lines">@@ -133,8 +133,10 @@
</span><span class="cx"> 
</span><span class="cx"> unsigned HTMLElement::parseBorderWidthAttribute(const AtomicString&amp; value) const
</span><span class="cx"> {
</span><del>-    auto optionalBorderWidth = value.isEmpty() ? Nullopt : parseHTMLNonNegativeInteger(value);
-    return optionalBorderWidth.valueOr(hasTagName(tableTag) ? 1 : 0);
</del><ins>+    if (Optional&lt;int&gt; borderWidth = parseHTMLNonNegativeInteger(value))
+        return borderWidth.value();
+
+    return 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,9 +453,9 @@
</span><span class="cx">     if (name == tabindexAttr) {
</span><span class="cx">         if (value.isEmpty())
</span><span class="cx">             clearTabIndexExplicitlyIfNeeded();
</span><del>-        else if (auto optionalTabIndex = parseHTMLInteger(value)) {
</del><ins>+        else if (Optional&lt;int&gt; tabIndex = 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(optionalTabIndex.value(), 0x7FFF)));
</del><ins>+            setTabIndexExplicitly(std::max(-0x8000, std::min(tabIndex.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 (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLInputElement.cpp        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp        2016-03-02 17:12:37 UTC (rev 197449)
</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 unsigned HTMLInputElement::maximumLength = 524288;
</del><ins>+const int 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></pre></div>
<a id="trunkSourceWebCorehtmlHTMLInputElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLInputElement.h (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLInputElement.h        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/html/HTMLInputElement.h        2016-03-02 17:12:37 UTC (rev 197449)
</span><span class="lines">@@ -292,7 +292,7 @@
</span><span class="cx">     bool shouldUseMediaCapture() const;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    static const unsigned maximumLength;
</del><ins>+    static const int 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="trunkSourceWebCorehtmlHTMLTextAreaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp        2016-03-02 17:12:37 UTC (rev 197449)
</span><span class="lines">@@ -423,10 +423,7 @@
</span><span class="cx"> 
</span><span class="cx"> int HTMLTextAreaElement::maxLength() const
</span><span class="cx"> {
</span><del>-    auto optionalMaxLength = parseHTMLNonNegativeInteger(fastGetAttribute(maxlengthAttr));
-    if (!optionalMaxLength)
-        return -1;
-    return optionalMaxLength.value();
</del><ins>+    return parseHTMLNonNegativeInteger(fastGetAttribute(maxlengthAttr)).valueOr(-1);
</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 (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/ImageInputType.cpp        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/html/ImageInputType.cpp        2016-03-02 17:12:37 UTC (rev 197449)
</span><span class="lines">@@ -176,8 +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>-        if (auto optionalHeight = parseHTMLNonNegativeInteger(element-&gt;fastGetAttribute(heightAttr)))
-            return optionalHeight.value();
</del><ins>+        if (Optional&lt;int&gt; height = parseHTMLNonNegativeInteger(element-&gt;fastGetAttribute(heightAttr)))
+            return height.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">@@ -197,8 +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>-        if (auto optionalWidth = parseHTMLNonNegativeInteger(element-&gt;fastGetAttribute(widthAttr)))
-            return optionalWidth.value();
</del><ins>+        if (Optional&lt;int&gt; width = parseHTMLNonNegativeInteger(element-&gt;fastGetAttribute(widthAttr)))
+            return width.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 (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp        2016-03-02 17:12:37 UTC (rev 197449)
</span><span class="lines">@@ -206,13 +206,13 @@
</span><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>-Optional&lt;unsigned&gt; parseHTMLNonNegativeInteger(const String&amp; input)
</del><ins>+Optional&lt;int&gt; parseHTMLNonNegativeInteger(const String&amp; input)
</ins><span class="cx"> {
</span><span class="cx">     Optional&lt;int&gt; signedValue = parseHTMLInteger(input);
</span><span class="cx">     if (!signedValue || signedValue.value() &lt; 0)
</span><span class="cx">         return Nullopt;
</span><span class="cx"> 
</span><del>-    return signedValue.value();
</del><ins>+    return signedValue;
</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 (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.h        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.h        2016-03-02 17:12:37 UTC (rev 197449)
</span><span class="lines">@@ -64,7 +64,7 @@
</span><span class="cx"> WEBCORE_EXPORT Optional&lt;int&gt; parseHTMLInteger(const String&amp;);
</span><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 Optional&lt;unsigned&gt; parseHTMLNonNegativeInteger(const String&amp;);
</del><ins>+WEBCORE_EXPORT Optional&lt;int&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">@@ -121,20 +121,25 @@
</span><span class="cx"> 
</span><span class="cx"> inline unsigned limitToOnlyHTMLNonNegativeNumbersGreaterThanZero(const String&amp; stringValue, unsigned defaultValue = 1)
</span><span class="cx"> {
</span><ins>+    ASSERT(defaultValue &gt; 0);
+    ASSERT(defaultValue &lt;= maxHTMLNonNegativeInteger);
</ins><span class="cx">     auto optionalValue = parseHTMLNonNegativeInteger(stringValue);
</span><span class="cx">     unsigned value = optionalValue &amp;&amp; optionalValue.value() ? optionalValue.value() : defaultValue;
</span><del>-    ASSERT(value &gt; 0 &amp;&amp; value &lt;= maxHTMLNonNegativeInteger);
</del><ins>+    ASSERT(value &gt; 0);
+    ASSERT(value &lt;= maxHTMLNonNegativeInteger);
</ins><span class="cx">     return value;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://html.spec.whatwg.org/#reflecting-content-attributes-in-idl-attributes:idl-unsigned-long
</span><span class="cx"> inline unsigned limitToOnlyHTMLNonNegative(unsigned value, unsigned defaultValue = 0)
</span><span class="cx"> {
</span><ins>+    ASSERT(defaultValue &lt;= maxHTMLNonNegativeInteger);
</ins><span class="cx">     return value &lt;= maxHTMLNonNegativeInteger ? value : defaultValue;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline unsigned limitToOnlyHTMLNonNegative(const String&amp; stringValue, unsigned defaultValue = 0)
</span><span class="cx"> {
</span><ins>+    ASSERT(defaultValue &lt;= maxHTMLNonNegativeInteger);
</ins><span class="cx">     unsigned value = parseHTMLNonNegativeInteger(stringValue).valueOr(defaultValue);
</span><span class="cx">     ASSERT(value &lt;= maxHTMLNonNegativeInteger);
</span><span class="cx">     return value;
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGElement.cpp (197448 => 197449)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGElement.cpp        2016-03-02 17:08:08 UTC (rev 197448)
+++ trunk/Source/WebCore/svg/SVGElement.cpp        2016-03-02 17:12:37 UTC (rev 197449)
</span><span class="lines">@@ -518,9 +518,9 @@
</span><span class="cx">     if (name == HTMLNames::tabindexAttr) {
</span><span class="cx">         if (value.isEmpty())
</span><span class="cx">             clearTabIndexExplicitlyIfNeeded();
</span><del>-        else if (auto optionalTabIndex = parseHTMLInteger(value)) {
</del><ins>+        else if (Optional&lt;int&gt; tabIndex = 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(optionalTabIndex.value(), 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(tabIndex.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>
</div>

</body>
</html>