Changeset 196769 in webkit


Ignore:
Timestamp:
Feb 18, 2016 12:14:13 PM (8 years ago)
Author:
Chris Dumez
Message:

Fix behavior of reflecting unsigned long IDL attributes that are limited to only non-negative numbers greater than zero
https://bugs.webkit.org/show_bug.cgi?id=154398

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline now that more checks are passing.

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

Source/WebCore:

Fix behavior of reflecting unsigned long IDL attributes that are limited
to only non-negative numbers greater than zero to comply with:

This patch updates the following IDL attributes:

  • colgroup.span
  • col.span
  • input.size
  • textarea.cols
  • textareal.rows

All of them now:

  • Have "unsigned long" type on IDL size and "unsigned" type on native side.
  • On getting, return the value if it is in the range [1; 2147483647], otherwise return the default value.
  • On setting, set to the input value if it is in the range [1; 2147483647], otherwise, set to the default value.

Note that as per the specification, we are supposed to throw an
IndexSizeError exception when trying to set those attributes to zero.
However, we instead use the default value to match other browsers.
It would be risky to be the only browser to throw in this case.

No new tests, already covered by existing test.

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::parseAttribute):
(WebCore::HTMLInputElement::setSize):

  • html/HTMLTableColElement.cpp:

(WebCore::HTMLTableColElement::parseAttribute):
(WebCore::HTMLTableColElement::setSpan):

  • html/HTMLTableColElement.h:
  • html/HTMLTableColElement.idl:
  • html/HTMLTextAreaElement.cpp:

(WebCore::HTMLTextAreaElement::parseAttribute):
(WebCore::HTMLTextAreaElement::setCols):
(WebCore::HTMLTextAreaElement::setRows):
(WebCore::HTMLTextAreaElement::shouldUseInputMethod): Deleted.

  • html/HTMLTextAreaElement.h:
  • html/HTMLTextAreaElement.idl:
  • html/parser/HTMLParserIdioms.h:

