Changeset 178097 in webkit


Ignore:
Timestamp:
Jan 7, 2015 8:55:45 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

HTMLSelectElement and HTMLOptionsCollection add() method should support index as second argument.
https://bugs.webkit.org/show_bug.cgi?id=139179

Patch by Shivakumar JM <shiva.jm@samsung.com> on 2015-01-07
Reviewed by Darin Adler.

Source/WebCore:

HTMLSelectElement and HTMLOptionsCollection add() method should support index as second argument as per specification
http://www.w3.org/html/wg/drafts/html/master/forms.html#the-select-element.
Also this matches the behavior of Chrome and FireFox.

Tests: fast/dom/HTMLSelectElement/add.html

fast/dom/HTMLSelectElement/options-collection-add.html

  • bindings/js/JSHTMLOptionsCollectionCustom.cpp:

(WebCore::JSHTMLOptionsCollection::add): Deleted.

  • html/HTMLOptionsCollection.cpp:

(WebCore::HTMLOptionsCollection::add):

  • html/HTMLOptionsCollection.h:
  • html/HTMLOptionsCollection.idl:
  • html/HTMLSelectElement.cpp:

(WebCore::HTMLSelectElement::add):

  • html/HTMLSelectElement.h:
  • html/HTMLSelectElement.idl:

LayoutTests:

  • fast/dom/HTMLSelectElement/add-expected.txt: Added.
  • fast/dom/HTMLSelectElement/add.html: Added.
  • fast/dom/HTMLSelectElement/options-collection-add-expected.txt: Added.
  • fast/dom/HTMLSelectElement/options-collection-add.html: Added.
  • fast/dom/HTMLSelectElement/select-add-optgroup-expected.txt:
  • fast/dom/HTMLSelectElement/select-add-optgroup.html:
  • fast/dom/incompatible-operations-expected.txt:
  • fast/dom/incompatible-operations.html:
  • js/dom/script-tests/select-options-add.js:
  • js/dom/select-options-add-expected.txt:
