Diff
Modified: trunk/Source/WebCore/ChangeLog (197448 => 197449)
--- 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)
@@ -1,3 +1,30 @@
+2016-03-02 Chris Dumez <[email protected]>
+
+ 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):
+
2016-03-01 Ryosuke Niwa <[email protected]>
Unreviewed. Remove the "Partial Support" status from web components since shadow DOM and custom elements
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (197448 => 197449)
--- 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)
@@ -133,8 +133,10 @@
unsigned HTMLElement::parseBorderWidthAttribute(const AtomicString& value) const
{
- auto optionalBorderWidth = value.isEmpty() ? Nullopt : parseHTMLNonNegativeInteger(value);
- return optionalBorderWidth.valueOr(hasTagName(tableTag) ? 1 : 0);
+ if (Optional<int> borderWidth = parseHTMLNonNegativeInteger(value))
+ return borderWidth.value();
+
+ return hasTagName(tableTag) ? 1 : 0;
}
void HTMLElement::applyBorderAttributeToStyle(const AtomicString& value, MutableStyleProperties& style)
@@ -451,9 +453,9 @@
if (name == tabindexAttr) {
if (value.isEmpty())
clearTabIndexExplicitlyIfNeeded();
- else if (auto optionalTabIndex = parseHTMLInteger(value)) {
+ else if (Optional<int> tabIndex = parseHTMLInteger(value)) {
// Clamp tab index to a 16-bit value to match Firefox's behavior.
- setTabIndexExplicitly(std::max(-0x8000, std::min(optionalTabIndex.value(), 0x7FFF)));
+ setTabIndexExplicitly(std::max(-0x8000, std::min(tabIndex.value(), 0x7FFF)));
}
return;
}
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (197448 => 197449)
--- 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)
@@ -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 unsigned HTMLInputElement::maximumLength = 524288;
+const int HTMLInputElement::maximumLength = 524288;
const int defaultSize = 20;
const int maxSavedResults = 256;
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (197448 => 197449)
--- 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)
@@ -292,7 +292,7 @@
bool shouldUseMediaCapture() const;
#endif
- static const unsigned maximumLength;
+ static const int maximumLength;
unsigned height() const;
unsigned width() const;
Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (197448 => 197449)
--- 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)
@@ -423,10 +423,7 @@
int HTMLTextAreaElement::maxLength() const
{
- auto optionalMaxLength = parseHTMLNonNegativeInteger(fastGetAttribute(maxlengthAttr));
- if (!optionalMaxLength)
- return -1;
- return optionalMaxLength.value();
+ return parseHTMLNonNegativeInteger(fastGetAttribute(maxlengthAttr)).valueOr(-1);
}
void HTMLTextAreaElement::setMaxLength(int newValue, ExceptionCode& ec)
Modified: trunk/Source/WebCore/html/ImageInputType.cpp (197448 => 197449)
--- 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)
@@ -176,8 +176,8 @@
if (!element->renderer()) {
// Check the attribute first for an explicit pixel value.
- if (auto optionalHeight = parseHTMLNonNegativeInteger(element->fastGetAttribute(heightAttr)))
- return optionalHeight.value();
+ if (Optional<int> height = parseHTMLNonNegativeInteger(element->fastGetAttribute(heightAttr)))
+ return height.value();
// If the image is available, use its height.
HTMLImageLoader* imageLoader = element->imageLoader();
@@ -197,8 +197,8 @@
if (!element->renderer()) {
// Check the attribute first for an explicit pixel value.
- if (auto optionalWidth = parseHTMLNonNegativeInteger(element->fastGetAttribute(widthAttr)))
- return optionalWidth.value();
+ if (Optional<int> width = parseHTMLNonNegativeInteger(element->fastGetAttribute(widthAttr)))
+ return width.value();
// If the image is available, use its width.
HTMLImageLoader* imageLoader = element->imageLoader();
Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp (197448 => 197449)
--- 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)
@@ -206,13 +206,13 @@
}
// https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-non-negative-integers
-Optional<unsigned> parseHTMLNonNegativeInteger(const String& input)
+Optional<int> parseHTMLNonNegativeInteger(const String& input)
{
Optional<int> signedValue = parseHTMLInteger(input);
if (!signedValue || signedValue.value() < 0)
return Nullopt;
- return signedValue.value();
+ return signedValue;
}
static bool threadSafeEqual(const StringImpl& a, const StringImpl& b)
Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.h (197448 => 197449)
--- 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)
@@ -64,7 +64,7 @@
WEBCORE_EXPORT Optional<int> parseHTMLInteger(const String&);
// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers
-WEBCORE_EXPORT Optional<unsigned> parseHTMLNonNegativeInteger(const String&);
+WEBCORE_EXPORT Optional<int> parseHTMLNonNegativeInteger(const String&);
// https://html.spec.whatwg.org/multipage/infrastructure.html#cors-settings-attribute
String parseCORSSettingsAttribute(const AtomicString&);
@@ -121,20 +121,25 @@
inline unsigned limitToOnlyHTMLNonNegativeNumbersGreaterThanZero(const String& stringValue, unsigned defaultValue = 1)
{
+ ASSERT(defaultValue > 0);
+ ASSERT(defaultValue <= maxHTMLNonNegativeInteger);
auto optionalValue = parseHTMLNonNegativeInteger(stringValue);
unsigned value = optionalValue && optionalValue.value() ? optionalValue.value() : defaultValue;
- ASSERT(value > 0 && value <= maxHTMLNonNegativeInteger);
+ ASSERT(value > 0);
+ ASSERT(value <= maxHTMLNonNegativeInteger);
return value;
}
// https://html.spec.whatwg.org/#reflecting-content-attributes-in-idl-attributes:idl-unsigned-long
inline unsigned limitToOnlyHTMLNonNegative(unsigned value, unsigned defaultValue = 0)
{
+ ASSERT(defaultValue <= maxHTMLNonNegativeInteger);
return value <= maxHTMLNonNegativeInteger ? value : defaultValue;
}
inline unsigned limitToOnlyHTMLNonNegative(const String& stringValue, unsigned defaultValue = 0)
{
+ ASSERT(defaultValue <= maxHTMLNonNegativeInteger);
unsigned value = parseHTMLNonNegativeInteger(stringValue).valueOr(defaultValue);
ASSERT(value <= maxHTMLNonNegativeInteger);
return value;
Modified: trunk/Source/WebCore/svg/SVGElement.cpp (197448 => 197449)
--- 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)
@@ -518,9 +518,9 @@
if (name == HTMLNames::tabindexAttr) {
if (value.isEmpty())
clearTabIndexExplicitlyIfNeeded();
- else if (auto optionalTabIndex = parseHTMLInteger(value)) {
+ else if (Optional<int> tabIndex = 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(optionalTabIndex.value(), static_cast<int>(std::numeric_limits<short>::max()))));
+ setTabIndexExplicitly(std::max(static_cast<int>(std::numeric_limits<short>::min()), std::min(tabIndex.value(), static_cast<int>(std::numeric_limits<short>::max()))));
}
return;
}