Changeset 186265 in webkit


Ignore:
Timestamp:
Jul 3, 2015 1:54:15 PM (9 years ago)
Author:
dbates@webkit.org
Message:

REGRESSION (r178097): JavaScript TypeError after clicking on compose button in Yahoo Mail
https://bugs.webkit.org/show_bug.cgi?id=146515
<rdar://problem/21348421>

Reviewed by Chris Dumez.

Source/WebCore:

Fixes an issue where extra arguments passed to a Web IDL overloaded function, whose implementation
is generated by the bindings generator script, are not ignored as per the note in section "Interface object Call? method"
of the Web IDL spec, <http://www.w3.org/TR/2012/CR-WebIDL-20120419/> (19 April 2012).

Currently for an overloaded function the JavaScript bindings generator script emits code to
throw a TypeError when it cannot find a candidate function that takes the same number of
arguments as passed by a caller. Prior to the change made in bug #139179 (r178097), the
bindings code for HTMLSelectElement.add() was written by hand and ignored extra arguments
that were passed to it. Following this change, the bindings code for HTMLSelectElement.add()
is generated by the bindings generator script. Therefore, we throw a TypeError when Yahoo Mail
calls HTMLSelectElement.add() with extra arguments because the code emitted by the bindings
generator script does not ignore them.

  • bindings/scripts/CodeGeneratorJS.pm:

(LengthOfLongestFunctionParameterList): Added. Computes the length of longest overload parameter list.
(GenerateOverloadedFunction): Emit code that ignores more arguments than LengthOfLongestFunctionParameterList().
(GenerateOverloadedConstructorDefinition): Ditto.

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::jsTestObjPrototypeFunctionOverloadedMethod12): Added; expected result for an overloaded
function that takes a variadic number of Blob elements.
(WebCore::jsTestObjPrototypeFunctionOverloadedMethod): Update expected result. The added
if-conditional expression for the IDL declaration overloadedMethod(Blob... blobArgs) is empty
because we do not support overloading of functions with variadic arguments.
(WebCore::jsTestObjConstructorFunctionOverloadedMethod1):

  • bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp:

(WebCore::JSTestOverloadedConstructorsConstructor::constructJSTestOverloadedConstructors5): Added; expected
result for an overloaded constructors that takes a variadic number of long arguments.
(WebCore::JSTestOverloadedConstructorsConstructor::constructJSTestOverloadedConstructors): Update expected
result. The added if-conditional expression for the IDL declaration Constructor(long... longArgs) is empty
because we do not support overloading of constructors with variadic arguments.

  • bindings/scripts/test/TestObj.idl: Added declaration overloadedMethod(Blob...). Also fixed

typo in license block text.

  • bindings/scripts/test/TestOverloadedConstructors.idl: Added declaration Constructor(long... longArgs).

Also fixed typo in license block text.

LayoutTests:

Add new sub-tests to LayoutTests/fast/dom/HTMLSelectElement/{add, options-collection-add}.html,
simplify existing test code, share common code, and update expected results.

Additionally, update results for tests in LayoutTests/fast/canvas now that we ignore extra
arguments passed to a Web IDL overloaded function whose implementation is generated by the
bindings generator script.

  • fast/canvas/canvas-overloads-drawImage-expected.txt:
  • fast/canvas/canvas-overloads-setFillColor-expected.txt:
  • fast/canvas/canvas-overloads-setShadow-expected.txt:
  • fast/canvas/canvas-overloads-setStrokeColor-expected.txt:
  • fast/canvas/script-tests/canvas-overloads-drawImage.js:
  • fast/canvas/script-tests/canvas-overloads-setFillColor.js:
  • fast/canvas/script-tests/canvas-overloads-setShadow.js:
  • fast/canvas/script-tests/canvas-overloads-setStrokeColor.js:
  • fast/dom/HTMLSelectElement/add-expected.txt:
  • fast/dom/HTMLSelectElement/add.html:
  • fast/dom/HTMLSelectElement/options-collection-add-expected.txt:
  • fast/dom/HTMLSelectElement/options-collection-add.html:
  • fast/dom/HTMLSelectElement/resources/html-select-and-options-collection-utilities.js: Added.

(createSelectElementWithTestData):
(deepCopy):
(createOption):
(createGroup):