Location:
trunk
Files:
4 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r178078 r178097  
     12015-01-07  Shivakumar JM  <shiva.jm@samsung.com>
     2
     3        HTMLSelectElement and HTMLOptionsCollection add() method should support index as second argument.
     4        https://bugs.webkit.org/show_bug.cgi?id=139179
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/dom/HTMLSelectElement/add-expected.txt: Added.
     9        * fast/dom/HTMLSelectElement/add.html: Added.
     10        * fast/dom/HTMLSelectElement/options-collection-add-expected.txt: Added.
     11        * fast/dom/HTMLSelectElement/options-collection-add.html: Added.
     12        * fast/dom/HTMLSelectElement/select-add-optgroup-expected.txt:
     13        * fast/dom/HTMLSelectElement/select-add-optgroup.html:
     14        * fast/dom/incompatible-operations-expected.txt:
     15        * fast/dom/incompatible-operations.html:
     16        * js/dom/script-tests/select-options-add.js:
     17        * js/dom/select-options-add-expected.txt:
     18
    1192015-01-07  Said Abou-Hallawa  <sabouhallawa@apple.com>
    220
  • trunk/LayoutTests/fast/dom/HTMLSelectElement/select-add-optgroup-expected.txt

    r177629 r178097  
    44
    55
    6 PASS deepCopy() is "0,1,2,Y1"
    7 PASS deepCopy() is "0,1,2,Y2,Y1"
    8 PASS deepCopy() is "0,1,2,Y3,Y2,Y1"
    9 PASS deepCopy() is "0,1,2,Y4,Y3,Y2,Y1"
    10 PASS deepCopy() is "0,1,2,X,Y"
    11 PASS deepCopy() is "0,1,X,Y,2"
    12 PASS deepCopy() is "0,1,X,Y,X,Y,2"
    13 PASS deepCopy() is "0,1,2,Y"
    14 PASS deepCopy() is "0,1,2,Y"
    15 PASS deepCopy() is "0,1,2,Y"
    16 PASS deepCopy() is "0,1,2,Y"
    17 PASS deepCopy() is "0,1,2,Y"
    18 PASS deepCopy() is "0,1,2,Y"
    19 PASS deepCopy() is "0,1,2,Y"
    20 PASS deepCopy() is "0,1,2,Y"
    21 PASS deepCopy() is "0,1,2,Y"
    22 PASS deepCopy() is "0,1,2,Y"
    23 PASS deepCopy() is "0,1,2,Y"
    24 PASS deepCopy() is "0,1,2,Y"
    25 PASS deepCopy() is "0,1,2,Y"
    26 PASS deepCopy() is "0,1,2,Y"
    27 PASS deepCopy() is "0,1,2,Y"
    28 PASS deepCopy() is "0,1,2,Y"
    29 PASS deepCopy() is "0,1,2,Y"
    30 PASS deepCopy() is "0,1,2,Y"
    31 PASS deepCopy() is "0,1,2,Y"
    32 PASS deepCopy() is "0,1,2,Y"
    33 PASS deepCopy() is "0,1,2,Y"
    34 PASS deepCopy() is "0,1,2,Y"
    35 PASS mySelect.add("foo") is undefined.
    36 PASS mySelect.add("foo", 0) is undefined.
    37 PASS mySelect.add(undefined) is undefined.
    38 PASS mySelect.add(undefined, 0) is undefined.
    39 PASS mySelect.add(null) is undefined.
    40 PASS mySelect.add(null, 0) is undefined.
     6list elements are = 0,1,2
     7PASS testAdd3(createGroup("Y1", "Y2"), null) is "0,1,2,Y1,Y2"
     8PASS testAdd3(createGroup("Y3", "Y4"), 0) is "Y3,Y4,0,1,2"
     9PASS testAdd3(createGroup("Y5", "Y6"), 2) is "0,1,Y5,Y6,2"
     10PASS testAdd1(createGroup("Y7", "Y8")) is "0,1,2,Y7,Y8"
     11PASS testAdd1(createOption("Y9")) is "0,1,2,Y9"
     12list elements are = 0,1,2
     13PASS testAdd2(createOption("Y10"), mySelect.options[2]) is "0,1,Y10,2"
     14PASS testAdd2(createOption("Y11"), mySelect.options[1]) is "0,Y11,1,Y10,2"
     15list elements are = 0,1,2
     16PASS testAdd2(createGroup("Y12", "Y13"), mySelect.options[1]) is "0,Y12,Y13,1,2"
     17PASS testAdd2(createGroup("Y14", "Y15"), mySelect.options[3]) is "0,Y12,Y13,Y14,Y15,1,2"
     18list elements are = 0,1,2
     19PASS testAdd2(createOption("Y16"), createOption("Y17")) threw exception Error: NotFoundError: DOM Exception 8.
    4120PASS successfullyParsed is true
    4221
  • trunk/LayoutTests/fast/dom/HTMLSelectElement/select-add-optgroup.html

    r177629 r178097  
    99       
    1010var mySelect;
    11 var selectedOptions;
    1211       
    1312function resetSelection() {
     
    1918
    2019function deepCopy() {
    21     var copy=[];
    22     for(var i=0;i<mySelect.options.length; ++i)
     20    var copy = [];
     21    for(var i = 0; i < mySelect.options.length; ++i)
    2322        copy.push(mySelect.options[i].value);
    2423    return copy.join(",");
    2524}
    2625
    27 resetSelection();
    28 var option1 = document.createElement("option");
    29 option1.text = "X1";
    30 option1.value = "Y1";
    31 mySelect.add(option1);
    32 shouldBeEqualToString('deepCopy()', '0,1,2,Y1');
     26function createOption(value) {
     27    return new Option(value + "X", value, false, false);
     28}
    3329
    34 var option2 = document.createElement("option");
    35 option2.text = "X2";
    36 option2.value = "Y2";
    37 mySelect.add(option2, option1);
    38 shouldBeEqualToString('deepCopy()', '0,1,2,Y2,Y1');
     30function createGroup(value1, value2) {
     31    var group = document.createElement('optgroup');
     32    group.appendChild(new Option(value1 + "X", value1, false, false));
     33    group.appendChild(new Option(value2 + "Y", value2, false, false));
     34    return group;
     35}
    3936
    40 var option3 = document.createElement("option");
    41 option3.text = "X3";
    42 option3.value = "Y3";
    43 mySelect.add(option3, option2);
    44 shouldBeEqualToString('deepCopy()', '0,1,2,Y3,Y2,Y1');
     37function testAdd1(element) {
     38    resetSelection();
     39    mySelect.add(element);
     40    return deepCopy();
     41}
    4542
    46 var option4 = document.createElement("option");
    47 option4.text = "X4";
    48 option4.value = "Y4";
    49 mySelect.add(option4, mySelect.options[3]);
    50 shouldBeEqualToString('deepCopy()', '0,1,2,Y4,Y3,Y2,Y1');
     43function testAdd2(newelement, element) {
     44    mySelect.add(newelement, element);
     45    return deepCopy();
     46}
    5147
    52 resetSelection();       
    53 var group1 = document.createElement('optgroup');
    54 group1.appendChild(new Option('X', 'X', false, false));
    55 group1.appendChild(new Option('Y', 'Y', false, false));
    56 mySelect.add(group1);
    57 shouldBeEqualToString('deepCopy()', '0,1,2,X,Y');
    58 
    59 resetSelection();       
    60 var group2 = document.createElement('optgroup');
    61 group2.appendChild(new Option('X', 'X', false, false));
    62 group2.appendChild(new Option('Y', 'Y', false, false));
    63 mySelect.add(group2,mySelect.options[2]);
    64 shouldBeEqualToString('deepCopy()', '0,1,X,Y,2');
    65 
    66 var group3 = document.createElement('optgroup');
    67 group3.appendChild(new Option('X', 'X', false, false));
    68 group3.appendChild(new Option('Y', 'Y', false, false));
    69 mySelect.add(group3,group2);
    70 shouldBeEqualToString('deepCopy()', '0,1,X,Y,X,Y,2');
     48function testAdd3(newelement, index) { 
     49    resetSelection();
     50    mySelect.add(newelement, index);
     51    return deepCopy();
     52}
    7153
    7254resetSelection();
    73 mySelect.add(new Option("X", "Y", false, false), null);
    74 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
     55debug('list elements are = ' + deepCopy());
     56shouldBeEqualToString('testAdd3(createGroup("Y1", "Y2"), null)', '0,1,2,Y1,Y2');
     57shouldBeEqualToString('testAdd3(createGroup("Y3", "Y4"), 0)', 'Y3,Y4,0,1,2');
     58shouldBeEqualToString('testAdd3(createGroup("Y5", "Y6"), 2)', '0,1,Y5,Y6,2');
     59shouldBeEqualToString('testAdd1(createGroup("Y7", "Y8"))', '0,1,2,Y7,Y8');
     60shouldBeEqualToString('testAdd1(createOption("Y9"))', '0,1,2,Y9');
     61resetSelection();
     62debug('list elements are = ' + deepCopy());
     63shouldBeEqualToString('testAdd2(createOption("Y10"), mySelect.options[2])', '0,1,Y10,2');
     64shouldBeEqualToString('testAdd2(createOption("Y11"), mySelect.options[1])', '0,Y11,1,Y10,2');
     65resetSelection();
     66debug('list elements are = ' + deepCopy());
     67shouldBeEqualToString('testAdd2(createGroup("Y12", "Y13"), mySelect.options[1])', '0,Y12,Y13,1,2');
     68shouldBeEqualToString('testAdd2(createGroup("Y14", "Y15"), mySelect.options[3])', '0,Y12,Y13,Y14,Y15,1,2');
     69resetSelection();
     70debug('list elements are = ' + deepCopy());
     71shouldThrow('testAdd2(createOption("Y16"), createOption("Y17"))');
    7572
    76 resetSelection();
    77 mySelect.add(new Option("X", "Y", false, false));
    78 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    79 
    80 resetSelection();
    81 mySelect.add(new Option("X", "Y", false, false), 0);
    82 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    83 
    84 resetSelection();
    85 mySelect.add(new Option("X", "Y", false, false), 1);
    86 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    87 
    88 resetSelection();
    89 mySelect.add(new Option("X", "Y", false, false), 2);
    90 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    91 
    92 resetSelection();
    93 mySelect.add(new Option("X", "Y", false, false), 100);
    94 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    95 
    96 resetSelection();
    97 mySelect.add(new Option("X", "Y", false, false), -100);
    98 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    99 
    100 resetSelection();
    101 mySelect.add(new Option("X", "Y", false, false), "2");
    102 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    103 
    104 resetSelection();
    105 mySelect.add(new Option("X", "Y", false, false), "1");
    106 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    107 
    108 resetSelection();
    109 mySelect.add(new Option("X", "Y", false, false), "0");
    110 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    111 
    112 resetSelection();
    113 mySelect.add(new Option("X", "Y", false, false), 2147483647);
    114 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    115 
    116 resetSelection();
    117 mySelect.add(new Option("X", "Y", false, false), 2147483648);
    118 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    119 
    120 resetSelection();
    121 mySelect.add(new Option("X", "Y", false, false), -2147483647);
    122 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    123 
    124 resetSelection();
    125 mySelect.add(new Option("X", "Y", false, false), -2147483648);
    126 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    127 
    128 resetSelection();
    129 mySelect.add(new Option("X", "Y", false, false), -2147483649);
    130 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    131 
    132 resetSelection();
    133 mySelect.add(new Option("X", "Y", false, false), true);
    134 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    135 
    136 resetSelection();
    137 mySelect.add(new Option("X", "Y", false, false), false);
    138 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    139 
    140 resetSelection();
    141 mySelect.add(new Option("X", "Y", false, false), undefined);
    142 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    143 
    144 resetSelection();
    145 mySelect.add(new Option("X", "Y", false, false), Infinity);
    146 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    147 
    148 resetSelection();
    149 mySelect.add(new Option("X", "Y", false, false), -Infinity);
    150 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    151 
    152 resetSelection();
    153 mySelect.add(new Option("X", "Y", false, false), "foo");
    154 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    155 
    156 resetSelection();
    157 mySelect.add(new Option("X", "Y", false, false), NaN);
    158 shouldBeEqualToString('deepCopy()', '0,1,2,Y');
    159 
    160 resetSelection();
    161 shouldBeUndefined('mySelect.add("foo")');
    162 shouldBeUndefined('mySelect.add("foo", 0)');
    163 shouldBeUndefined('mySelect.add(undefined)');
    164 shouldBeUndefined('mySelect.add(undefined, 0)');
    165 shouldBeUndefined('mySelect.add(null)');
    166 shouldBeUndefined('mySelect.add(null, 0)');
    167        
    16873</script>
    16974</body>
  • trunk/LayoutTests/fast/dom/incompatible-operations-expected.txt

    r134618 r178097  
    1313PASS aNode.lookupPrefix(void 0) is null
    1414PASS aNode.cloneNode(aDOMImplementation) instanceof HTMLDivElement is true
    15 PASS aSelect.add(aDOMImplementation, aDOMImplementation) is undefined.
    16 PASS aSelect.add(aDOMImplementation, anOption) is undefined.
     15PASS aSelect.add(aDOMImplementation, aDOMImplementation) threw exception TypeError: Type error.
     16PASS aSelect.add(aDOMImplementation, anOption) threw exception TypeError: Type error.
    1717PASS aSelect.add(anOption, aDOMImplementation) is undefined.
    18 PASS aSelect.add(void 0, void 0) is undefined.
    19 PASS aSelect.add(void 0, anOption) is undefined.
     18PASS aSelect.add(void 0, void 0) threw exception TypeError: Type error.
     19PASS aSelect.add(void 0, anOption) threw exception TypeError: Type error.
    2020PASS aSelect.add(anOption, void 0) is undefined.
    2121PASS successfullyParsed is true
  • trunk/LayoutTests/fast/dom/incompatible-operations.html

    r155265 r178097  
    4141shouldBe("aNode.lookupPrefix(void 0)", "null");
    4242shouldBeTrue("aNode.cloneNode(aDOMImplementation) instanceof HTMLDivElement");
    43 shouldBeUndefined("aSelect.add(aDOMImplementation, aDOMImplementation)");
    44 shouldBeUndefined("aSelect.add(aDOMImplementation, anOption)");
     43shouldThrow("aSelect.add(aDOMImplementation, aDOMImplementation)");
     44shouldThrow("aSelect.add(aDOMImplementation, anOption)");
    4545shouldBeUndefined("aSelect.add(anOption, aDOMImplementation)");
    46 shouldBeUndefined("aSelect.add(void 0, void 0)");
    47 shouldBeUndefined("aSelect.add(void 0, anOption)");
     46shouldThrow("aSelect.add(void 0, void 0)");
     47shouldThrow("aSelect.add(void 0, anOption)");
    4848shouldBeUndefined("aSelect.add(anOption, void 0)");
    4949</script>
  • trunk/LayoutTests/js/dom/script-tests/select-options-add.js

    r156066 r178097  
    5555debug("1.4 Add a non-Option element");
    5656option1 = document.createElement("DIV");
    57 shouldThrow("select1.options.add(option1)");
     57shouldBeUndefined("select1.options.add(option1)");
    5858shouldBe("select1.options.length", "3");
    5959shouldBe("select1.selectedIndex", "0");
     
    238238debug("2.8 Add an Option at index -2");
    239239option2 = document.createElement("OPTION");
    240 shouldThrow("select2.options.add(option2, -2)");
    241 shouldBe("select2.options.length", "7");
     240shouldNotThrow("select2.options.add(option2, -2)");
     241shouldBe("select2.options.length", "8");
    242242shouldBe("select2.selectedIndex", "1");
    243243debug("");
     
    246246option2 = document.createElement("OPTION");
    247247shouldNotThrow("select2.options.add(option2, -1/0)");
    248 shouldBe("select2.options.length", "8");
     248shouldBe("select2.options.length", "9");
    249249shouldBe("select2.selectedIndex", "2");
    250250debug("");
     
    253253option2 = document.createElement("OPTION");
    254254shouldNotThrow("select2.options.add(option2, 0/0)");
    255 shouldBe("select2.options.length", "9");
     255shouldBe("select2.options.length", "10");
    256256shouldBe("select2.selectedIndex", "3");
    257257debug("");
     
    260260option2 = document.createElement("OPTION");
    261261shouldNotThrow("select2.options.add(option2, 1/0)");
    262 shouldBe("select2.options.length", "10");
     262shouldBe("select2.options.length", "11");
    263263shouldBe("select2.selectedIndex", "4");
    264264debug("");
     
    266266debug("2.12 Add a non-Option element");
    267267option2 = document.createElement("DIV");
    268 shouldThrow("select2.options.add(option2, 1)");
    269 shouldBe("select2.options.length", "10");
     268shouldBeUndefined("select2.options.add(option2, 1)");
     269shouldBe("select2.options.length", "11");
    270270shouldBe("select2.selectedIndex", "4");
    271271debug("");
     
    274274option2 = "o";
    275275shouldThrow("select2.options.add(option2, 1)");
    276 shouldBe("select2.options.length", "10");
     276shouldBe("select2.options.length", "11");
    277277shouldBe("select2.selectedIndex", "4");
    278278debug("");
     
    281281option2 = 3.14;
    282282shouldThrow("select2.options.add(option2, 1)");
    283 shouldBe("select2.options.length", "10");
     283shouldBe("select2.options.length", "11");
    284284shouldBe("select2.selectedIndex", "4");
    285285debug("");
     
    288288option2 = true;
    289289shouldThrow("select2.options.add(option2, 1)");
    290 shouldBe("select2.options.length", "10");
     290shouldBe("select2.options.length", "11");
    291291shouldBe("select2.selectedIndex", "4");
    292292debug("");
     
    295295option2 = undefined;
    296296shouldThrow("select2.options.add(option2, 1)");
    297 shouldBe("select2.options.length", "10");
     297shouldBe("select2.options.length", "11");
    298298shouldBe("select2.selectedIndex", "4");
    299299debug("");
     
    302302option2 = null;
    303303shouldThrow("select2.options.add(option2, 1)");
    304 shouldBe("select2.options.length", "10");
     304shouldBe("select2.options.length", "11");
    305305shouldBe("select2.selectedIndex", "4");
    306306debug("");
     
    309309option2 = -1/0;
    310310shouldThrow("select2.options.add(option2, 1)");
    311 shouldBe("select2.options.length", "10");
     311shouldBe("select2.options.length", "11");
    312312shouldBe("select2.selectedIndex", "4");
    313313debug("");
     
    316316option2 = 0/0;
    317317shouldThrow("select2.options.add(option2, 1)");
    318 shouldBe("select2.options.length", "10");
     318shouldBe("select2.options.length", "11");
    319319shouldBe("select2.selectedIndex", "4");
    320320debug("");
     
    323323option2 = 1/0;
    324324shouldThrow("select2.options.add(option2, 1)");
    325 shouldBe("select2.options.length", "10");
    326 shouldBe("select2.selectedIndex", "4");
    327 debug("");
     325shouldBe("select2.options.length", "11");
     326shouldBe("select2.selectedIndex", "4");
     327debug("");
  • trunk/LayoutTests/js/dom/select-options-add-expected.txt

    r156066 r178097  
    3030
    31311.4 Add a non-Option element
    32 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     32PASS select1.options.add(option1) is undefined.
    3333PASS select1.options.length is 3
    3434PASS select1.selectedIndex is 0
    3535
    36361.5 Add a non-element (string)
    37 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     37PASS select1.options.add(option1) threw exception TypeError: Type error.
    3838PASS select1.options.length is 3
    3939PASS select1.selectedIndex is 0
    4040
    41411.6 Add a non-element (number)
    42 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     42PASS select1.options.add(option1) threw exception TypeError: Type error.
    4343PASS select1.options.length is 3
    4444PASS select1.selectedIndex is 0
    4545
    46461.7 Add a non-element (boolean)
    47 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     47PASS select1.options.add(option1) threw exception TypeError: Type error.
    4848PASS select1.options.length is 3
    4949PASS select1.selectedIndex is 0
    5050
    51511.8 Add undefined
    52 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     52PASS select1.options.add(option1) threw exception TypeError: Type error.
    5353PASS select1.options.length is 3
    5454PASS select1.selectedIndex is 0
    5555
    56561.9 Add null
    57 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     57PASS select1.options.add(option1) threw exception TypeError: Type error.
    5858PASS select1.options.length is 3
    5959PASS select1.selectedIndex is 0
    6060
    61611.10 Add negative infinity
    62 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     62PASS select1.options.add(option1) threw exception TypeError: Type error.
    6363PASS select1.options.length is 3
    6464PASS select1.selectedIndex is 0
    6565
    66661.11 Add NaN
    67 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     67PASS select1.options.add(option1) threw exception TypeError: Type error.
    6868PASS select1.options.length is 3
    6969PASS select1.selectedIndex is 0
    7070
    71711.12 Add positive infinity
    72 PASS select1.options.add(option1) threw exception Error: TypeMismatchError: DOM Exception 17.
     72PASS select1.options.add(option1) threw exception TypeError: Type error.
    7373PASS select1.options.length is 3
    7474PASS select1.selectedIndex is 0
     
    159159
    1601602.8 Add an Option at index -2
    161 PASS select2.options.add(option2, -2) threw exception Error: IndexSizeError: DOM Exception 1.
    162 PASS select2.options.length is 7
     161PASS select2.options.add(option2, -2) did not throw exception.
     162PASS select2.options.length is 8
    163163PASS select2.selectedIndex is 1
    164164
    1651652.9 Add an Option at index -Infinity
    166166PASS select2.options.add(option2, -1/0) did not throw exception.
    167 PASS select2.options.length is 8
     167PASS select2.options.length is 9
    168168PASS select2.selectedIndex is 2
    169169
    1701702.10 Add an Option at index NaN
    171171PASS select2.options.add(option2, 0/0) did not throw exception.
    172 PASS select2.options.length is 9
     172PASS select2.options.length is 10
    173173PASS select2.selectedIndex is 3
    174174
    1751752.11 Add an Option at index Infinity
    176176PASS select2.options.add(option2, 1/0) did not throw exception.
    177 PASS select2.options.length is 10
     177PASS select2.options.length is 11
    178178PASS select2.selectedIndex is 4
    179179
    1801802.12 Add a non-Option element
    181 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    182 PASS select2.options.length is 10
     181PASS select2.options.add(option2, 1) is undefined.
     182PASS select2.options.length is 11
    183183PASS select2.selectedIndex is 4
    184184
    1851852.13 Add a non-element (string)
    186 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    187 PASS select2.options.length is 10
     186PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
     187PASS select2.options.length is 11
    188188PASS select2.selectedIndex is 4
    189189
    1901902.14 Add a non-element (number)
    191 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    192 PASS select2.options.length is 10
     191PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
     192PASS select2.options.length is 11
    193193PASS select2.selectedIndex is 4
    194194
    1951952.15 Add a non-element (boolean)
    196 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    197 PASS select2.options.length is 10
     196PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
     197PASS select2.options.length is 11
    198198PASS select2.selectedIndex is 4
    199199
    2002002.16 Add undefined
    201 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    202 PASS select2.options.length is 10
     201PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
     202PASS select2.options.length is 11
    203203PASS select2.selectedIndex is 4
    204204
    2052052.17 Add null
    206 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    207 PASS select2.options.length is 10
     206PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
     207PASS select2.options.length is 11
    208208PASS select2.selectedIndex is 4
    209209
    2102102.18 Add negative infinity
    211 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    212 PASS select2.options.length is 10
     211PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
     212PASS select2.options.length is 11
    213213PASS select2.selectedIndex is 4
    214214
    2152152.19 Add NaN
    216 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    217 PASS select2.options.length is 10
     216PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
     217PASS select2.options.length is 11
    218218PASS select2.selectedIndex is 4
    219219
    2202202.20 Add positive infinity
    221 PASS select2.options.add(option2, 1) threw exception Error: TypeMismatchError: DOM Exception 17.
    222 PASS select2.options.length is 10
     221PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
     222PASS select2.options.length is 11
    223223PASS select2.selectedIndex is 4
    224224
  • trunk/Source/WebCore/ChangeLog

    r178095 r178097  
     12015-01-07  Shivakumar JM  <shiva.jm@samsung.com>
     2
     3        HTMLSelectElement and HTMLOptionsCollection add() method should support index as second argument.
     4        https://bugs.webkit.org/show_bug.cgi?id=139179
     5
     6        Reviewed by Darin Adler.
     7
     8        HTMLSelectElement and HTMLOptionsCollection add() method should support index as second argument as per specification
     9        http://www.w3.org/html/wg/drafts/html/master/forms.html#the-select-element.
     10        Also this matches the behavior of Chrome and FireFox.
     11
     12        Tests: fast/dom/HTMLSelectElement/add.html
     13               fast/dom/HTMLSelectElement/options-collection-add.html
     14
     15        * bindings/js/JSHTMLOptionsCollectionCustom.cpp:
     16        (WebCore::JSHTMLOptionsCollection::add): Deleted.
     17        * html/HTMLOptionsCollection.cpp:
     18        (WebCore::HTMLOptionsCollection::add):
     19        * html/HTMLOptionsCollection.h:
     20        * html/HTMLOptionsCollection.idl:
     21        * html/HTMLSelectElement.cpp:
     22        (WebCore::HTMLSelectElement::add):
     23        * html/HTMLSelectElement.h:
     24        * html/HTMLSelectElement.idl:
     25
    1262015-01-07  Gwang Yoon Hwang  <yoon@igalia.com>
    227
  • trunk/Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp

    r173804 r178097  
    6161}
    6262
    63 JSValue JSHTMLOptionsCollection::add(ExecState* exec)
    64 {
    65     HTMLOptionsCollection& imp = impl();
    66     HTMLOptionElement* option = JSHTMLOptionElement::toWrapped(exec->argument(0));
    67     ExceptionCode ec = 0;
    68     if (exec->argumentCount() < 2)
    69         imp.add(option, ec);
    70     else {
    71         int index = exec->argument(1).toInt32(exec);
    72         if (exec->hadException())
    73             return jsUndefined();
    74         imp.add(option, index, ec);
    75     }
    76     setDOMException(exec, ec);
    77     return jsUndefined();
    78 }
    79 
    8063JSValue JSHTMLOptionsCollection::remove(ExecState* exec)
    8164{
  • trunk/Source/WebCore/html/HTMLOptionsCollection.cpp

    r177259 r178097  
    3737}
    3838
    39 void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, ExceptionCode& ec)
     39void HTMLOptionsCollection::add(HTMLElement* element, HTMLElement* beforeElement, ExceptionCode& ec)
    4040{
    41     add(element, length(), ec);
     41    selectElement().add(element, beforeElement, ec);
    4242}
    4343
    44 void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, int index, ExceptionCode& ec)
     44void HTMLOptionsCollection::add(HTMLElement* element, int beforeIndex, ExceptionCode& ec)
    4545{
    46     HTMLOptionElement* newOption = element.get();
    47 
    48     if (!newOption) {
    49         ec = TYPE_MISMATCH_ERR;
    50         return;
    51     }
    52 
    53     if (index < -1) {
    54         ec = INDEX_SIZE_ERR;
    55         return;
    56     }
    57 
    58     ec = 0;
    59 
    60     if (index == -1 || unsigned(index) >= length())
    61         selectElement().add(newOption, nullptr, ec);
    62     else
    63         selectElement().add(newOption, downcast<HTMLOptionElement>(item(index)), ec);
    64 
    65     ASSERT(!ec);
     46    add(element, downcast<HTMLElement>(item(beforeIndex)), ec);
    6647}
    6748
  • trunk/Source/WebCore/html/HTMLOptionsCollection.h

    r177259 r178097  
    4141    const HTMLSelectElement& selectElement() const { return downcast<HTMLSelectElement>(ownerNode()); }
    4242
    43     void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&);
    44     void add(PassRefPtr<HTMLOptionElement>, int index, ExceptionCode&);
     43    void add(HTMLElement*, HTMLElement* beforeElement, ExceptionCode&);
     44    void add(HTMLElement*, int beforeIndex, ExceptionCode&);
    4545    void remove(int index);
    4646    void remove(HTMLOptionElement*);
  • trunk/Source/WebCore/html/HTMLOptionsCollection.idl

    r159061 r178097  
    2929    Node namedItem([Default=Undefined] optional DOMString name);
    3030
    31     [Custom, RaisesException] void add([Default=Undefined] optional HTMLOptionElement option,
    32                       optional unsigned long index);
     31#if (!defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C) && (!defined(LANGUAGE_GOBJECT) || !LANGUAGE_GOBJECT)
     32    [RaisesException] void add(HTMLElement element, [Default=Undefined] optional HTMLElement? before);
     33    [RaisesException] void add(HTMLElement element, [Default=Undefined] optional long index);
     34#else
     35    [RaisesException] void add(HTMLOptionElement option, unsigned long index);
     36#endif
    3337    [Custom] void remove([Default=Undefined] optional unsigned long index);
    3438
  • trunk/Source/WebCore/html/HTMLSelectElement.cpp

    r177996 r178097  
    219219}
    220220
    221 void HTMLSelectElement::add(HTMLElement* element, HTMLElement* before, ExceptionCode& ec)
     221void HTMLSelectElement::add(HTMLElement* element, HTMLElement* beforeElement, ExceptionCode& ec)
    222222{
    223223    if (!element || !(is<HTMLOptionElement>(*element) || element->hasTagName(hrTag) || is<HTMLOptGroupElement>(*element)))
     
    227227    Ref<HTMLElement> protectNewChild(*element);
    228228
    229     insertBefore(element, before, ec);
     229    insertBefore(element, beforeElement, ec);
    230230    updateValidity();
     231}
     232
     233void HTMLSelectElement::add(HTMLElement* element, int beforeIndex, ExceptionCode& ec)
     234{
     235    add(element, item(beforeIndex), ec);
    231236}
    232237
  • trunk/Source/WebCore/html/HTMLSelectElement.h

    r177996 r178097  
    5858
    5959    void add(HTMLElement*, HTMLElement* beforeElement, ExceptionCode&);
     60    void add(HTMLElement*, int beforeIndex, ExceptionCode&);
    6061
    6162    using Node::remove;
  • trunk/Source/WebCore/html/HTMLSelectElement.idl

    r159061 r178097  
    4242    getter Node item(unsigned long index);
    4343    Node namedItem([Default=Undefined] optional DOMString name);
    44     [ObjCLegacyUnnamedParameters, RaisesException] void add([Default=Undefined] optional HTMLElement element,
    45                             [Default=Undefined] optional HTMLElement before);
     44    [ObjCLegacyUnnamedParameters, RaisesException] void add(HTMLElement element, [Default=Undefined] optional HTMLElement? before);
    4645#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
     46    [RaisesException] void add(HTMLElement element, [Default=Undefined] optional long index);
    4747    // In JavaScript, we support both option index and option object parameters.
    4848    // As of this writing this cannot be auto-generated.
Note: See TracChangeset for help on using the changeset viewer.