<!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 <cdumez@apple.com>
+
+ 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 <zdobersek@igalia.com>
</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& 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& attributeName, int value)
</span><span class="lines">@@ -2777,9 +2775,7 @@
</span><span class="cx">
</span><span class="cx"> unsigned Element::getUnsignedIntegralAttribute(const QualifiedName& 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& 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& 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& value, MutableStyleProperties& 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& value)
</span><span class="cx"> {
</span><del>- int maxLength;
- if (!parseHTMLInteger(value, maxLength))
- maxLength = maximumLength;
- if (maxLength < 0 || maxLength > 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& 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->renderer()) {
</span><span class="cx"> // Check the attribute first for an explicit pixel value.
</span><del>- unsigned height;
- if (parseHTMLNonNegativeInteger(element->fastGetAttribute(heightAttr), height))
- return height;
</del><ins>+ if (auto optionalHeight = parseHTMLNonNegativeInteger(element->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->imageLoader();
</span><span class="lines">@@ -198,9 +197,8 @@
</span><span class="cx">
</span><span class="cx"> if (!element->renderer()) {
</span><span class="cx"> // Check the attribute first for an explicit pixel value.
</span><del>- unsigned width;
- if (parseHTMLNonNegativeInteger(element->fastGetAttribute(widthAttr), width))
- return width;
</del><ins>+ if (auto optionalWidth = parseHTMLNonNegativeInteger(element->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->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 <typename CharacterType>
</span><del>-static bool parseHTMLIntegerInternal(const CharacterType* position, const CharacterType* end, int& value)
</del><ins>+static Optional<int> parseHTMLIntegerInternal(const CharacterType* position, const CharacterType* end)
</ins><span class="cx"> {
</span><span class="cx"> while (position < end && 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<int>::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 > maxMultiplier || (result == maxMultiplier && digitValue > (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 < end && 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& input, int& value)
</del><ins>+Optional<int> parseHTMLInteger(const String& 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& input, unsigned& value)
</del><ins>+Optional<unsigned> parseHTMLNonNegativeInteger(const String& input)
</ins><span class="cx"> {
</span><del>- int signedValue;
- if (!parseHTMLInteger(input, signedValue) || signedValue < 0)
- return false;
</del><ins>+ Optional<int> signedValue = parseHTMLInteger(input);
+ if (!signedValue || signedValue.value() < 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& a, const StringImpl& 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 <unicode/uchar.h>
</span><span class="cx"> #include <wtf/Forward.h>
</span><ins>+#include <wtf/Optional.h>
</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&, 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&, int&);
</del><ins>+WEBCORE_EXPORT Optional<int> parseHTMLInteger(const String&);
</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&, unsigned&);
</del><ins>+WEBCORE_EXPORT Optional<unsigned> parseHTMLNonNegativeInteger(const String&);
</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&);
</span><span class="lines">@@ -120,9 +121,8 @@
</span><span class="cx">
</span><span class="cx"> inline unsigned limitToOnlyHTMLNonNegativeNumbersGreaterThanZero(const String& 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 && optionalValue.value() ? optionalValue.value() : defaultValue;
</ins><span class="cx"> ASSERT(value > 0 && value <= 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& 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 <= 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<int>(std::numeric_limits<short>::min()), std::min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
</del><ins>+ setTabIndexExplicitly(std::max(static_cast<int>(std::numeric_limits<short>::min()), std::min(optionalTabIndex.value(), static_cast<int>(std::numeric_limits<short>::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 <cdumez@apple.com>
+
+ 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 <simon.fraser@apple.com>
</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& 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& 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& 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& 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>