Changeset 205655 in webkit


Ignore:
Timestamp:
Sep 8, 2016 12:46:10 PM (8 years ago)
Author:
Chris Dumez
Message:

HTMLImageElement.width / height attributes should be unsigned
https://bugs.webkit.org/show_bug.cgi?id=161730

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline W3C test now that more checks are passing.

  • web-platform-tests/html/dom/reflection-embedded-expected.txt:

Source/WebCore:

HTMLImageElement.width / height attributes should be unsigned as per
the HTML specification:

However, they are signed in WebKit. Firefox agrees with the
specification.

No new tests, rebaselined existing test.

  • bindings/js/JSImageConstructor.cpp:

(WebCore::JSImageConstructor::construct):
(WebCore::createImageConstructor): Deleted.

  • html/HTMLImageElement.cpp:

(WebCore::HTMLImageElement::createForJSConstructor):
(WebCore::HTMLImageElement::width):
(WebCore::HTMLImageElement::height):
(WebCore::HTMLImageElement::setHeight):
(WebCore::HTMLImageElement::setWidth):

  • html/HTMLImageElement.h:
  • html/HTMLImageElement.idl:
  • html/ImageDocument.cpp:

(WebCore::ImageDocument::restoreImageSize):

LayoutTests:

Update existing test to reflect behavior change.

  • js/dom/custom-constructors-expected.txt:
  • js/dom/script-tests/custom-constructors.js:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205653 r205655  
     12016-09-08  Chris Dumez  <cdumez@apple.com>
     2
     3        HTMLImageElement.width / height attributes should be unsigned
     4        https://bugs.webkit.org/show_bug.cgi?id=161730
     5
     6        Reviewed by Alex Christensen.
     7
     8        Update existing test to reflect behavior change.
     9
     10        * js/dom/custom-constructors-expected.txt:
     11        * js/dom/script-tests/custom-constructors.js:
     12
    1132016-09-08  Commit Queue  <commit-queue@webkit.org>
    214
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r205565 r205655  
     12016-09-08  Chris Dumez  <cdumez@apple.com>
     2
     3        HTMLImageElement.width / height attributes should be unsigned
     4        https://bugs.webkit.org/show_bug.cgi?id=161730
     5
     6        Reviewed by Alex Christensen.
     7
     8        Rebaseline W3C test now that more checks are passing.
     9
     10        * web-platform-tests/html/dom/reflection-embedded-expected.txt:
     11
    1122016-09-07  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/reflection-embedded-expected.txt

    r204090 r205655  
    11481148PASS img.width: IDL set to "-0" followed by IDL get
    11491149PASS img.width: IDL set to 2147483648 should not throw
    1150 FAIL img.width: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "0" but got "-2147483648"
    1151 FAIL img.width: IDL set to 2147483648 followed by IDL get assert_equals: expected 0 but got -2147483648
     1150PASS img.width: IDL set to 2147483648 followed by getAttribute()
     1151PASS img.width: IDL set to 2147483648 followed by IDL get
    11521152PASS img.width: IDL set to 4294967295 should not throw
    1153 FAIL img.width: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "0" but got "-1"
    1154 FAIL img.width: IDL set to 4294967295 followed by IDL get assert_equals: expected 0 but got -1
     1153PASS img.width: IDL set to 4294967295 followed by getAttribute()
     1154PASS img.width: IDL set to 4294967295 followed by IDL get
    11551155PASS img.height: typeof IDL attribute
    11561156PASS img.height: IDL get with DOM attribute unset
     
    11711171PASS img.height: IDL set to "-0" followed by IDL get
    11721172PASS img.height: IDL set to 2147483648 should not throw
    1173 FAIL img.height: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "0" but got "-2147483648"
    1174 FAIL img.height: IDL set to 2147483648 followed by IDL get assert_equals: expected 0 but got -2147483648
     1173PASS img.height: IDL set to 2147483648 followed by getAttribute()
     1174PASS img.height: IDL set to 2147483648 followed by IDL get
    11751175PASS img.height: IDL set to 4294967295 should not throw
    1176 FAIL img.height: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "0" but got "-1"
    1177 FAIL img.height: IDL set to 4294967295 followed by IDL get assert_equals: expected 0 but got -1
     1176PASS img.height: IDL set to 4294967295 followed by getAttribute()
     1177PASS img.height: IDL set to 4294967295 followed by IDL get
    11781178PASS img.name: typeof IDL attribute
    11791179PASS img.name: IDL get with DOM attribute unset
  • trunk/LayoutTests/js/dom/custom-constructors-expected.txt

    r189507 r205655  
    1010PASS new Image(100).width is 100
    1111PASS new Image(100, 200).height is 200
    12 PASS new Image(-100).width is -100
    13 PASS new Image(-100, -200).height is -200
     12PASS new Image(-100).width is 0
     13PASS new Image(-100, -200).height is 0
    1414PASS new Image().outerHTML is "<img>"
    1515PASS new Image(100, 100).outerHTML.replace(/"/g, "'") is "<img width='100' height='100'>"
  • trunk/LayoutTests/js/dom/script-tests/custom-constructors.js

    r189507 r205655  
    1111shouldBe("new Image(100).width", "100");
    1212shouldBe("new Image(100, 200).height", "200");
    13 shouldBe("new Image(-100).width", "-100");
    14 shouldBe("new Image(-100, -200).height", "-200");
     13shouldBe("new Image(-100).width", "0");
     14shouldBe("new Image(-100, -200).height", "0");
    1515
    1616shouldBeEqualToString("new Image().outerHTML","<img>");
  • trunk/LayoutTests/platform/ios-simulator/imported/w3c/web-platform-tests/html/dom/reflection-embedded-expected.txt

    r204096 r205655  
    11481148PASS img.width: IDL set to "-0" followed by IDL get
    11491149PASS img.width: IDL set to 2147483648 should not throw
    1150 FAIL img.width: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "0" but got "-2147483648"
    1151 FAIL img.width: IDL set to 2147483648 followed by IDL get assert_equals: expected 0 but got -2147483648
     1150PASS img.width: IDL set to 2147483648 followed by getAttribute()
     1151PASS img.width: IDL set to 2147483648 followed by IDL get
    11521152PASS img.width: IDL set to 4294967295 should not throw
    1153 FAIL img.width: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "0" but got "-1"
    1154 FAIL img.width: IDL set to 4294967295 followed by IDL get assert_equals: expected 0 but got -1
     1153PASS img.width: IDL set to 4294967295 followed by getAttribute()
     1154PASS img.width: IDL set to 4294967295 followed by IDL get
    11551155PASS img.height: typeof IDL attribute
    11561156PASS img.height: IDL get with DOM attribute unset
     
    11711171PASS img.height: IDL set to "-0" followed by IDL get
    11721172PASS img.height: IDL set to 2147483648 should not throw
    1173 FAIL img.height: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "0" but got "-2147483648"
    1174 FAIL img.height: IDL set to 2147483648 followed by IDL get assert_equals: expected 0 but got -2147483648
     1173PASS img.height: IDL set to 2147483648 followed by getAttribute()
     1174PASS img.height: IDL set to 2147483648 followed by IDL get
    11751175PASS img.height: IDL set to 4294967295 should not throw
    1176 FAIL img.height: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "0" but got "-1"
    1177 FAIL img.height: IDL set to 4294967295 followed by IDL get assert_equals: expected 0 but got -1
     1176PASS img.height: IDL set to 4294967295 followed by getAttribute()
     1177PASS img.height: IDL set to 4294967295 followed by IDL get
    11781178PASS img.name: typeof IDL attribute
    11791179PASS img.name: IDL get with DOM attribute unset
  • trunk/Source/WebCore/ChangeLog

    r205654 r205655  
     12016-09-08  Chris Dumez  <cdumez@apple.com>
     2
     3        HTMLImageElement.width / height attributes should be unsigned
     4        https://bugs.webkit.org/show_bug.cgi?id=161730
     5
     6        Reviewed by Alex Christensen.
     7
     8        HTMLImageElement.width / height attributes should be unsigned as per
     9        the HTML specification:
     10        - https://html.spec.whatwg.org/#htmlimageelement
     11
     12        However, they are signed in WebKit. Firefox agrees with the
     13        specification.
     14
     15        No new tests, rebaselined existing test.
     16
     17        * bindings/js/JSImageConstructor.cpp:
     18        (WebCore::JSImageConstructor::construct):
     19        (WebCore::createImageConstructor): Deleted.
     20        * html/HTMLImageElement.cpp:
     21        (WebCore::HTMLImageElement::createForJSConstructor):
     22        (WebCore::HTMLImageElement::width):
     23        (WebCore::HTMLImageElement::height):
     24        (WebCore::HTMLImageElement::setHeight):
     25        (WebCore::HTMLImageElement::setWidth):
     26        * html/HTMLImageElement.h:
     27        * html/HTMLImageElement.idl:
     28        * html/ImageDocument.cpp:
     29        (WebCore::ImageDocument::restoreImageSize):
     30
    1312016-09-08  Filip Pizlo  <fpizlo@apple.com>
    232
  • trunk/Source/WebCore/bindings/js/JSImageConstructor.cpp

    r205198 r205655  
    5959    // will be called, which will cause the image element to be marked if necessary.
    6060    toJS(state, jsConstructor->globalObject(), *document);
    61     int width;
    62     int height;
    63     int* optionalWidth = 0;
    64     int* optionalHeight = 0;
     61    Optional<unsigned> width;
     62    Optional<unsigned> height;
    6563    if (state->argumentCount() > 0) {
    66         width = state->argument(0).toInt32(state);
    67         optionalWidth = &width;
    68     }
    69     if (state->argumentCount() > 1) {
    70         height = state->argument(1).toInt32(state);
    71         optionalHeight = &height;
     64        width = state->uncheckedArgument(0).toUInt32(state);
     65        if (state->argumentCount() > 1)
     66            height = state->uncheckedArgument(1).toUInt32(state);
    7267    }
    7368
    7469    return JSValue::encode(asObject(toJS(state, jsConstructor->globalObject(),
    75         HTMLImageElement::createForJSConstructor(*document, optionalWidth, optionalHeight))));
     70        HTMLImageElement::createForJSConstructor(*document, width, height))));
    7671}
    7772
  • trunk/Source/WebCore/html/HTMLImageElement.cpp

    r203383 r205655  
    9090}
    9191
    92 Ref<HTMLImageElement> HTMLImageElement::createForJSConstructor(Document& document, const int* optionalWidth, const int* optionalHeight)
    93 {
    94     Ref<HTMLImageElement> image = adoptRef(*new HTMLImageElement(imgTag, document));
    95     if (optionalWidth)
    96         image->setWidth(*optionalWidth);
    97     if (optionalHeight)
    98         image->setHeight(*optionalHeight);
     92Ref<HTMLImageElement> HTMLImageElement::createForJSConstructor(Document& document, Optional<unsigned> width, Optional<unsigned> height)
     93{
     94    auto image = adoptRef(*new HTMLImageElement(imgTag, document));
     95    if (width)
     96        image->setWidth(width.value());
     97    if (height)
     98        image->setHeight(height.value());
    9999    return image;
    100100}
     
    377377}
    378378   
    379 int HTMLImageElement::width(bool ignorePendingStylesheets)
     379unsigned HTMLImageElement::width(bool ignorePendingStylesheets)
    380380{
    381381    if (!renderer()) {
    382382        // check the attribute first for an explicit pixel value
    383         bool ok;
    384         int width = attributeWithoutSynchronization(widthAttr).toInt(&ok);
    385         if (ok)
    386             return width;
     383        Optional<int> width = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(widthAttr));
     384        if (width)
     385            return width.value();
    387386
    388387        // if the image is available, use its width
    389388        if (m_imageLoader.image())
    390             return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f).width();
     389            return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f).width().toUnsigned();
    391390    }
    392391
     
    403402}
    404403
    405 int HTMLImageElement::height(bool ignorePendingStylesheets)
     404unsigned HTMLImageElement::height(bool ignorePendingStylesheets)
    406405{
    407406    if (!renderer()) {
    408407        // check the attribute first for an explicit pixel value
    409         bool ok;
    410         int height = attributeWithoutSynchronization(heightAttr).toInt(&ok);
    411         if (ok)
    412             return height;
     408        Optional<int> height = parseHTMLNonNegativeInteger(attributeWithoutSynchronization(heightAttr));
     409        if (height)
     410            return height.value();
    413411
    414412        // if the image is available, use its height
    415413        if (m_imageLoader.image())
    416             return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f).height();
     414            return m_imageLoader.image()->imageSizeForRenderer(renderer(), 1.0f).height().toUnsigned();
    417415    }
    418416
     
    502500}
    503501
    504 void HTMLImageElement::setHeight(int value)
    505 {
    506     setIntegralAttribute(heightAttr, value);
     502void HTMLImageElement::setHeight(unsigned value)
     503{
     504    setUnsignedIntegralAttribute(heightAttr, value);
    507505}
    508506
     
    517515}
    518516
    519 void HTMLImageElement::setWidth(int value)
    520 {
    521     setIntegralAttribute(widthAttr, value);
     517void HTMLImageElement::setWidth(unsigned value)
     518{
     519    setUnsignedIntegralAttribute(widthAttr, value);
    522520}
    523521
  • trunk/Source/WebCore/html/HTMLImageElement.h

    r204717 r205655  
    4040    static Ref<HTMLImageElement> create(Document&);
    4141    static Ref<HTMLImageElement> create(const QualifiedName&, Document&, HTMLFormElement*);
    42     static Ref<HTMLImageElement> createForJSConstructor(Document&, const int* optionalWidth, const int* optionalHeight);
     42    static Ref<HTMLImageElement> createForJSConstructor(Document&, Optional<unsigned> width, Optional<unsigned> height);
    4343
    4444    virtual ~HTMLImageElement();
    4545
    46     WEBCORE_EXPORT int width(bool ignorePendingStylesheets = false);
    47     WEBCORE_EXPORT int height(bool ignorePendingStylesheets = false);
     46    WEBCORE_EXPORT unsigned width(bool ignorePendingStylesheets = false);
     47    WEBCORE_EXPORT unsigned height(bool ignorePendingStylesheets = false);
    4848
    4949    WEBCORE_EXPORT int naturalWidth() const;
     
    6565    WEBCORE_EXPORT const AtomicString& alt() const;
    6666
    67     WEBCORE_EXPORT void setHeight(int);
     67    WEBCORE_EXPORT void setHeight(unsigned);
    6868
    6969    URL src() const;
     
    7373    WEBCORE_EXPORT String crossOrigin() const;
    7474
    75     WEBCORE_EXPORT void setWidth(int);
     75    WEBCORE_EXPORT void setWidth(unsigned);
    7676
    7777    WEBCORE_EXPORT int x() const;
  • trunk/Source/WebCore/html/HTMLImageElement.idl

    r204259 r205655  
    2828    [Reflect, TreatNullAs=EmptyString] attribute DOMString border;
    2929    attribute DOMString? crossOrigin;
    30     attribute long height;
     30    attribute unsigned long height;
    3131    [Reflect] attribute long hspace;
    3232    [Reflect] attribute boolean isMap;
     
    3838    [Reflect] attribute DOMString useMap;
    3939    [Reflect] attribute long vspace;
    40     attribute long width;
     40    attribute unsigned long width;
    4141
    4242    // Extensions
  • trunk/Source/WebCore/html/ImageDocument.cpp

    r205106 r205655  
    314314
    315315    LayoutSize imageSize = this->imageSize();
    316     m_imageElement->setWidth(imageSize.width());
    317     m_imageElement->setHeight(imageSize.height());
     316    m_imageElement->setWidth(imageSize.width().toUnsigned());
     317    m_imageElement->setHeight(imageSize.height().toUnsigned());
    318318
    319319    if (imageFitsInWindow())
Note: See TracChangeset for help on using the changeset viewer.