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