Location:
trunk
Files:
2 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r186264 r186265  
     12015-07-03  Daniel Bates  <dabates@apple.com>
     2
     3        REGRESSION (r178097): JavaScript TypeError after clicking on compose button in Yahoo Mail
     4        https://bugs.webkit.org/show_bug.cgi?id=146515
     5        <rdar://problem/21348421>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Add new sub-tests to LayoutTests/fast/dom/HTMLSelectElement/{add, options-collection-add}.html,
     10        simplify existing test code, share common code, and update expected results.
     11
     12        Additionally, update results for tests in LayoutTests/fast/canvas now that we ignore extra
     13        arguments passed to a Web IDL overloaded function whose implementation is generated by the
     14        bindings generator script.
     15
     16        * fast/canvas/canvas-overloads-drawImage-expected.txt:
     17        * fast/canvas/canvas-overloads-setFillColor-expected.txt:
     18        * fast/canvas/canvas-overloads-setShadow-expected.txt:
     19        * fast/canvas/canvas-overloads-setStrokeColor-expected.txt:
     20        * fast/canvas/script-tests/canvas-overloads-drawImage.js:
     21        * fast/canvas/script-tests/canvas-overloads-setFillColor.js:
     22        * fast/canvas/script-tests/canvas-overloads-setShadow.js:
     23        * fast/canvas/script-tests/canvas-overloads-setStrokeColor.js:
     24        * fast/dom/HTMLSelectElement/add-expected.txt:
     25        * fast/dom/HTMLSelectElement/add.html:
     26        * fast/dom/HTMLSelectElement/options-collection-add-expected.txt:
     27        * fast/dom/HTMLSelectElement/options-collection-add.html:
     28        * fast/dom/HTMLSelectElement/resources/html-select-and-options-collection-utilities.js: Added.
     29        (createSelectElementWithTestData):
     30        (deepCopy):
     31        (createOption):
     32        (createGroup):
     33
    1342015-07-03  Chris Dumez  <cdumez@apple.com>
    235
  • trunk/LayoutTests/fast/canvas/canvas-overloads-drawImage-expected.txt

    r134613 r186265  
    1414PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
    1515PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
    16 PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
    17 PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
     16PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
     17PASS ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
    1818PASS ctx.drawImage(canvasElement) threw exception TypeError: Not enough arguments.
    1919PASS ctx.drawImage(canvasElement, 0) threw exception TypeError: Not enough arguments.
     
    2525PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
    2626PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0) threw exception Error: IndexSizeError: DOM Exception 1.
    27 PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
    28 PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
     27PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception Error: IndexSizeError: DOM Exception 1.
     28PASS ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception Error: IndexSizeError: DOM Exception 1.
    2929PASS successfullyParsed is true
    3030
  • trunk/LayoutTests/fast/canvas/canvas-overloads-setFillColor-expected.txt

    r126562 r186265  
    1111PASS ctx.setFillColor(0, 0, 0, 0) is undefined
    1212PASS ctx.setFillColor(0, 0, 0, 0, 0) is undefined
    13 PASS ctx.setFillColor(0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
     13PASS ctx.setFillColor(0, 0, 0, 0, 0, 0) is undefined
    1414PASS successfullyParsed is true
    1515
  • trunk/LayoutTests/fast/canvas/canvas-overloads-setShadow-expected.txt

    r126562 r186265  
    1717PASS ctx.setShadow(0, 0, 0, 0, 0, 0, 0) is undefined
    1818PASS ctx.setShadow(0, 0, 0, 0, 0, 0, 0, 0) is undefined
    19 PASS ctx.setShadow(0, 0, 0, 0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
     19PASS ctx.setShadow(0, 0, 0, 0, 0, 0, 0, 0, 0) is undefined
    2020PASS successfullyParsed is true
    2121
  • trunk/LayoutTests/fast/canvas/canvas-overloads-setStrokeColor-expected.txt

    r126562 r186265  
    1111PASS ctx.setStrokeColor(0, 0, 0, 0) is undefined
    1212PASS ctx.setStrokeColor(0, 0, 0, 0, 0) is undefined
    13 PASS ctx.setStrokeColor(0, 0, 0, 0, 0, 0) threw exception TypeError: Type error.
     13PASS ctx.setStrokeColor(0, 0, 0, 0, 0, 0) is undefined
    1414PASS successfullyParsed is true
    1515
  • trunk/LayoutTests/fast/canvas/script-tests/canvas-overloads-drawImage.js

    r134613 r186265  
    1717shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
    1818shouldBe("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
    19 shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
    20 shouldThrow("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
     19shouldBe("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
     20shouldBe("ctx.drawImage(imageElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
    2121
    2222var canvasElement = document.createElement("canvas");
     
    3030shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
    3131shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0)", "'Error: IndexSizeError: DOM Exception 1'");
    32 shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
    33 shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
     32shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "'Error: IndexSizeError: DOM Exception 1'");
     33shouldThrow("ctx.drawImage(canvasElement, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "'Error: IndexSizeError: DOM Exception 1'");
  • trunk/LayoutTests/fast/canvas/script-tests/canvas-overloads-setFillColor.js

    r126562 r186265  
    1313shouldBe("ctx.setFillColor(0, 0, 0, 0)", "undefined");
    1414shouldBe("ctx.setFillColor(0, 0, 0, 0, 0)", "undefined");
    15 shouldThrow("ctx.setFillColor(0, 0, 0, 0, 0, 0)", "TypeError");
     15shouldBe("ctx.setFillColor(0, 0, 0, 0, 0, 0)", "undefined");
  • trunk/LayoutTests/fast/canvas/script-tests/canvas-overloads-setShadow.js

    r126562 r186265  
    1919shouldBe("ctx.setShadow(0, 0, 0, 0, 0, 0, 0)", "undefined");
    2020shouldBe("ctx.setShadow(0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
    21 shouldThrow("ctx.setShadow(0, 0, 0, 0, 0, 0, 0, 0, 0)", "TypeError");
     21shouldBe("ctx.setShadow(0, 0, 0, 0, 0, 0, 0, 0, 0)", "undefined");
  • trunk/LayoutTests/fast/canvas/script-tests/canvas-overloads-setStrokeColor.js

    r126562 r186265  
    1313shouldBe("ctx.setStrokeColor(0, 0, 0, 0)", "undefined");
    1414shouldBe("ctx.setStrokeColor(0, 0, 0, 0, 0)", "undefined");
    15 shouldThrow("ctx.setStrokeColor(0, 0, 0, 0, 0, 0)", "TypeError");
     15shouldBe("ctx.setStrokeColor(0, 0, 0, 0, 0, 0)", "undefined");
  • trunk/LayoutTests/fast/dom/HTMLSelectElement/add-expected.txt

    r178097 r186265  
    1 Test select.add() with index parameter
     1Test that HTMLSelectElement.add() works when passing an index or an HTML option element as its second argument.
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    44
    55
    6 list elements are = 0,1,2
    7 PASS testAdd1(createOption("Y1")) is "0,1,2,Y1"
    8 PASS testAdd3(createOption("Y2"), null) is "0,1,2,Y2"
    9 PASS testAdd3(createOption("Y3"), 0) is "Y3,0,1,2"
    10 PASS testAdd3(createOption("Y4"), 1) is "0,Y4,1,2"
    11 PASS testAdd3(createOption("Y5"), 2) is "0,1,Y5,2"
    12 PASS testAdd3(createOption("Y6"), 3) is "0,1,2,Y6"
    13 PASS testAdd3(createOption("Y7"), 100) is "0,1,2,Y7"
    14 PASS testAdd3(createOption("Y8"), -100) is "0,1,2,Y8"
    15 PASS testAdd3(createOption("Y9"), "0") is "Y9,0,1,2"
    16 PASS testAdd3(createOption("Y10"), "1") is "0,Y10,1,2"
    17 PASS testAdd3(createOption("Y11"), "2") is "0,1,Y11,2"
    18 PASS testAdd3(createOption("Y12"), true) is "0,Y12,1,2"
    19 PASS testAdd3(createOption("Y13"), false) is "Y13,0,1,2"
    20 PASS testAdd3(createOption("Y14"), 2147483647) is "0,1,2,Y14"
    21 PASS testAdd3(createOption("Y15"), 2147483648) is "0,1,2,Y15"
    22 PASS testAdd3(createOption("Y16"), -2147483647) is "0,1,2,Y16"
    23 PASS testAdd3(createOption("Y17"), -2147483648) is "0,1,2,Y17"
    24 PASS testAdd3(createOption("Y18"), -2147483649) is "0,1,2,Y18"
    25 PASS testAdd3(createOption("Y19"), Infinity) is "Y19,0,1,2"
    26 PASS testAdd3(createOption("Y20"), -Infinity) is "Y20,0,1,2"
    27 PASS testAdd3(createOption("Y21"), "foo") is "Y21,0,1,2"
    28 PASS testAdd3(createOption("Y22"), NaN) is "Y22,0,1,2"
    29 PASS testAdd3(createOption("Y23"), undefined) is "Y23,0,1,2"
    30 PASS testAdd3(createOption("Y24"), -2) is "0,1,2,Y24"
    31 PASS testAdd4(createOption("Y25"), 0, 1) threw exception TypeError: Type error.
    32 PASS testAdd4(createOption("Y25"), mySelect.options[0], 1) threw exception TypeError: Type error.
    33 list elements are = 0,1,2
    34 PASS mySelect.add("foo") threw exception TypeError: Type error.
    35 PASS mySelect.add("foo", 0) threw exception TypeError: Type error.
    36 PASS mySelect.add(undefined) threw exception TypeError: Type error.
    37 PASS mySelect.add(undefined, 0) threw exception TypeError: Type error.
    38 PASS mySelect.add(null, 0) threw exception TypeError: Type error.
    39 PASS mySelect.add(null) threw exception TypeError: Type error.
    40 PASS mySelect.add() threw exception TypeError: Not enough arguments.
     6
     7Call HTMLSelectElement.add() with zero arguments:
     8PASS testAdd() threw exception TypeError: Not enough arguments.
     9
     10Call HTMLSelectElement.add() with one argument:
     11PASS testAdd(createOption("Y1")) is "0,1,2,Y1"
     12PASS testAdd("foo") threw exception TypeError: Type error.
     13PASS testAdd(undefined) threw exception TypeError: Type error.
     14PASS testAdd(null) threw exception TypeError: Type error.
     15
     16Call HTMLSelectElement.add() with two arguments:
     17PASS testAdd(createOption("Y2"), null) is "0,1,2,Y2"
     18PASS testAdd(createOption("Y3"), 0) is "Y3,0,1,2"
     19PASS testAdd(createOption("Y4"), 1) is "0,Y4,1,2"
     20PASS testAdd(createOption("Y5"), 2) is "0,1,Y5,2"
     21PASS testAdd(createOption("Y6"), 3) is "0,1,2,Y6"
     22PASS testAdd(createOption("Y7"), 100) is "0,1,2,Y7"
     23PASS testAdd(createOption("Y8"), -100) is "0,1,2,Y8"
     24PASS testAdd(createOption("Y9"), "0") is "Y9,0,1,2"
     25PASS testAdd(createOption("Y10"), "1") is "0,Y10,1,2"
     26PASS testAdd(createOption("Y11"), "2") is "0,1,Y11,2"
     27PASS testAdd(createOption("Y12"), true) is "0,Y12,1,2"
     28PASS testAdd(createOption("Y13"), false) is "Y13,0,1,2"
     29PASS testAdd(createOption("Y14"), 2147483647) is "0,1,2,Y14"
     30PASS testAdd(createOption("Y15"), 2147483648) is "0,1,2,Y15"
     31PASS testAdd(createOption("Y16"), -2147483647) is "0,1,2,Y16"
     32PASS testAdd(createOption("Y17"), -2147483648) is "0,1,2,Y17"
     33PASS testAdd(createOption("Y18"), -2147483649) is "0,1,2,Y18"
     34PASS testAdd(createOption("Y19"), Infinity) is "Y19,0,1,2"
     35PASS testAdd(createOption("Y20"), -Infinity) is "Y20,0,1,2"
     36PASS testAdd(createOption("Y21"), "foo") is "Y21,0,1,2"
     37PASS testAdd(createOption("Y22"), NaN) is "Y22,0,1,2"
     38PASS testAdd(createOption("Y23"), undefined) is "Y23,0,1,2"
     39PASS testAdd(createOption("Y24"), -2) is "0,1,2,Y24"
     40PASS testAdd(createOption("X"), mySelect.options[0]) is "X,0,1,2"
     41PASS testAdd(createOption("X"), mySelect.options[1]) is "0,X,1,2"
     42PASS testAdd(createOption("X"), mySelect.options[2]) is "0,1,X,2"
     43PASS testAdd("foo", 0) threw exception TypeError: Type error.
     44PASS testAdd(undefined, 0) threw exception TypeError: Type error.
     45PASS testAdd(null, 0) threw exception TypeError: Type error.
     46
     47Call HTMLSelectElement.add() with three arguments (when it only takes two arguments):
     48PASS testAdd(createOption("X"), 0, "unnecessary extra argument - should be ignored") is "X,0,1,2"
     49PASS testAdd(createOption("X"), mySelect.options[1], "unnecessary extra argument - should be ignored") is "0,X,1,2"
    4150PASS successfullyParsed is true
    4251
  • trunk/LayoutTests/fast/dom/HTMLSelectElement/add.html

    r178097 r186265  
    33<head>
    44<script src="../../../resources/js-test.js"></script>
     5<script src="resources/html-select-and-options-collection-utilities.js"></script>
    56</head>
    67<body>
    78<script>
    8 description('Test select.add() with index parameter');
    9        
    10 var mySelect;
     9description("Test that HTMLSelectElement.add() works when passing an index or an HTML option element as its second argument.");
    1110
    12 function resetSelection() {
    13     mySelect = document.createElement('select');
    14     mySelect.appendChild(new Option("0", "0", false, false));
    15     mySelect.appendChild(new Option("1", "1", false, false));
    16     mySelect.appendChild(new Option("2", "2", false, false));
     11var mySelect = createSelectElementWithTestData();
     12
     13function testAdd()
     14{
     15    HTMLSelectElement.prototype.add.apply(mySelect, arguments);
     16    var result = deepCopy(mySelect);
     17    mySelect = createSelectElementWithTestData(); // Reset
     18    return result;
    1719}
    1820
    19 function deepCopy() {
    20     var copy = [];
    21     for(var i = 0; i < mySelect.options.length; ++i)
    22         copy.push(mySelect.options[i].value);
    23     return copy.join(",");
    24 }
    25        
    26 function createOption(value) {
    27     return new Option(value + "X", value, false, false);
    28 }
     21debug("<br>Call HTMLSelectElement.add() with zero arguments:");
     22shouldThrow("testAdd()");
    2923
    30 function testAdd1(element) {
    31     resetSelection();
    32     mySelect.add(element);
    33     return deepCopy();
    34 }
     24debug("<br>Call HTMLSelectElement.add() with one argument:");
     25shouldBeEqualToString('testAdd(createOption("Y1"))', "0,1,2,Y1");
     26shouldThrow('testAdd("foo")');
     27shouldThrow("testAdd(undefined)");
     28shouldThrow("testAdd(null)");
    3529
    36 function testAdd3(newelement, index) {
    37     resetSelection();
    38     mySelect.add(newelement, index);
    39     return deepCopy();
    40 }
     30debug("<br>Call HTMLSelectElement.add() with two arguments:");
     31shouldBeEqualToString('testAdd(createOption("Y2"), null)', "0,1,2,Y2");
     32shouldBeEqualToString('testAdd(createOption("Y3"), 0)', "Y3,0,1,2");
     33shouldBeEqualToString('testAdd(createOption("Y4"), 1)', "0,Y4,1,2");
     34shouldBeEqualToString('testAdd(createOption("Y5"), 2)', "0,1,Y5,2");
     35shouldBeEqualToString('testAdd(createOption("Y6"), 3)', "0,1,2,Y6");
     36shouldBeEqualToString('testAdd(createOption("Y7"), 100)', "0,1,2,Y7");
     37shouldBeEqualToString('testAdd(createOption("Y8"), -100)', "0,1,2,Y8");
     38shouldBeEqualToString('testAdd(createOption("Y9"), "0")', "Y9,0,1,2");
     39shouldBeEqualToString('testAdd(createOption("Y10"), "1")', "0,Y10,1,2");
     40shouldBeEqualToString('testAdd(createOption("Y11"), "2")', "0,1,Y11,2");
     41shouldBeEqualToString('testAdd(createOption("Y12"), true)', "0,Y12,1,2");
     42shouldBeEqualToString('testAdd(createOption("Y13"), false)', "Y13,0,1,2");
     43shouldBeEqualToString('testAdd(createOption("Y14"), 2147483647)', "0,1,2,Y14");
     44shouldBeEqualToString('testAdd(createOption("Y15"), 2147483648)', "0,1,2,Y15");
     45shouldBeEqualToString('testAdd(createOption("Y16"), -2147483647)', "0,1,2,Y16");
     46shouldBeEqualToString('testAdd(createOption("Y17"), -2147483648)', "0,1,2,Y17");
     47shouldBeEqualToString('testAdd(createOption("Y18"), -2147483649)', "0,1,2,Y18");
     48shouldBeEqualToString('testAdd(createOption("Y19"), Infinity)', "Y19,0,1,2");
     49shouldBeEqualToString('testAdd(createOption("Y20"), -Infinity)', "Y20,0,1,2");
     50shouldBeEqualToString('testAdd(createOption("Y21"), "foo")', "Y21,0,1,2");
     51shouldBeEqualToString('testAdd(createOption("Y22"), NaN)', "Y22,0,1,2");
     52shouldBeEqualToString('testAdd(createOption("Y23"), undefined)', "Y23,0,1,2");
     53shouldBeEqualToString('testAdd(createOption("Y24"), -2)', "0,1,2,Y24");
     54shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[0])', "X,0,1,2");
     55shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[1])', "0,X,1,2");
     56shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[2])', "0,1,X,2");
     57shouldThrow('testAdd("foo", 0)', "'TypeError: Type error'");
     58shouldThrow('testAdd(undefined, 0)', "'TypeError: Type error'");
     59shouldThrow('testAdd(null, 0)', "'TypeError: Type error'");
    4160
    42 function testAdd4(newelement, element, index) {
    43     resetSelection();
    44     mySelect.add(newelement, element, index);
    45     return deepCopy();
    46 }
    47 
    48 resetSelection();
    49 debug('list elements are = ' + deepCopy());
    50 shouldBeEqualToString('testAdd1(createOption("Y1"))', '0,1,2,Y1');
    51 shouldBeEqualToString('testAdd3(createOption("Y2"), null)', '0,1,2,Y2');
    52 shouldBeEqualToString('testAdd3(createOption("Y3"), 0)', 'Y3,0,1,2');
    53 shouldBeEqualToString('testAdd3(createOption("Y4"), 1)', '0,Y4,1,2');
    54 shouldBeEqualToString('testAdd3(createOption("Y5"), 2)', '0,1,Y5,2');
    55 shouldBeEqualToString('testAdd3(createOption("Y6"), 3)', '0,1,2,Y6');
    56 shouldBeEqualToString('testAdd3(createOption("Y7"), 100)', '0,1,2,Y7');
    57 shouldBeEqualToString('testAdd3(createOption("Y8"), -100)', '0,1,2,Y8');
    58 shouldBeEqualToString('testAdd3(createOption("Y9"), "0")', 'Y9,0,1,2');
    59 shouldBeEqualToString('testAdd3(createOption("Y10"), "1")', '0,Y10,1,2');
    60 shouldBeEqualToString('testAdd3(createOption("Y11"), "2")', '0,1,Y11,2');
    61 shouldBeEqualToString('testAdd3(createOption("Y12"), true)', '0,Y12,1,2');
    62 shouldBeEqualToString('testAdd3(createOption("Y13"), false)', 'Y13,0,1,2');
    63 shouldBeEqualToString('testAdd3(createOption("Y14"), 2147483647)', '0,1,2,Y14');
    64 shouldBeEqualToString('testAdd3(createOption("Y15"), 2147483648)', '0,1,2,Y15');
    65 shouldBeEqualToString('testAdd3(createOption("Y16"), -2147483647)', '0,1,2,Y16');
    66 shouldBeEqualToString('testAdd3(createOption("Y17"), -2147483648)', '0,1,2,Y17');
    67 shouldBeEqualToString('testAdd3(createOption("Y18"), -2147483649)', '0,1,2,Y18');
    68 shouldBeEqualToString('testAdd3(createOption("Y19"), Infinity)', 'Y19,0,1,2');
    69 shouldBeEqualToString('testAdd3(createOption("Y20"), -Infinity)', 'Y20,0,1,2');
    70 shouldBeEqualToString('testAdd3(createOption("Y21"), "foo")', 'Y21,0,1,2');
    71 shouldBeEqualToString('testAdd3(createOption("Y22"), NaN)', 'Y22,0,1,2');
    72 shouldBeEqualToString('testAdd3(createOption("Y23"), undefined)', 'Y23,0,1,2');
    73 shouldBeEqualToString('testAdd3(createOption("Y24"), -2)','0,1,2,Y24');
    74 shouldThrow('testAdd4(createOption("Y25"), 0, 1)');
    75 shouldThrow('testAdd4(createOption("Y25"), mySelect.options[0], 1)');
    76 resetSelection();
    77 debug('list elements are = ' + deepCopy());
    78 shouldThrow('mySelect.add("foo")');
    79 shouldThrow('mySelect.add("foo", 0)');
    80 shouldThrow('mySelect.add(undefined)');
    81 shouldThrow('mySelect.add(undefined, 0)');
    82 shouldThrow('mySelect.add(null, 0)');
    83 shouldThrow('mySelect.add(null)');
    84 shouldThrow('mySelect.add()');
    85        
     61debug("<br>Call HTMLSelectElement.add() with three arguments (when it only takes two arguments):");
     62shouldBeEqualToString('testAdd(createOption("X"), 0, "unnecessary extra argument - should be ignored")', "X,0,1,2");
     63shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[1], "unnecessary extra argument - should be ignored")', "0,X,1,2");
    8664</script>
    8765</body>
  • trunk/LayoutTests/fast/dom/HTMLSelectElement/options-collection-add-expected.txt

    r178097 r186265  
    44
    55
    6 list elements are = 0,1,2
    7 PASS testAdd3(createGroup("Y1", "Y2"), null) is "0,1,2,Y1,Y2"
    8 PASS testAdd3(createGroup("Y3", "Y4"), 0) is "Y3,Y4,0,1,2"
    9 PASS testAdd3(createGroup("Y5", "Y6"), 2) is "0,1,Y5,Y6,2"
    10 PASS testAdd1(createGroup("Y7", "Y8")) is "0,1,2,Y7,Y8"
    11 PASS testAdd1(createOption("Y9")) is "0,1,2,Y9"
    12 list elements are = 0,1,2
    13 PASS testAdd2(createOption("Y10"), mySelect.options[2]) is "0,1,Y10,2"
    14 PASS testAdd2(createOption("Y11"), mySelect.options[1]) is "0,Y11,1,Y10,2"
    15 list elements are = 0,1,2
    16 PASS testAdd2(createGroup("Y12", "Y13"), mySelect.options[1]) is "0,Y12,Y13,1,2"
    17 PASS testAdd2(createGroup("Y14", "Y15"), mySelect.options[3]) is "0,Y12,Y13,Y14,Y15,1,2"
    18 list elements are = 0,1,2
    19 PASS testAdd2(createOption("Y16"), createOption("Y17")) threw exception Error: NotFoundError: DOM Exception 8.
    20 list elements are = 0,1,2
    21 PASS testAdd1(createOption("Y1")) is "0,1,2,Y1"
    22 PASS testAdd3(createOption("Y2"), null) is "0,1,2,Y2"
    23 PASS testAdd3(createOption("Y3"), 0) is "Y3,0,1,2"
    24 PASS testAdd3(createOption("Y4"), 1) is "0,Y4,1,2"
    25 PASS testAdd3(createOption("Y5"), 2) is "0,1,Y5,2"
    26 PASS testAdd3(createOption("Y6"), 3) is "0,1,2,Y6"
    27 PASS testAdd3(createOption("Y7"), 100) is "0,1,2,Y7"
    28 PASS testAdd3(createOption("Y8"), -100) is "0,1,2,Y8"
    29 PASS testAdd3(createOption("Y9"), "0") is "Y9,0,1,2"
    30 PASS testAdd3(createOption("Y10"), "1") is "0,Y10,1,2"
    31 PASS testAdd3(createOption("Y11"), "2") is "0,1,Y11,2"
    32 PASS testAdd3(createOption("Y12"), true) is "0,Y12,1,2"
    33 PASS testAdd3(createOption("Y13"), false) is "Y13,0,1,2"
    34 PASS testAdd3(createOption("Y14"), 2147483647) is "0,1,2,Y14"
    35 PASS testAdd3(createOption("Y15"), 2147483648) is "0,1,2,Y15"
    36 PASS testAdd3(createOption("Y16"), -2147483647) is "0,1,2,Y16"
    37 PASS testAdd3(createOption("Y17"), -2147483648) is "0,1,2,Y17"
    38 PASS testAdd3(createOption("Y18"), -2147483649) is "0,1,2,Y18"
    39 PASS testAdd3(createOption("Y19"), Infinity) is "Y19,0,1,2"
    40 PASS testAdd3(createOption("Y20"), -Infinity) is "Y20,0,1,2"
    41 PASS testAdd3(createOption("Y21"), "foo") is "Y21,0,1,2"
    42 PASS testAdd3(createOption("Y22"), NaN) is "Y22,0,1,2"
    43 PASS testAdd3(createOption("Y23"), undefined) is "Y23,0,1,2"
    44 PASS testAdd3(createOption("Y24"), -2) is "0,1,2,Y24"
    45 PASS testAdd4(createOption("Y25"), 0, 1) threw exception TypeError: Type error.
    46 PASS testAdd4(createOption("Y25"), mySelect.options[0], 1) threw exception TypeError: Type error.
    47 list elements are = 0,1,2
    48 PASS mySelect.options.add("foo") threw exception TypeError: Type error.
    49 PASS mySelect.options.add("foo", 0) threw exception TypeError: Type error.
    50 PASS mySelect.options.add(undefined) threw exception TypeError: Type error.
    51 PASS mySelect.options.add(undefined, 0) threw exception TypeError: Type error.
    52 PASS mySelect.options.add(null, 0) threw exception TypeError: Type error.
    53 PASS mySelect.options.add(null) threw exception TypeError: Type error.
    54 PASS mySelect.options.add() threw exception TypeError: Not enough arguments.
     6
     7Call HTMLOptionsCollection.add() with zero arguments:
     8PASS testAdd() threw exception TypeError: Not enough arguments.
     9
     10Call HTMLOptionsCollection.add() with only one argument:
     11PASS testAdd(createOption("Y9")) is "0,1,2,Y9"
     12PASS testAdd("foo") threw exception TypeError: Type error.
     13PASS testAdd(undefined) threw exception TypeError: Type error.
     14PASS testAdd(null) threw exception TypeError: Type error.
     15
     16Call HTMLOptionsCollection.add() with two arguments:
     17PASS testAdd(createGroup("Y1", "Y2"), null) is "0,1,2,Y1,Y2"
     18PASS testAdd(createGroup("Y3", "Y4"), 0) is "Y3,Y4,0,1,2"
     19PASS testAdd(createGroup("Y5", "Y6"), 2) is "0,1,Y5,Y6,2"
     20PASS testAdd(createGroup("Y7", "Y8")) is "0,1,2,Y7,Y8"
     21PASS testAddWithoutResettingListOptions(createOption("Y10"), mySelect.options[2]) is "0,1,Y10,2"
     22PASS testAdd(createOption("Y11"), mySelect.options[1]) is "0,Y11,1,Y10,2"
     23PASS testAddWithoutResettingListOptions(createGroup("Y12", "Y13"), mySelect.options[1]) is "0,Y12,Y13,1,2"
     24PASS testAdd(createGroup("Y14", "Y15"), mySelect.options[3]) is "0,Y12,Y13,Y14,Y15,1,2"
     25PASS testAdd(createOption("Y16"), createOption("Y17")) threw exception Error: NotFoundError: DOM Exception 8.
     26PASS testAdd(createOption("Y1")) is "0,1,2,Y1"
     27PASS testAdd(createOption("Y2"), null) is "0,1,2,Y2"
     28PASS testAdd(createOption("Y3"), 0) is "Y3,0,1,2"
     29PASS testAdd(createOption("Y4"), 1) is "0,Y4,1,2"
     30PASS testAdd(createOption("Y5"), 2) is "0,1,Y5,2"
     31PASS testAdd(createOption("Y6"), 3) is "0,1,2,Y6"
     32PASS testAdd(createOption("Y7"), 100) is "0,1,2,Y7"
     33PASS testAdd(createOption("Y8"), -100) is "0,1,2,Y8"
     34PASS testAdd(createOption("Y9"), "0") is "Y9,0,1,2"
     35PASS testAdd(createOption("Y10"), "1") is "0,Y10,1,2"
     36PASS testAdd(createOption("Y11"), "2") is "0,1,Y11,2"
     37PASS testAdd(createOption("Y12"), true) is "0,Y12,1,2"
     38PASS testAdd(createOption("Y13"), false) is "Y13,0,1,2"
     39PASS testAdd(createOption("Y14"), 2147483647) is "0,1,2,Y14"
     40PASS testAdd(createOption("Y15"), 2147483648) is "0,1,2,Y15"
     41PASS testAdd(createOption("Y16"), -2147483647) is "0,1,2,Y16"
     42PASS testAdd(createOption("Y17"), -2147483648) is "0,1,2,Y17"
     43PASS testAdd(createOption("Y18"), -2147483649) is "0,1,2,Y18"
     44PASS testAdd(createOption("Y19"), Infinity) is "Y19,0,1,2"
     45PASS testAdd(createOption("Y20"), -Infinity) is "Y20,0,1,2"
     46PASS testAdd(createOption("Y21"), "foo") is "Y21,0,1,2"
     47PASS testAdd(createOption("Y22"), NaN) is "Y22,0,1,2"
     48PASS testAdd(createOption("Y23"), undefined) is "Y23,0,1,2"
     49PASS testAdd(createOption("Y24"), -2) is "0,1,2,Y24"
     50PASS testAdd(createOption("X"), mySelect.options[0]) is "X,0,1,2"
     51PASS testAdd(createOption("X"), mySelect.options[1]) is "0,X,1,2"
     52PASS testAdd(createOption("X"), mySelect.options[2]) is "0,1,X,2"
     53PASS testAdd(createOption("Y25"), 0, 1) is "Y25,0,1,2"
     54PASS testAdd(createOption("Y25"), mySelect.options[0], 1) is "Y25,0,1,2"
     55PASS testAdd("foo", 0) threw exception TypeError: Type error.
     56PASS testAdd(undefined, 0) threw exception TypeError: Type error.
     57PASS testAdd(null, 0) threw exception TypeError: Type error.
     58
     59Call HTMLOptionsCollection.add() with three arguments (when it only takes two arguments):
     60PASS testAdd(createOption("X"), 0, "unnecessary extra argument - should be ignored") is "X,0,1,2"
     61PASS testAdd(createOption("X"), mySelect.options[1], "unnecessary extra argument - should be ignored") is "0,X,1,2"
     62PASS testAdd(createGroup("G1", "G2"), 1, "unnecessary extra argument - should be ignored") is "0,G1,G2,1,2"
    5563PASS successfullyParsed is true
    5664
  • trunk/LayoutTests/fast/dom/HTMLSelectElement/options-collection-add.html

    r178097 r186265  
    33<head>
    44<script src="../../../resources/js-test.js"></script>
     5<script src="resources/html-select-and-options-collection-utilities.js"></script>
    56</head>
    67<body>
    78<script>
    89description('Test select.options.add() with optgroup and with index parameter');
    9        
    10 var mySelect;
    1110
    12 function resetSelection() {
    13     mySelect = document.createElement('select');
    14     mySelect.appendChild(new Option("0", "0", false, false));
    15     mySelect.appendChild(new Option("1", "1", false, false));
    16     mySelect.appendChild(new Option("2", "2", false, false));
     11var mySelect = createSelectElementWithTestData();
     12
     13function testAdd()
     14{
     15    HTMLOptionsCollection.prototype.add.apply(mySelect.options, arguments);
     16    var result = deepCopy(mySelect);
     17    mySelect = createSelectElementWithTestData(); // Reset
     18    return result;
    1719}
    1820
    19 function deepCopy() {
    20     var copy = [];
    21     for(var i = 0; i < mySelect.options.length; ++i)
    22         copy.push(mySelect.options[i].value);
    23     return copy.join(",");
    24 }
    25        
    26 function createOption(value) {
    27     return new Option(value + "X", value, false, false);
     21function testAddWithoutResettingListOptions()
     22{
     23    HTMLOptionsCollection.prototype.add.apply(mySelect.options, arguments);
     24    return deepCopy(mySelect);
    2825}
    2926
    30 function 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 }
     27debug("<br>Call HTMLOptionsCollection.add() with zero arguments:");
     28shouldThrow("testAdd()");
    3629
    37 function testAdd1(element) {
    38     resetSelection();
    39     mySelect.options.add(element);
    40     return deepCopy();
    41 }
     30debug("<br>Call HTMLOptionsCollection.add() with only one argument:");
     31shouldBeEqualToString('testAdd(createOption("Y9"))', "0,1,2,Y9");
     32shouldThrow('testAdd("foo")');
     33shouldThrow("testAdd(undefined)");
     34shouldThrow("testAdd(null)");
    4235
    43 function testAdd2(newelement, element) {
    44     mySelect.options.add(newelement, element);
    45     return deepCopy();
    46 }
     36debug("<br>Call HTMLOptionsCollection.add() with two arguments:");
     37shouldBeEqualToString('testAdd(createGroup("Y1", "Y2"), null)', "0,1,2,Y1,Y2");
     38shouldBeEqualToString('testAdd(createGroup("Y3", "Y4"), 0)', "Y3,Y4,0,1,2");
     39shouldBeEqualToString('testAdd(createGroup("Y5", "Y6"), 2)', "0,1,Y5,Y6,2");
     40shouldBeEqualToString('testAdd(createGroup("Y7", "Y8"))', "0,1,2,Y7,Y8");
    4741
    48 function testAdd3(newelement, index) {
    49     resetSelection();
    50     mySelect.options.add(newelement, index);
    51     return deepCopy();
    52 }
     42shouldBeEqualToString('testAddWithoutResettingListOptions(createOption("Y10"), mySelect.options[2])', "0,1,Y10,2");
     43shouldBeEqualToString('testAdd(createOption("Y11"), mySelect.options[1])', "0,Y11,1,Y10,2");
    5344
    54 function testAdd4(newelement, element, index) {
    55     resetSelection();
    56     mySelect.options.add(newelement, element, index);
    57     return deepCopy();
    58 }
     45shouldBeEqualToString('testAddWithoutResettingListOptions(createGroup("Y12", "Y13"), mySelect.options[1])', "0,Y12,Y13,1,2");
     46shouldBeEqualToString('testAdd(createGroup("Y14", "Y15"), mySelect.options[3])', "0,Y12,Y13,Y14,Y15,1,2");
    5947
    60 resetSelection();
    61 debug('list elements are = ' + deepCopy());
    62 shouldBeEqualToString('testAdd3(createGroup("Y1", "Y2"), null)', '0,1,2,Y1,Y2');
    63 shouldBeEqualToString('testAdd3(createGroup("Y3", "Y4"), 0)', 'Y3,Y4,0,1,2');
    64 shouldBeEqualToString('testAdd3(createGroup("Y5", "Y6"), 2)', '0,1,Y5,Y6,2');
    65 shouldBeEqualToString('testAdd1(createGroup("Y7", "Y8"))', '0,1,2,Y7,Y8');
    66 shouldBeEqualToString('testAdd1(createOption("Y9"))', '0,1,2,Y9');
    67 resetSelection();
    68 debug('list elements are = ' + deepCopy());
    69 shouldBeEqualToString('testAdd2(createOption("Y10"), mySelect.options[2])', '0,1,Y10,2');
    70 shouldBeEqualToString('testAdd2(createOption("Y11"), mySelect.options[1])', '0,Y11,1,Y10,2');
    71 resetSelection();
    72 debug('list elements are = ' + deepCopy());
    73 shouldBeEqualToString('testAdd2(createGroup("Y12", "Y13"), mySelect.options[1])', '0,Y12,Y13,1,2');
    74 shouldBeEqualToString('testAdd2(createGroup("Y14", "Y15"), mySelect.options[3])', '0,Y12,Y13,Y14,Y15,1,2');
    75 resetSelection();
    76 debug('list elements are = ' + deepCopy());
    77 shouldThrow('testAdd2(createOption("Y16"), createOption("Y17"))');
    78 resetSelection();
    79 debug('list elements are = ' + deepCopy());
    80 shouldBeEqualToString('testAdd1(createOption("Y1"))', '0,1,2,Y1');
    81 shouldBeEqualToString('testAdd3(createOption("Y2"), null)', '0,1,2,Y2');
    82 shouldBeEqualToString('testAdd3(createOption("Y3"), 0)', 'Y3,0,1,2');
    83 shouldBeEqualToString('testAdd3(createOption("Y4"), 1)', '0,Y4,1,2');
    84 shouldBeEqualToString('testAdd3(createOption("Y5"), 2)', '0,1,Y5,2');
    85 shouldBeEqualToString('testAdd3(createOption("Y6"), 3)', '0,1,2,Y6');
    86 shouldBeEqualToString('testAdd3(createOption("Y7"), 100)', '0,1,2,Y7');
    87 shouldBeEqualToString('testAdd3(createOption("Y8"), -100)', '0,1,2,Y8');
    88 shouldBeEqualToString('testAdd3(createOption("Y9"), "0")', 'Y9,0,1,2');
    89 shouldBeEqualToString('testAdd3(createOption("Y10"), "1")', '0,Y10,1,2');
    90 shouldBeEqualToString('testAdd3(createOption("Y11"), "2")', '0,1,Y11,2');
    91 shouldBeEqualToString('testAdd3(createOption("Y12"), true)', '0,Y12,1,2');
    92 shouldBeEqualToString('testAdd3(createOption("Y13"), false)', 'Y13,0,1,2');
    93 shouldBeEqualToString('testAdd3(createOption("Y14"), 2147483647)', '0,1,2,Y14');
    94 shouldBeEqualToString('testAdd3(createOption("Y15"), 2147483648)', '0,1,2,Y15');
    95 shouldBeEqualToString('testAdd3(createOption("Y16"), -2147483647)', '0,1,2,Y16');
    96 shouldBeEqualToString('testAdd3(createOption("Y17"), -2147483648)', '0,1,2,Y17');
    97 shouldBeEqualToString('testAdd3(createOption("Y18"), -2147483649)', '0,1,2,Y18');
    98 shouldBeEqualToString('testAdd3(createOption("Y19"), Infinity)', 'Y19,0,1,2');
    99 shouldBeEqualToString('testAdd3(createOption("Y20"), -Infinity)', 'Y20,0,1,2');
    100 shouldBeEqualToString('testAdd3(createOption("Y21"), "foo")', 'Y21,0,1,2');
    101 shouldBeEqualToString('testAdd3(createOption("Y22"), NaN)', 'Y22,0,1,2');
    102 shouldBeEqualToString('testAdd3(createOption("Y23"), undefined)', 'Y23,0,1,2');
    103 shouldBeEqualToString('testAdd3(createOption("Y24"), -2)','0,1,2,Y24');
    104 shouldThrow('testAdd4(createOption("Y25"), 0, 1)');
    105 shouldThrow('testAdd4(createOption("Y25"), mySelect.options[0], 1)');
    106 resetSelection();
    107 debug('list elements are = ' + deepCopy());
    108 shouldThrow('mySelect.options.add("foo")');
    109 shouldThrow('mySelect.options.add("foo", 0)');
    110 shouldThrow('mySelect.options.add(undefined)');
    111 shouldThrow('mySelect.options.add(undefined, 0)');
    112 shouldThrow('mySelect.options.add(null, 0)');
    113 shouldThrow('mySelect.options.add(null)');
    114 shouldThrow('mySelect.options.add()');
    115        
     48shouldThrow('testAdd(createOption("Y16"), createOption("Y17"))');
     49
     50shouldBeEqualToString('testAdd(createOption("Y1"))', "0,1,2,Y1");
     51shouldBeEqualToString('testAdd(createOption("Y2"), null)', "0,1,2,Y2");
     52shouldBeEqualToString('testAdd(createOption("Y3"), 0)', "Y3,0,1,2");
     53shouldBeEqualToString('testAdd(createOption("Y4"), 1)', "0,Y4,1,2");
     54shouldBeEqualToString('testAdd(createOption("Y5"), 2)', "0,1,Y5,2");
     55shouldBeEqualToString('testAdd(createOption("Y6"), 3)', "0,1,2,Y6");
     56shouldBeEqualToString('testAdd(createOption("Y7"), 100)', "0,1,2,Y7");
     57shouldBeEqualToString('testAdd(createOption("Y8"), -100)', "0,1,2,Y8");
     58shouldBeEqualToString('testAdd(createOption("Y9"), "0")', "Y9,0,1,2");
     59shouldBeEqualToString('testAdd(createOption("Y10"), "1")', "0,Y10,1,2");
     60shouldBeEqualToString('testAdd(createOption("Y11"), "2")', "0,1,Y11,2");
     61shouldBeEqualToString('testAdd(createOption("Y12"), true)', "0,Y12,1,2");
     62shouldBeEqualToString('testAdd(createOption("Y13"), false)', "Y13,0,1,2");
     63shouldBeEqualToString('testAdd(createOption("Y14"), 2147483647)', "0,1,2,Y14");
     64shouldBeEqualToString('testAdd(createOption("Y15"), 2147483648)', "0,1,2,Y15");
     65shouldBeEqualToString('testAdd(createOption("Y16"), -2147483647)', "0,1,2,Y16");
     66shouldBeEqualToString('testAdd(createOption("Y17"), -2147483648)', "0,1,2,Y17");
     67shouldBeEqualToString('testAdd(createOption("Y18"), -2147483649)', "0,1,2,Y18");
     68shouldBeEqualToString('testAdd(createOption("Y19"), Infinity)', "Y19,0,1,2");
     69shouldBeEqualToString('testAdd(createOption("Y20"), -Infinity)', "Y20,0,1,2");
     70shouldBeEqualToString('testAdd(createOption("Y21"), "foo")', "Y21,0,1,2");
     71shouldBeEqualToString('testAdd(createOption("Y22"), NaN)', "Y22,0,1,2");
     72shouldBeEqualToString('testAdd(createOption("Y23"), undefined)', "Y23,0,1,2");
     73shouldBeEqualToString('testAdd(createOption("Y24"), -2)', "0,1,2,Y24");
     74shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[0])', "X,0,1,2");
     75shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[1])', "0,X,1,2");
     76shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[2])', "0,1,X,2");
     77shouldBeEqualToString('testAdd(createOption("Y25"), 0, 1)', "Y25,0,1,2");
     78shouldBeEqualToString('testAdd(createOption("Y25"), mySelect.options[0], 1)', "Y25,0,1,2");
     79shouldThrow('testAdd("foo", 0)', "'TypeError: Type error'");
     80shouldThrow('testAdd(undefined, 0)', "'TypeError: Type error'");
     81shouldThrow('testAdd(null, 0)', "'TypeError: Type error'");
     82
     83debug("<br>Call HTMLOptionsCollection.add() with three arguments (when it only takes two arguments):");
     84shouldBeEqualToString('testAdd(createOption("X"), 0, "unnecessary extra argument - should be ignored")', "X,0,1,2");
     85shouldBeEqualToString('testAdd(createOption("X"), mySelect.options[1], "unnecessary extra argument - should be ignored")', "0,X,1,2");
     86shouldBeEqualToString('testAdd(createGroup("G1", "G2"), 1, "unnecessary extra argument - should be ignored")', "0,G1,G2,1,2");
    11687</script>
    11788</body>
  • trunk/Source/WebCore/ChangeLog

    r186263 r186265  
     12015-07-03  Daniel Bates  <dabates@apple.com>
     2
     3        REGRESSION (r178097): JavaScript TypeError after clicking on compose button in Yahoo Mail
     4        https://bugs.webkit.org/show_bug.cgi?id=146515
     5        <rdar://problem/21348421>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Fixes an issue where extra arguments passed to a Web IDL overloaded function, whose implementation
     10        is generated by the bindings generator script, are not ignored as per the note in section "Interface object [[Call]] method"
     11        of the Web IDL spec, <http://www.w3.org/TR/2012/CR-WebIDL-20120419/> (19 April 2012).
     12
     13        Currently for an overloaded function the JavaScript bindings generator script emits code to
     14        throw a TypeError when it cannot find a candidate function that takes the same number of
     15        arguments as passed by a caller. Prior to the change made in bug #139179 (r178097), the
     16        bindings code for HTMLSelectElement.add() was written by hand and ignored extra arguments
     17        that were passed to it. Following this change, the bindings code for HTMLSelectElement.add()
     18        is generated by the bindings generator script. Therefore, we throw a TypeError when Yahoo Mail
     19        calls HTMLSelectElement.add() with extra arguments because the code emitted by the bindings
     20        generator script does not ignore them.
     21
     22        * bindings/scripts/CodeGeneratorJS.pm:
     23        (LengthOfLongestFunctionParameterList): Added. Computes the length of longest overload parameter list.
     24        (GenerateOverloadedFunction): Emit code that ignores more arguments than LengthOfLongestFunctionParameterList().
     25        (GenerateOverloadedConstructorDefinition): Ditto.
     26        * bindings/scripts/test/JS/JSTestObj.cpp:
     27        (WebCore::jsTestObjPrototypeFunctionOverloadedMethod12): Added; expected result for an overloaded
     28        function that takes a variadic number of Blob elements.
     29        (WebCore::jsTestObjPrototypeFunctionOverloadedMethod): Update expected result. The added
     30        if-conditional expression for the IDL declaration overloadedMethod(Blob... blobArgs) is empty
     31        because we do not support overloading of functions with variadic arguments.
     32        (WebCore::jsTestObjConstructorFunctionOverloadedMethod1):
     33        * bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp:
     34        (WebCore::JSTestOverloadedConstructorsConstructor::constructJSTestOverloadedConstructors5): Added; expected
     35        result for an overloaded constructors that takes a variadic number of long arguments.
     36        (WebCore::JSTestOverloadedConstructorsConstructor::constructJSTestOverloadedConstructors): Update expected
     37        result. The added if-conditional expression for the IDL declaration Constructor(long... longArgs) is empty
     38        because we do not support overloading of constructors with variadic arguments.
     39        * bindings/scripts/test/TestObj.idl: Added declaration overloadedMethod(Blob...). Also fixed
     40        typo in license block text.
     41        * bindings/scripts/test/TestOverloadedConstructors.idl: Added declaration Constructor(long... longArgs).
     42        Also fixed typo in license block text.
     43
    1442015-07-03  Mario Sanchez Prada  <mario@endlessm.com>
    245
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r186257 r186265  
    14541454}
    14551455
     1456sub LengthOfLongestFunctionParameterList
     1457{
     1458    my ($overloads) = @_;
     1459    my $result = 0;
     1460    foreach my $overload (@{$overloads}) {
     1461        my @parameters = @{$overload->parameters};
     1462        $result = @parameters if $result < @parameters;
     1463    }
     1464    return $result;
     1465}
     1466
    14561467sub GenerateOverloadedFunction
    14571468{
     
    14691480    my $functionName = "js${interfaceName}${kind}Function" . $codeGenerator->WK_ucfirst($function->signature->name);
    14701481
     1482    # FIXME: Implement support for overloaded functions with variadic arguments.
     1483    my $lengthOfLongestOverloadedFunctionParameterList = LengthOfLongestFunctionParameterList($function->{overloads});
     1484
    14711485    push(@implContent, "EncodedJSValue JSC_HOST_CALL ${functionName}(ExecState* exec)\n");
    14721486    push(@implContent, <<END);
    14731487{
    1474     size_t argsCount = exec->argumentCount();
     1488    size_t argsCount = std::min<size_t>($lengthOfLongestOverloadedFunctionParameterList, exec->argumentCount());
    14751489END
    14761490
     
    45014515
    45024516    my $functionName = "${className}Constructor::construct${className}";
     4517
     4518    # FIXME: Implement support for overloaded constructors with variadic arguments.
     4519    my $lengthOfLongestOverloadedConstructorParameterList = LengthOfLongestFunctionParameterList($interface->constructors);
     4520
    45034521    push(@$outputArray, <<END);
    45044522EncodedJSValue JSC_HOST_CALL ${functionName}(ExecState* exec)
    45054523{
    4506     size_t argsCount = exec->argumentCount();
     4524    size_t argsCount = std::min<size_t>($lengthOfLongestOverloadedConstructorParameterList, exec->argumentCount());
    45074525END
    45084526
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r186257 r186265  
    39193919}
    39203920
     3921static EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadedMethod12(ExecState* exec)
     3922{
     3923    JSValue thisValue = exec->thisValue();
     3924    JSTestObj* castedThis = jsDynamicCast<JSTestObj*>(thisValue);
     3925    if (UNLIKELY(!castedThis))
     3926        return throwThisTypeError(*exec, "TestObj", "overloadedMethod");
     3927    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
     3928    auto& impl = castedThis->impl();
     3929    Vector<Blob*> blobArgs;
     3930    for (unsigned i = 0, count = exec->argumentCount(); i < count; ++i) {
     3931        if (!exec->uncheckedArgument(i).inherits(JSBlob::info()))
     3932            return throwArgumentTypeError(*exec, i, "blobArgs", "TestObj", "overloadedMethod", "Blob");
     3933        blobArgs.append(JSBlob::toWrapped(exec->uncheckedArgument(i)));
     3934    }
     3935    impl.overloadedMethod(blobArgs);
     3936    return JSValue::encode(jsUndefined());
     3937}
     3938
    39213939EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadedMethod(ExecState* exec)
    39223940{
    3923     size_t argsCount = exec->argumentCount();
     3941    size_t argsCount = std::min<size_t>(2, exec->argumentCount());
    39243942    JSValue arg0(exec->argument(0));
    39253943    JSValue arg1(exec->argument(1));
     
    39463964    if (argsCount == 1)
    39473965        return jsTestObjPrototypeFunctionOverloadedMethod11(exec);
     3966    if ()
     3967        return jsTestObjPrototypeFunctionOverloadedMethod12(exec);
    39483968    if (argsCount < 1)
    39493969        return throwVMError(exec, createNotEnoughArgumentsError(exec));
     
    40104030EncodedJSValue JSC_HOST_CALL jsTestObjConstructorFunctionOverloadedMethod1(ExecState* exec)
    40114031{
    4012     size_t argsCount = exec->argumentCount();
     4032    size_t argsCount = std::min<size_t>(1, exec->argumentCount());
    40134033#if ENABLE(Condition1)
    40144034    if (argsCount == 1)
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp

    r185373 r186265  
    8787    static JSC::EncodedJSValue JSC_HOST_CALL constructJSTestOverloadedConstructors3(JSC::ExecState*);
    8888    static JSC::EncodedJSValue JSC_HOST_CALL constructJSTestOverloadedConstructors4(JSC::ExecState*);
     89    static JSC::EncodedJSValue JSC_HOST_CALL constructJSTestOverloadedConstructors5(JSC::ExecState*);
    8990    static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&);
    9091};
     
    138139}
    139140
     141EncodedJSValue JSC_HOST_CALL JSTestOverloadedConstructorsConstructor::constructJSTestOverloadedConstructors5(ExecState* exec)
     142{
     143    auto* castedThis = jsCast<JSTestOverloadedConstructorsConstructor*>(exec->callee());
     144    Vector<int> longArgs = toNativeArguments<int>(exec, 0);
     145    if (UNLIKELY(exec->hadException()))
     146        return JSValue::encode(jsUndefined());
     147    RefPtr<TestOverloadedConstructors> object = TestOverloadedConstructors::create(longArgs);
     148    return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), object.get())));
     149}
     150
    140151EncodedJSValue JSC_HOST_CALL JSTestOverloadedConstructorsConstructor::constructJSTestOverloadedConstructors(ExecState* exec)
    141152{
    142     size_t argsCount = exec->argumentCount();
     153    size_t argsCount = std::min<size_t>(1, exec->argumentCount());
    143154    JSValue arg0(exec->argument(0));
    144155    if ((argsCount == 1 && (arg0.isObject() && asObject(arg0)->inherits(JSArrayBuffer::info()))))
     
    150161    if (argsCount == 1)
    151162        return JSTestOverloadedConstructorsConstructor::constructJSTestOverloadedConstructors4(exec);
     163    if ()
     164        return JSTestOverloadedConstructorsConstructor::constructJSTestOverloadedConstructors5(exec);
    152165    if (argsCount < 1)
    153166        return throwVMError(exec, createNotEnoughArgumentsError(exec));
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r186257 r186265  
    1717 *
    1818 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
    19  * EXPRESS OR IMPLIED WARRANTIEstrArg, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    2020 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    2121 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     
    188188    void    overloadedMethod(sequence<unsigned long> arrayArg);
    189189    void    overloadedMethod(DOMString strArg);
     190
     191    // FIXME: Implement support for overloaded functions with variadic arguments.
     192    void    overloadedMethod(Blob... blobArgs);
    190193#endif
    191194
  • trunk/Source/WebCore/bindings/scripts/test/TestOverloadedConstructors.idl

    r165676 r186265  
    1616 *
    1717 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
    18  * EXPRESS OR IMPLIED WARRANTIEstrArg, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1919 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    2020 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     
    3131    Constructor(Blob blob),
    3232    Constructor(DOMString string),
     33    Constructor(long... longArgs) // FIXME: Implement support for overloaded constructors with variadic arguments.
    3334] interface TestOverloadedConstructors {
    3435};
Note: See TracChangeset for help on using the changeset viewer.