(WebCore::limitToOnlyNonNegativeNumbersGreaterThanZero):

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r196742 r196769  
     12016-02-18  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix behavior of reflecting unsigned long IDL attributes that are limited to only non-negative numbers greater than zero
     4        https://bugs.webkit.org/show_bug.cgi?id=154398
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Rebaseline now that more checks are passing.
     9
     10        * web-platform-tests/html/dom/reflection-forms-expected.txt:
     11        * web-platform-tests/html/dom/reflection-tabular-expected.txt:
     12
    1132016-02-17  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/reflection-forms-expected.txt

    r196710 r196769  
    69606960PASS input.size: IDL set to 2147483647 followed by IDL get
    69616961PASS input.size: IDL set to 2147483648 should not throw
    6962 FAIL input.size: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "20" but got "2147483648"
     6962PASS input.size: IDL set to 2147483648 followed by getAttribute()
    69636963PASS input.size: IDL set to 2147483648 followed by IDL get
    69646964PASS input.size: IDL set to 4294967295 should not throw
    6965 FAIL input.size: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "20" but got "4294967295"
     6965PASS input.size: IDL set to 4294967295 followed by getAttribute()
    69666966PASS input.size: IDL set to 4294967295 followed by IDL get
    69676967PASS input.src: typeof IDL attribute
     
    1464314643PASS textarea.cols: IDL set to 2147483647 followed by IDL get
    1464414644PASS textarea.cols: IDL set to 2147483648 should not throw
    14645 FAIL textarea.cols: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "20" but got "-2147483648"
     14645PASS textarea.cols: IDL set to 2147483648 followed by getAttribute()
    1464614646PASS textarea.cols: IDL set to 2147483648 followed by IDL get
    1464714647PASS textarea.cols: IDL set to 4294967295 should not throw
    14648 FAIL textarea.cols: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "20" but got "-1"
     14648PASS textarea.cols: IDL set to 4294967295 followed by getAttribute()
    1464914649PASS textarea.cols: IDL set to 4294967295 followed by IDL get
    1465014650PASS textarea.dirName: typeof IDL attribute
     
    1571015710PASS textarea.rows: IDL set to 2147483647 followed by IDL get
    1571115711PASS textarea.rows: IDL set to 2147483648 should not throw
    15712 FAIL textarea.rows: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "2" but got "-2147483648"
     15712PASS textarea.rows: IDL set to 2147483648 followed by getAttribute()
    1571315713PASS textarea.rows: IDL set to 2147483648 followed by IDL get
    1571415714PASS textarea.rows: IDL set to 4294967295 should not throw
    15715 FAIL textarea.rows: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "2" but got "-1"
     15715PASS textarea.rows: IDL set to 4294967295 followed by getAttribute()
    1571615716PASS textarea.rows: IDL set to 4294967295 followed by IDL get
    1571715717PASS textarea.wrap: typeof IDL attribute
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/reflection-tabular-expected.txt

    r196710 r196769  
    29752975PASS colgroup.span: setAttribute() to -2147483649 followed by IDL get
    29762976PASS colgroup.span: setAttribute() to -2147483648 followed by getAttribute()
    2977 FAIL colgroup.span: setAttribute() to -2147483648 followed by IDL get assert_equals: expected 1 but got -2147483648
     2977PASS colgroup.span: setAttribute() to -2147483648 followed by IDL get
    29782978PASS colgroup.span: setAttribute() to -36 followed by getAttribute()
    2979 FAIL colgroup.span: setAttribute() to -36 followed by IDL get assert_equals: expected 1 but got -36
     2979PASS colgroup.span: setAttribute() to -36 followed by IDL get
    29802980PASS colgroup.span: setAttribute() to -1 followed by getAttribute()
    2981 FAIL colgroup.span: setAttribute() to -1 followed by IDL get assert_equals: expected 1 but got -1
     2981PASS colgroup.span: setAttribute() to -1 followed by IDL get
    29822982PASS colgroup.span: setAttribute() to 0 followed by getAttribute()
    29832983PASS colgroup.span: setAttribute() to 0 followed by IDL get
     
    29952995PASS colgroup.span: setAttribute() to "" followed by IDL get
    29962996PASS colgroup.span: setAttribute() to "-1" followed by getAttribute()
    2997 FAIL colgroup.span: setAttribute() to "-1" followed by IDL get assert_equals: expected 1 but got -1
     2997PASS colgroup.span: setAttribute() to "-1" followed by IDL get
    29982998PASS colgroup.span: setAttribute() to "-0" followed by getAttribute()
    29992999PASS colgroup.span: setAttribute() to "-0" followed by IDL get
     
    30893089PASS colgroup.span: IDL set to 2147483647 followed by IDL get
    30903090PASS colgroup.span: IDL set to 2147483648 should not throw
    3091 FAIL colgroup.span: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "1" but got "-2147483648"
    3092 FAIL colgroup.span: IDL set to 2147483648 followed by IDL get assert_equals: expected 1 but got -2147483648
     3091PASS colgroup.span: IDL set to 2147483648 followed by getAttribute()
     3092PASS colgroup.span: IDL set to 2147483648 followed by IDL get
    30933093PASS colgroup.span: IDL set to 4294967295 should not throw
    3094 FAIL colgroup.span: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "1" but got "-1"
    3095 FAIL colgroup.span: IDL set to 4294967295 followed by IDL get assert_equals: expected 1 but got -1
     3094PASS colgroup.span: IDL set to 4294967295 followed by getAttribute()
     3095PASS colgroup.span: IDL set to 4294967295 followed by IDL get
    30963096PASS colgroup.align: typeof IDL attribute
    30973097PASS colgroup.align: IDL get with DOM attribute unset
     
    42464246PASS col.span: setAttribute() to -2147483649 followed by IDL get
    42474247PASS col.span: setAttribute() to -2147483648 followed by getAttribute()
    4248 FAIL col.span: setAttribute() to -2147483648 followed by IDL get assert_equals: expected 1 but got -2147483648
     4248PASS col.span: setAttribute() to -2147483648 followed by IDL get
    42494249PASS col.span: setAttribute() to -36 followed by getAttribute()
    4250 FAIL col.span: setAttribute() to -36 followed by IDL get assert_equals: expected 1 but got -36
     4250PASS col.span: setAttribute() to -36 followed by IDL get
    42514251PASS col.span: setAttribute() to -1 followed by getAttribute()
    4252 FAIL col.span: setAttribute() to -1 followed by IDL get assert_equals: expected 1 but got -1
     4252PASS col.span: setAttribute() to -1 followed by IDL get
    42534253PASS col.span: setAttribute() to 0 followed by getAttribute()
    42544254PASS col.span: setAttribute() to 0 followed by IDL get
     
    42664266PASS col.span: setAttribute() to "" followed by IDL get
    42674267PASS col.span: setAttribute() to "-1" followed by getAttribute()
    4268 FAIL col.span: setAttribute() to "-1" followed by IDL get assert_equals: expected 1 but got -1
     4268PASS col.span: setAttribute() to "-1" followed by IDL get
    42694269PASS col.span: setAttribute() to "-0" followed by getAttribute()
    42704270PASS col.span: setAttribute() to "-0" followed by IDL get
     
    43604360PASS col.span: IDL set to 2147483647 followed by IDL get
    43614361PASS col.span: IDL set to 2147483648 should not throw
    4362 FAIL col.span: IDL set to 2147483648 followed by getAttribute() assert_equals: expected "1" but got "-2147483648"
    4363 FAIL col.span: IDL set to 2147483648 followed by IDL get assert_equals: expected 1 but got -2147483648
     4362PASS col.span: IDL set to 2147483648 followed by getAttribute()
     4363PASS col.span: IDL set to 2147483648 followed by IDL get
    43644364PASS col.span: IDL set to 4294967295 should not throw
    4365 FAIL col.span: IDL set to 4294967295 followed by getAttribute() assert_equals: expected "1" but got "-1"
    4366 FAIL col.span: IDL set to 4294967295 followed by IDL get assert_equals: expected 1 but got -1
     4365PASS col.span: IDL set to 4294967295 followed by getAttribute()
     4366PASS col.span: IDL set to 4294967295 followed by IDL get
    43674367PASS col.align: typeof IDL attribute
    43684368PASS col.align: IDL get with DOM attribute unset
  • trunk/Source/WebCore/ChangeLog

    r196763 r196769  
     12016-02-18  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix behavior of reflecting unsigned long IDL attributes that are limited to only non-negative numbers greater than zero
     4        https://bugs.webkit.org/show_bug.cgi?id=154398
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Fix behavior of reflecting unsigned long IDL attributes that are limited
     9        to only non-negative numbers greater than zero to comply with:
     10        - https://html.spec.whatwg.org/#limited-to-only-non-negative-numbers-greater-than-zero
     11
     12        This patch updates the following IDL attributes:
     13        - colgroup.span
     14        - col.span
     15        - input.size
     16        - textarea.cols
     17        - textareal.rows
     18
     19        All of them now:
     20        - Have "unsigned long" type on IDL size and "unsigned" type on native
     21          side.
     22        - On getting, return the value if it is in the range [1; 2147483647],
     23          otherwise return the default value.
     24        - On setting, set to the input value if it is in the range
     25          [1; 2147483647], otherwise, set to the default value.
     26
     27        Note that as per the specification, we are supposed to throw an
     28        IndexSizeError exception when trying to set those attributes to zero.
     29        However, we instead use the default value to match other browsers.
     30        It would be risky to be the only browser to throw in this case.
     31
     32        No new tests, already covered by existing test.
     33
     34        * html/HTMLInputElement.cpp:
     35        (WebCore::HTMLInputElement::parseAttribute):
     36        (WebCore::HTMLInputElement::setSize):
     37        * html/HTMLTableColElement.cpp:
     38        (WebCore::HTMLTableColElement::parseAttribute):
     39        (WebCore::HTMLTableColElement::setSpan):
     40        * html/HTMLTableColElement.h:
     41        * html/HTMLTableColElement.idl:
     42        * html/HTMLTextAreaElement.cpp:
     43        (WebCore::HTMLTextAreaElement::parseAttribute):
     44        (WebCore::HTMLTextAreaElement::setCols):
     45        (WebCore::HTMLTextAreaElement::setRows):
     46        (WebCore::HTMLTextAreaElement::shouldUseInputMethod): Deleted.
     47        * html/HTMLTextAreaElement.h:
     48        * html/HTMLTextAreaElement.idl:
     49        * html/parser/HTMLParserIdioms.h:
     50        (WebCore::limitToOnlyNonNegativeNumbersGreaterThanZero):
     51
    1522016-02-18  David Kilzer  <ddkilzer@apple.com>
    253
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r196080 r196769  
    686686    else if (name == sizeAttr) {
    687687        int oldSize = m_size;
    688         int valueAsInteger = value.toInt();
    689         m_size = valueAsInteger > 0 ? valueAsInteger : defaultSize;
     688        m_size = limitToOnlyNonNegativeNumbersGreaterThanZero(value.string().toUInt(), defaultSize);
    690689        if (m_size != oldSize && renderer())
    691690            renderer()->setNeedsLayoutAndPrefWidthsRecalc();
     
    12761275void HTMLInputElement::setSize(unsigned size)
    12771276{
    1278     setUnsignedIntegralAttribute(sizeAttr, size);
     1277    setUnsignedIntegralAttribute(sizeAttr, limitToOnlyNonNegativeNumbersGreaterThanZero(size, defaultSize));
    12791278}
    12801279
  • trunk/Source/WebCore/html/HTMLTableColElement.cpp

    r182120 r196769  
    2828#include "CSSPropertyNames.h"
    2929#include "HTMLNames.h"
     30#include "HTMLParserIdioms.h"
    3031#include "HTMLTableElement.h"
    3132#include "RenderTableCol.h"
     
    6566{
    6667    if (name == spanAttr) {
    67         int newSpan = value.toInt();
    68         m_span = newSpan ? newSpan : 1;
     68        m_span = limitToOnlyNonNegativeNumbersGreaterThanZero(value.string().toUInt());
    6969        if (is<RenderTableCol>(renderer()))
    7070            downcast<RenderTableCol>(*renderer()).updateFromElement();
     
    9191}
    9292
    93 void HTMLTableColElement::setSpan(int n)
     93void HTMLTableColElement::setSpan(unsigned n)
    9494{
    95     setIntegralAttribute(spanAttr, n);
     95    setUnsignedIntegralAttribute(spanAttr, limitToOnlyNonNegativeNumbersGreaterThanZero(n));
    9696}
    9797
  • trunk/Source/WebCore/html/HTMLTableColElement.h

    r177996 r196769  
    3535    static Ref<HTMLTableColElement> create(const QualifiedName& tagName, Document&);
    3636
    37     int span() const { return m_span; }
    38     void setSpan(int);
     37    unsigned span() const { return m_span; }
     38    void setSpan(unsigned);
    3939
    4040    String width() const;
     
    4848    virtual const StyleProperties* additionalPresentationAttributeStyle() override;
    4949
    50     int m_span;
     50    unsigned m_span;
    5151};
    5252
  • trunk/Source/WebCore/html/HTMLTableColElement.idl

    r131172 r196769  
    2323    [Reflect=char] attribute DOMString ch;
    2424    [Reflect=charoff] attribute DOMString chOff;
     25#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
     26    attribute unsigned long span;
     27#else
    2528    attribute long span;
     29#endif
    2630    [Reflect] attribute DOMString vAlign;
    2731    [Reflect] attribute DOMString width;
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r195452 r196769  
    4141#include "FrameSelection.h"
    4242#include "HTMLNames.h"
     43#include "HTMLParserIdioms.h"
    4344#include "LocalizedStrings.h"
    4445#include "RenderTextControlMultiLine.h"
     
    170171{
    171172    if (name == rowsAttr) {
    172         int rows = value.toInt();
    173         if (rows <= 0)
    174             rows = defaultRows;
     173        unsigned rows = limitToOnlyNonNegativeNumbersGreaterThanZero(value.string().toUInt(), defaultRows);
    175174        if (m_rows != rows) {
    176175            m_rows = rows;
     
    179178        }
    180179    } else if (name == colsAttr) {
    181         int cols = value.toInt();
    182         if (cols <= 0)
    183             cols = defaultCols;
     180        unsigned cols = limitToOnlyNonNegativeNumbersGreaterThanZero(value.string().toUInt(), defaultCols);
    184181        if (m_cols != cols) {
    185182            m_cols = cols;
     
    493490}
    494491
    495 void HTMLTextAreaElement::setCols(int cols)
    496 {
    497     setIntegralAttribute(colsAttr, cols);
    498 }
    499 
    500 void HTMLTextAreaElement::setRows(int rows)
    501 {
    502     setIntegralAttribute(rowsAttr, rows);
     492void HTMLTextAreaElement::setCols(unsigned cols)
     493{
     494    setUnsignedIntegralAttribute(colsAttr, limitToOnlyNonNegativeNumbersGreaterThanZero(cols, defaultCols));
     495}
     496
     497void HTMLTextAreaElement::setRows(unsigned rows)
     498{
     499    setUnsignedIntegralAttribute(rowsAttr, limitToOnlyNonNegativeNumbersGreaterThanZero(rows, defaultRows));
    503500}
    504501
  • trunk/Source/WebCore/html/HTMLTextAreaElement.h

    r191451 r196769  
    3636    static Ref<HTMLTextAreaElement> create(const QualifiedName&, Document&, HTMLFormElement*);
    3737
    38     int cols() const { return m_cols; }
    39     int rows() const { return m_rows; }
     38    unsigned cols() const { return m_cols; }
     39    unsigned rows() const { return m_rows; }
    4040
    4141    bool shouldWrapText() const { return m_wrap != NoWrap; }
     
    5858    void rendererWillBeDestroyed();
    5959
    60     void setCols(int);
    61     void setRows(int);
     60    void setCols(unsigned);
     61    void setRows(unsigned);
    6262
    6363    virtual bool willRespondToMouseClickEvents() override;
     
    119119    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
    120120
    121     int m_rows;
    122     int m_cols;
     121    unsigned m_rows;
     122    unsigned m_cols;
    123123    WrapMethod m_wrap;
    124124    HTMLElement* m_placeholder;
  • trunk/Source/WebCore/html/HTMLTextAreaElement.idl

    r195700 r196769  
    2222interface HTMLTextAreaElement : HTMLElement {
    2323    [Reflect] attribute boolean autofocus;
    24     attribute long cols;
    2524    [Reflect] attribute DOMString dirName;
    2625    [Reflect] attribute boolean disabled;
     
    3130    [Reflect] attribute boolean readOnly;
    3231    [Reflect] attribute boolean required;
     32#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
    3333    attribute long rows;
     34    attribute long cols;
     35#else
     36    attribute unsigned long rows;
     37    attribute unsigned long cols;
     38#endif
    3439    [Reflect] attribute DOMString wrap;
    3540
  • trunk/Source/WebCore/html/parser/HTMLParserIdioms.h

    r195951 r196769  
    107107}
    108108
     109// https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-non-negative-numbers-greater-than-zero
     110inline unsigned limitToOnlyNonNegativeNumbersGreaterThanZero(unsigned value, unsigned defaultValue = 1)
     111{
     112    return (value > 0 && value <= 2147483647) ? value : defaultValue;
     113}
     114
    109115}
    110116
Note: See TracChangeset for help on using the changeset viewer.