Changeset 205663 in webkit


Ignore:
Timestamp:
Sep 8, 2016 2:31:54 PM (8 years ago)
Author:
Chris Dumez
Message:

Update parseHTMLNonNegativeInteger() to return an unsigned value
https://bugs.webkit.org/show_bug.cgi?id=161759

Reviewed by Alex Christensen.

Update parseHTMLNonNegativeInteger() to return an unsigned value instead
of a signed one as the value can never be negative.

  • html/HTMLElement.cpp:

(WebCore::HTMLElement::parseBorderWidthAttribute):

  • html/HTMLImageElement.cpp:

(WebCore::HTMLImageElement::width):
(WebCore::HTMLImageElement::height):

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::maxLengthAttributeChanged):
(WebCore::HTMLInputElement::minLengthAttributeChanged):

  • html/HTMLTextAreaElement.cpp:

(WebCore::HTMLTextAreaElement::maxLengthAttributeChanged):
(WebCore::HTMLTextAreaElement::minLengthAttributeChanged):

  • html/ImageInputType.cpp:

(WebCore::ImageInputType::height):
(WebCore::ImageInputType::width):

  • html/parser/HTMLParserIdioms.cpp:

(WebCore::parseHTMLNonNegativeInteger):
(WebCore::parseHTTPRefreshInternal):

  • html/parser/HTMLParserIdioms.h:
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r205661 r205663  
     12016-09-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Update parseHTMLNonNegativeInteger() to return an unsigned value
     4        https://bugs.webkit.org/show_bug.cgi?id=161759
     5
     6        Reviewed by Alex Christensen.
     7
     8        Update parseHTMLNonNegativeInteger() to return an unsigned value instead
     9        of a signed one as the value can never be negative.
     10
     11        * html/HTMLElement.cpp:
     12        (WebCore::HTMLElement::parseBorderWidthAttribute):
     13        * html/HTMLImageElement.cpp:
     14        (WebCore::HTMLImageElement::width):
     15        (WebCore::HTMLImageElement::height):
     16        * html/HTMLInputElement.cpp:
     17        (WebCore::HTMLInputElement::maxLengthAttributeChanged):
     18        (WebCore::HTMLInputElement::minLengthAttributeChanged):
     19        * html/HTMLTextAreaElement.cpp:
     20        (WebCore::HTMLTextAreaElement::maxLengthAttributeChanged):
     21        (WebCore::HTMLTextAreaElement::minLengthAttributeChanged):
     22        * html/ImageInputType.cpp:
     23        (WebCore::ImageInputType::height):
     24        (WebCore::ImageInputType::width):
     25        * html/parser/HTMLParserIdioms.cpp:
     26        (WebCore::parseHTMLNonNegativeInteger):
     27        (WebCore::parseHTTPRefreshInternal):
     28        * html/parser/HTMLParserIdioms.h:
     29
    1302016-09-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
    231
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r205468 r205663  
    103103unsigned HTMLElement::parseBorderWidthAttribute(const AtomicString& value) const
    104104{
    105     if (Optional<int> borderWidth = parseHTMLNonNegativeInteger(value))
     105    if (Optional<unsigned> borderWidth = parseHTMLNonNegativeInteger(value))
    106106        return borderWidth.value();
    107107
  • trunk/Source/WebCore/html/HTMLImageElement.cpp

    r205655 r205663  
    381381    if (!renderer()) {
    382382        // check the attribute first for an explicit pixel value
    383         Optional<int> width = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(widthAttr));
     383        Optional<unsigned> width = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(widthAttr));
    384384        if (width)
    385385            return width.value();
     
    406406    if (!renderer()) {
    407407        // check the attribute first for an explicit pixel value
    408         Optional<int> height = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(heightAttr));
     408        Optional<unsigned> height = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(heightAttr));
    409409        if (height)
    410410            return height.value();
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r205524 r205663  
    17861786{
    17871787    unsigned oldEffectiveMaxLength = effectiveMaxLength();
    1788     setMaxLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
     1788    if (Optional<unsigned> maxLength = parseHTMLNonNegativeInteger(newValue))
     1789        setMaxLength(maxLength.value());
     1790    else
     1791        setMaxLength(-1);
     1792
    17891793    if (oldEffectiveMaxLength != effectiveMaxLength())
    17901794        updateValueIfNeeded();
     
    17981802{
    17991803    int oldMinLength = minLength();
    1800     setMinLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
     1804    if (Optional<unsigned> minLength = parseHTMLNonNegativeInteger(newValue))
     1805        setMinLength(minLength.value());
     1806    else
     1807        setMinLength(-1);
     1808
    18011809    if (oldMinLength != minLength())
    18021810        updateValueIfNeeded();
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r205524 r205663  
    206206void HTMLTextAreaElement::maxLengthAttributeChanged(const AtomicString& newValue)
    207207{
    208     setMaxLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
     208    if (Optional<unsigned> maxLength = parseHTMLNonNegativeInteger(newValue))
     209        setMaxLength(maxLength.value());
     210    else
     211        setMaxLength(-1);
     212
    209213    updateValidity();
    210214}
     
    212216void HTMLTextAreaElement::minLengthAttributeChanged(const AtomicString& newValue)
    213217{
    214     setMinLength(parseHTMLNonNegativeInteger(newValue).valueOr(-1));
     218    if (Optional<unsigned> minLength = parseHTMLNonNegativeInteger(newValue))
     219        setMinLength(minLength.value());
     220    else
     221        setMinLength(-1);
     222
    215223    updateValidity();
    216224}
  • trunk/Source/WebCore/html/ImageInputType.cpp

    r205249 r205663  
    177177    if (!element->renderer()) {
    178178        // Check the attribute first for an explicit pixel value.
    179         if (Optional<int> height = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(heightAttr)))
     179        if (Optional<unsigned> height = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(heightAttr)))
    180180            return height.value();
    181181
     
    198198    if (!element->renderer()) {
    199199        // Check the attribute first for an explicit pixel value.
    200         if (Optional<int> width = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(widthAttr)))
     200        if (Optional<unsigned> width = parseHTMLNonNegativeInteger(element->attributeWithoutSynchronization(widthAttr)))
    201201            return width.value();
    202202
  • trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp

    r205515 r205663  
    208208
    209209// https://html.spec.whatwg.org/multipage/infrastructure.html#rules-for-parsing-non-negative-integers
    210 Optional<int> parseHTMLNonNegativeInteger(const String& input)
     210Optional<unsigned> parseHTMLNonNegativeInteger(const String& input)
    211211{
    212212    Optional<int> signedValue = parseHTMLInteger(input);
     
    214214        return Nullopt;
    215215
    216     return signedValue;
     216    return static_cast<unsigned>(signedValue.value());
    217217}
    218218
     
    364364        ++position;
    365365
    366     Optional<int> number = parseHTMLNonNegativeInteger(StringView(numberStart, position - numberStart).toStringWithoutCopying());
     366    Optional<unsigned> number = parseHTMLNonNegativeInteger(StringView(numberStart, position - numberStart).toStringWithoutCopying());
    367367    if (!number)
    368368        return false;
  • trunk/Source/WebCore/html/parser/HTMLParserIdioms.h

    r205515 r205663  
    6666
    6767// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers
    68 WEBCORE_EXPORT Optional<int> parseHTMLNonNegativeInteger(const String&);
     68WEBCORE_EXPORT Optional<unsigned> parseHTMLNonNegativeInteger(const String&);
    6969
    7070// https://html.spec.whatwg.org/#valid-non-negative-integer
Note: See TracChangeset for help on using the changeset viewer.