Title: [207497] trunk
Revision
207497
Author
cdu...@apple.com
Date
2016-10-18 16:18:20 -0700 (Tue, 18 Oct 2016)

Log Message

Leverage new union type support for HTMLSelectElement.add() / HTMLOptionsCollection.add()
https://bugs.webkit.org/show_bug.cgi?id=163608

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline W3C test now that one more check is passing. This is because we are now
correctly throwing a TypeError when calling add() with an unexpected HTMLElement type.

* web-platform-tests/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection-expected.txt:

Source/WebCore:

Leverage new union type support for HTMLSelectElement.add() / HTMLOptionsCollection.add():
- https://html.spec.whatwg.org/#htmlselectelement
- https://html.spec.whatwg.org/#htmloptionscollection

No new tests, rebaseline existing test.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateDefaultValue):
(GenerateParametersCheck):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionMethodWithOptionalSequenceIsEmptyCaller):
* bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.cpp:
(WebCore::constructJSTestOverloadedConstructorsWithSequence1):
* bindings/scripts/test/JS/JSTestTypedefs.cpp:
(WebCore::jsTestTypedefsPrototypeFunctionFuncCaller):
* html/HTMLOptGroupElement.idl:
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::add):
* html/HTMLOptionsCollection.h:
* html/HTMLOptionsCollection.idl:
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::add):
(WebCore::HTMLSelectElement::setOption):
(WebCore::HTMLSelectElement::setLength):
* html/HTMLSelectElement.h:
* html/HTMLSelectElement.idl:

Source/WebKit/mac:

Update add() call sites now that it takes std::variant types in.

* DOM/DOMHTMLOptionsCollection.mm:
(-[DOMHTMLOptionsCollection add:index:]):
* DOM/DOMHTMLSelectElement.mm:
(-[DOMHTMLSelectElement add:before:]):

LayoutTests:

Rebaseline existing tests now that exception messages are different.

* fast/dom/HTMLSelectElement/add-expected.txt:
* fast/dom/HTMLSelectElement/options-collection-add-expected.txt:
* fast/dom/incompatible-operations-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (207496 => 207497)


--- trunk/LayoutTests/ChangeLog	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/LayoutTests/ChangeLog	2016-10-18 23:18:20 UTC (rev 207497)
@@ -1,3 +1,16 @@
+2016-10-18  Chris Dumez  <cdu...@apple.com>
+
+        Leverage new union type support for HTMLSelectElement.add() / HTMLOptionsCollection.add()
+        https://bugs.webkit.org/show_bug.cgi?id=163608
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline existing tests now that exception messages are different.
+
+        * fast/dom/HTMLSelectElement/add-expected.txt:
+        * fast/dom/HTMLSelectElement/options-collection-add-expected.txt:
+        * fast/dom/incompatible-operations-expected.txt:
+
 2016-10-18  Ryosuke Niwa  <rn...@webkit.org>
 
         REGRESSION (r201471): Keyboard remains visible when swiping back on twitter.com

Modified: trunk/LayoutTests/fast/dom/HTMLSelectElement/add-expected.txt (207496 => 207497)


--- trunk/LayoutTests/fast/dom/HTMLSelectElement/add-expected.txt	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/LayoutTests/fast/dom/HTMLSelectElement/add-expected.txt	2016-10-18 23:18:20 UTC (rev 207497)
@@ -9,9 +9,9 @@
 
 Call HTMLSelectElement.add() with one argument:
 PASS testAdd(createOption("Y1")) is "0,1,2,Y1"
-PASS testAdd("foo") threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
-PASS testAdd(undefined) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
-PASS testAdd(null) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
+PASS testAdd("foo") threw exception TypeError: Type error.
+PASS testAdd(undefined) threw exception TypeError: Type error.
+PASS testAdd(null) threw exception TypeError: Type error.
 
 Call HTMLSelectElement.add() with two arguments:
 PASS testAdd(createOption("Y2"), null) is "0,1,2,Y2"
@@ -40,9 +40,9 @@
 PASS testAdd(createOption("X"), mySelect.options[0]) is "X,0,1,2"
 PASS testAdd(createOption("X"), mySelect.options[1]) is "0,X,1,2"
 PASS testAdd(createOption("X"), mySelect.options[2]) is "0,1,X,2"
-PASS testAdd("foo", 0) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
-PASS testAdd(undefined, 0) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
-PASS testAdd(null, 0) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
+PASS testAdd("foo", 0) threw exception TypeError: Type error.
+PASS testAdd(undefined, 0) threw exception TypeError: Type error.
+PASS testAdd(null, 0) threw exception TypeError: Type error.
 
 Call HTMLSelectElement.add() with three arguments (when it only takes two arguments):
 PASS testAdd(createOption("X"), 0, "unnecessary extra argument - should be ignored") is "X,0,1,2"

Modified: trunk/LayoutTests/fast/dom/HTMLSelectElement/options-collection-add-expected.txt (207496 => 207497)


--- trunk/LayoutTests/fast/dom/HTMLSelectElement/options-collection-add-expected.txt	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/LayoutTests/fast/dom/HTMLSelectElement/options-collection-add-expected.txt	2016-10-18 23:18:20 UTC (rev 207497)
@@ -9,9 +9,9 @@
 
 Call HTMLOptionsCollection.add() with only one argument:
 PASS testAdd(createOption("Y9")) is "0,1,2,Y9"
-PASS testAdd("foo") threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
-PASS testAdd(undefined) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
-PASS testAdd(null) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS testAdd("foo") threw exception TypeError: Type error.
+PASS testAdd(undefined) threw exception TypeError: Type error.
+PASS testAdd(null) threw exception TypeError: Type error.
 
 Call HTMLOptionsCollection.add() with two arguments:
 PASS testAdd(createGroup("Y1", "Y2"), null) is "0,1,2,Y1,Y2"
@@ -52,9 +52,9 @@
 PASS testAdd(createOption("X"), mySelect.options[2]) is "0,1,X,2"
 PASS testAdd(createOption("Y25"), 0, 1) is "Y25,0,1,2"
 PASS testAdd(createOption("Y25"), mySelect.options[0], 1) is "Y25,0,1,2"
-PASS testAdd("foo", 0) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
-PASS testAdd(undefined, 0) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
-PASS testAdd(null, 0) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS testAdd("foo", 0) threw exception TypeError: Type error.
+PASS testAdd(undefined, 0) threw exception TypeError: Type error.
+PASS testAdd(null, 0) threw exception TypeError: Type error.
 
 Call HTMLOptionsCollection.add() with three arguments (when it only takes two arguments):
 PASS testAdd(createOption("X"), 0, "unnecessary extra argument - should be ignored") is "X,0,1,2"

Modified: trunk/LayoutTests/fast/dom/incompatible-operations-expected.txt (207496 => 207497)


--- trunk/LayoutTests/fast/dom/incompatible-operations-expected.txt	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/LayoutTests/fast/dom/incompatible-operations-expected.txt	2016-10-18 23:18:20 UTC (rev 207497)
@@ -12,11 +12,11 @@
 PASS aNode.lookupPrefix(aDOMImplementation) is null
 PASS aNode.lookupPrefix(void 0) is null
 PASS aNode.cloneNode(aDOMImplementation) instanceof HTMLDivElement is true
-PASS aSelect.add(aDOMImplementation, aDOMImplementation) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
-PASS aSelect.add(aDOMImplementation, anOption) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
+PASS aSelect.add(aDOMImplementation, aDOMImplementation) threw exception TypeError: Type error.
+PASS aSelect.add(aDOMImplementation, anOption) threw exception TypeError: Type error.
 PASS aSelect.add(anOption, aDOMImplementation) is undefined.
-PASS aSelect.add(void 0, void 0) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
-PASS aSelect.add(void 0, anOption) threw exception TypeError: Argument 1 ('element') to HTMLSelectElement.add must be an instance of HTMLElement.
+PASS aSelect.add(void 0, void 0) threw exception TypeError: Type error.
+PASS aSelect.add(void 0, anOption) threw exception TypeError: Type error.
 PASS aSelect.add(anOption, void 0) is undefined.
 PASS successfullyParsed is true
 

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (207496 => 207497)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-10-18 23:18:20 UTC (rev 207497)
@@ -1,5 +1,17 @@
 2016-10-18  Chris Dumez  <cdu...@apple.com>
 
+        Leverage new union type support for HTMLSelectElement.add() / HTMLOptionsCollection.add()
+        https://bugs.webkit.org/show_bug.cgi?id=163608
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline W3C test now that one more check is passing. This is because we are now
+        correctly throwing a TypeError when calling add() with an unexpected HTMLElement type.
+
+        * web-platform-tests/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection-expected.txt:
+
+2016-10-18  Chris Dumez  <cdu...@apple.com>
+
         Update TrackEvent to stop using legacy [ConstructorTemplate=Event]
         https://bugs.webkit.org/show_bug.cgi?id=163580
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection-expected.txt (207496 => 207497)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection-expected.txt	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection-expected.txt	2016-10-18 23:18:20 UTC (rev 207497)
@@ -23,5 +23,5 @@
 PASS HTMLOptionsCollection.item(name) method return the item with index 0 
 PASS HTMLOptionsCollection.add method insert HTMLOptionElement Option element 
 PASS HTMLOptionsCollection.remove method remove Option element by index 
-FAIL Add non-option to collection assert_throws: function "function () {b_opts.add(add);}" did not throw
+PASS Add non-option to collection 
 

Modified: trunk/LayoutTests/js/dom/script-tests/select-options-add.js (207496 => 207497)


--- trunk/LayoutTests/js/dom/script-tests/select-options-add.js	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/LayoutTests/js/dom/script-tests/select-options-add.js	2016-10-18 23:18:20 UTC (rev 207497)
@@ -53,8 +53,8 @@
 debug("");
 
 debug("1.4 Add a non-Option element");
-option1 = document.createElement("DIV");
-shouldBeUndefined("select1.options.add(option1)");
+div = document.createElement("DIV");
+shouldThrowErrorName("select1.options.add(div)", "TypeError");
 shouldBe("select1.options.length", "3");
 shouldBe("select1.selectedIndex", "0");
 debug("");
@@ -264,8 +264,8 @@
 debug("");
 
 debug("2.12 Add a non-Option element");
-option2 = document.createElement("DIV");
-shouldBeUndefined("select2.options.add(option2, 1)");
+div = document.createElement("DIV");
+shouldThrowErrorName("select2.options.add(div, 1)", "TypeError");
 shouldBe("select2.options.length", "11");
 shouldBe("select2.selectedIndex", "4");
 debug("");

Modified: trunk/LayoutTests/js/dom/select-options-add-expected.txt (207496 => 207497)


--- trunk/LayoutTests/js/dom/select-options-add-expected.txt	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/LayoutTests/js/dom/select-options-add-expected.txt	2016-10-18 23:18:20 UTC (rev 207497)
@@ -29,47 +29,47 @@
 PASS select1.options[2].textContent is 'C'
 
 1.4 Add a non-Option element
-PASS select1.options.add(option1) is undefined.
+PASS select1.options.add(div) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
 1.5 Add a non-element (string)
-PASS select1.options.add(option1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select1.options.add(option1) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
 1.6 Add a non-element (number)
-PASS select1.options.add(option1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select1.options.add(option1) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
 1.7 Add a non-element (boolean)
-PASS select1.options.add(option1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select1.options.add(option1) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
 1.8 Add undefined
-PASS select1.options.add(option1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select1.options.add(option1) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
 1.9 Add null
-PASS select1.options.add(option1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select1.options.add(option1) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
 1.10 Add negative infinity
-PASS select1.options.add(option1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select1.options.add(option1) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
 1.11 Add NaN
-PASS select1.options.add(option1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select1.options.add(option1) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
 1.12 Add positive infinity
-PASS select1.options.add(option1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select1.options.add(option1) threw exception TypeError: Type error.
 PASS select1.options.length is 3
 PASS select1.selectedIndex is 0
 
@@ -178,47 +178,47 @@
 PASS select2.selectedIndex is 4
 
 2.12 Add a non-Option element
-PASS select2.options.add(option2, 1) is undefined.
+PASS select2.options.add(div, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 
 2.13 Add a non-element (string)
-PASS select2.options.add(option2, 1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 
 2.14 Add a non-element (number)
-PASS select2.options.add(option2, 1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 
 2.15 Add a non-element (boolean)
-PASS select2.options.add(option2, 1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 
 2.16 Add undefined
-PASS select2.options.add(option2, 1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 
 2.17 Add null
-PASS select2.options.add(option2, 1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 
 2.18 Add negative infinity
-PASS select2.options.add(option2, 1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 
 2.19 Add NaN
-PASS select2.options.add(option2, 1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 
 2.20 Add positive infinity
-PASS select2.options.add(option2, 1) threw exception TypeError: Argument 1 ('element') to HTMLOptionsCollection.add must be an instance of HTMLElement.
+PASS select2.options.add(option2, 1) threw exception TypeError: Type error.
 PASS select2.options.length is 11
 PASS select2.selectedIndex is 4
 

Modified: trunk/Source/WebCore/ChangeLog (207496 => 207497)


--- trunk/Source/WebCore/ChangeLog	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/ChangeLog	2016-10-18 23:18:20 UTC (rev 207497)
@@ -1,3 +1,37 @@
+2016-10-18  Chris Dumez  <cdu...@apple.com>
+
+        Leverage new union type support for HTMLSelectElement.add() / HTMLOptionsCollection.add()
+        https://bugs.webkit.org/show_bug.cgi?id=163608
+
+        Reviewed by Ryosuke Niwa.
+
+        Leverage new union type support for HTMLSelectElement.add() / HTMLOptionsCollection.add():
+        - https://html.spec.whatwg.org/#htmlselectelement
+        - https://html.spec.whatwg.org/#htmloptionscollection
+
+        No new tests, rebaseline existing test.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateDefaultValue):
+        (GenerateParametersCheck):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalSequenceIsEmptyCaller):
+        * bindings/scripts/test/JS/JSTestOverloadedConstructorsWithSequence.cpp:
+        (WebCore::constructJSTestOverloadedConstructorsWithSequence1):
+        * bindings/scripts/test/JS/JSTestTypedefs.cpp:
+        (WebCore::jsTestTypedefsPrototypeFunctionFuncCaller):
+        * html/HTMLOptGroupElement.idl:
+        * html/HTMLOptionsCollection.cpp:
+        (WebCore::HTMLOptionsCollection::add):
+        * html/HTMLOptionsCollection.h:
+        * html/HTMLOptionsCollection.idl:
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::add):
+        (WebCore::HTMLSelectElement::setOption):
+        (WebCore::HTMLSelectElement::setLength):
+        * html/HTMLSelectElement.h:
+        * html/HTMLSelectElement.idl:
+
 2016-10-18  Aaron Chu  <aaron_...@apple.com>
 
         Web Inspector: AXI: focused/focusable state should be based on Accessibility Object instead of Element

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (207496 => 207497)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-10-18 23:18:20 UTC (rev 207497)
@@ -996,25 +996,31 @@
 
 sub GenerateDefaultValue
 {
-    my ($interface, $member) = @_;
+    my ($interface, $signature) = @_;
 
-    my $defaultValue = $member->default;
+    my $defaultValue = $signature->default;
 
-    if ($codeGenerator->IsEnumType($member->type)) {
+    if ($codeGenerator->IsEnumType($signature->type)) {
         # FIXME: Would be nice to report an error if the value does not have quote marks around it.
         # FIXME: Would be nice to report an error if the value is not one of the enumeration values.
-        my $className = GetEnumerationClassName($member->type, $interface);
+        my $className = GetEnumerationClassName($signature->type, $interface);
         my $enumerationValueName = GetEnumerationValueName(substr($defaultValue, 1, -1));
         return $className . "::" . $enumerationValueName;
     }
     if ($defaultValue eq "null") {
-        return "jsNull()" if $member->type eq "any";
-        return "nullptr" if $codeGenerator->IsWrapperType($member->type) || $codeGenerator->IsTypedArrayType($member->type);
-        return "String()" if $codeGenerator->IsStringType($member->type);
+        return "Nullopt" if $signature->idlType->isUnion;
+        return "jsNull()" if $signature->type eq "any";
+        return "nullptr" if $codeGenerator->IsWrapperType($signature->type) || $codeGenerator->IsTypedArrayType($signature->type);
+        return "String()" if $codeGenerator->IsStringType($signature->type);
         return "Nullopt";
     }
-    return "{ }" if $defaultValue eq "[]";
+    if ($defaultValue eq "[]") {
+        my $nativeType = GetNativeTypeFromSignature($interface, $signature);
+        return "$nativeType()"
+    }
+
     return "jsUndefined()" if $defaultValue eq "undefined";
+    return "PNaN" if $defaultValue eq "NaN";
 
     return $defaultValue;
 }
@@ -4342,10 +4348,7 @@
                             $defaultValue = $useAtomicString ? "AtomicString($defaultValue, AtomicString::ConstructFromLiteral)" : "ASCIILiteral($defaultValue)";
                         }
                     } else {
-                        $defaultValue = "nullptr" if $defaultValue eq "null";
-                        $defaultValue = "PNaN" if $defaultValue eq "NaN";
-                        $defaultValue = "$nativeType()" if $defaultValue eq "[]";
-                        $defaultValue = "JSValue::JSUndefined" if $defaultValue eq "undefined";
+                        $defaultValue = GenerateDefaultValue($interface, $parameter);
                     }
 
                     $outer = "state->$argumentLookupMethod($argumentIndex).isUndefined() ? $defaultValue : ";

Modified: trunk/Source/WebCore/html/HTMLOptGroupElement.idl (207496 => 207497)


--- trunk/Source/WebCore/html/HTMLOptGroupElement.idl	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/html/HTMLOptGroupElement.idl	2016-10-18 23:18:20 UTC (rev 207497)
@@ -17,7 +17,9 @@
  * Boston, MA 02110-1301, USA.
  */
 
-interface HTMLOptGroupElement : HTMLElement {
+[
+    JSGenerateToNativeObject,
+] interface HTMLOptGroupElement : HTMLElement {
     [Reflect] attribute boolean disabled;
     [Reflect] attribute DOMString label;
 };

Modified: trunk/Source/WebCore/html/HTMLOptionsCollection.cpp (207496 => 207497)


--- trunk/Source/WebCore/html/HTMLOptionsCollection.cpp	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/html/HTMLOptionsCollection.cpp	2016-10-18 23:18:20 UTC (rev 207497)
@@ -36,16 +36,11 @@
     return adoptRef(*new HTMLOptionsCollection(select));
 }
 
-void HTMLOptionsCollection::add(HTMLElement& element, HTMLElement* beforeElement, ExceptionCode& ec)
+ExceptionOr<void> HTMLOptionsCollection::add(const OptionOrOptGroupElement& element, Optional<HTMLElementOrInt> before)
 {
-    selectElement().add(element, beforeElement, ec);
+    return selectElement().add(element, before);
 }
 
-void HTMLOptionsCollection::add(HTMLElement& element, int beforeIndex, ExceptionCode& ec)
-{
-    add(element, item(beforeIndex), ec);
-}
-
 void HTMLOptionsCollection::remove(int index)
 {
     selectElement().removeByIndex(index);

Modified: trunk/Source/WebCore/html/HTMLOptionsCollection.h (207496 => 207497)


--- trunk/Source/WebCore/html/HTMLOptionsCollection.h	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/html/HTMLOptionsCollection.h	2016-10-18 23:18:20 UTC (rev 207497)
@@ -41,8 +41,9 @@
     HTMLOptionElement* item(unsigned offset) const final;
     HTMLOptionElement* namedItem(const AtomicString& name) const final;
 
-    WEBCORE_EXPORT void add(HTMLElement&, HTMLElement* beforeElement, ExceptionCode&);
-    WEBCORE_EXPORT void add(HTMLElement&, int beforeIndex, ExceptionCode&);
+    using OptionOrOptGroupElement = std::experimental::variant<RefPtr<HTMLOptionElement>, RefPtr<HTMLOptGroupElement>>;
+    using HTMLElementOrInt = std::experimental::variant<RefPtr<HTMLElement>, int>;
+    WEBCORE_EXPORT ExceptionOr<void> add(const OptionOrOptGroupElement&, Optional<HTMLElementOrInt> before);
     WEBCORE_EXPORT void remove(int index);
     void remove(HTMLOptionElement&);
 

Modified: trunk/Source/WebCore/html/HTMLOptionsCollection.idl (207496 => 207497)


--- trunk/Source/WebCore/html/HTMLOptionsCollection.idl	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/html/HTMLOptionsCollection.idl	2016-10-18 23:18:20 UTC (rev 207497)
@@ -30,10 +30,7 @@
     getter HTMLOptionElement? item(unsigned long index);
     getter HTMLOptionElement? namedItem(DOMString name);
 
-    // FIXME: Should be:
-    // void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
-    [MayThrowLegacyException] void add(HTMLElement element, optional HTMLElement? before = null);
-    [MayThrowLegacyException] void add(HTMLElement element, long index);
+    [MayThrowException] void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
 
     void remove(long index);
     // FIXME: This overload is not in the specification and has been dropped in Blink.

Modified: trunk/Source/WebCore/html/HTMLSelectElement.cpp (207496 => 207497)


--- trunk/Source/WebCore/html/HTMLSelectElement.cpp	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/html/HTMLSelectElement.cpp	2016-10-18 23:18:20 UTC (rev 207497)
@@ -221,16 +221,27 @@
     return lastSelectedListIndex();
 }
 
-void HTMLSelectElement::add(HTMLElement& element, HTMLElement* beforeElement, ExceptionCode& ec)
+ExceptionOr<void> HTMLSelectElement::add(const OptionOrOptGroupElement& element, Optional<HTMLElementOrInt> before)
 {
-    if (!(is<HTMLOptionElement>(element) || is<HTMLHRElement>(element) || is<HTMLOptGroupElement>(element)))
-        return;
-    insertBefore(element, beforeElement, ec);
-}
+    HTMLElement* beforeElement = nullptr;
+    if (before) {
+        auto visitor = WTF::makeVisitor(
+            [](const RefPtr<HTMLElement>& element) -> HTMLElement* { return element.get(); },
+            [this](int index) -> HTMLElement* { return item(index); }
+        );
 
-void HTMLSelectElement::add(HTMLElement& element, int beforeIndex, ExceptionCode& ec)
-{
-    add(element, item(beforeIndex), ec);
+        beforeElement = std::experimental::visit(visitor, before.value());
+    }
+    HTMLElement& toInsert = std::experimental::visit([](const auto& htmlElement) -> HTMLElement& {
+        return *htmlElement;
+    }, element);
+
+
+    ExceptionCode ec = 0;
+    insertBefore(toInsert, beforeElement, ec);
+    if (ec)
+        return Exception { ec };
+    return { };
 }
 
 void HTMLSelectElement::removeByIndex(int optionIndex)
@@ -440,7 +451,9 @@
     }
     // Finally add the new element.
     if (!ec) {
-        add(option, before.get(), ec);
+        auto exception = add(&option, HTMLElementOrInt(before.get()));
+        if (exception.hasException())
+            ec = exception.releaseException().code();
         if (diff >= 0 && option.selected())
             optionSelectionStateChanged(option, true);
     }
@@ -456,9 +469,11 @@
     if (diff < 0) { // Add dummy elements.
         do {
             auto option = document().createElement(optionTag, false);
-            add(downcast<HTMLElement>(option.get()), nullptr, ec);
-            if (ec)
+            auto exception = add(downcast<HTMLOptionElement>(option.ptr()), Nullopt);
+            if (exception.hasException()) {
+                ec = exception.releaseException().code();
                 break;
+        }
         } while (++diff);
     } else {
         auto& items = listItems();

Modified: trunk/Source/WebCore/html/HTMLSelectElement.h (207496 => 207497)


--- trunk/Source/WebCore/html/HTMLSelectElement.h	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/html/HTMLSelectElement.h	2016-10-18 23:18:20 UTC (rev 207497)
@@ -51,8 +51,9 @@
 
     bool usesMenuList() const;
 
-    WEBCORE_EXPORT void add(HTMLElement&, HTMLElement* beforeElement, ExceptionCode&);
-    void add(HTMLElement&, int beforeIndex, ExceptionCode&);
+    using OptionOrOptGroupElement = std::experimental::variant<RefPtr<HTMLOptionElement>, RefPtr<HTMLOptGroupElement>>;
+    using HTMLElementOrInt = std::experimental::variant<RefPtr<HTMLElement>, int>;
+    WEBCORE_EXPORT ExceptionOr<void> add(const OptionOrOptGroupElement&, Optional<HTMLElementOrInt> before);
 
     using Node::remove;
     void remove(HTMLOptionElement&);

Modified: trunk/Source/WebCore/html/HTMLSelectElement.idl (207496 => 207497)


--- trunk/Source/WebCore/html/HTMLSelectElement.idl	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebCore/html/HTMLSelectElement.idl	2016-10-18 23:18:20 UTC (rev 207497)
@@ -40,10 +40,7 @@
     getter HTMLOptionElement? item(unsigned long index);
     HTMLOptionElement? namedItem(DOMString name);
 
-    [MayThrowLegacyException] void add(HTMLElement element, optional HTMLElement? before = null);
-    // FIXME: Should be:
-    // void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
-    [MayThrowLegacyException] void add(HTMLElement element, long index);
+    [MayThrowException] void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
 
     [MayThrowLegacyException] void remove(); // ChildNode overload
     // FIXME: This overload is not in the specification and was dropped in Blink.

Modified: trunk/Source/WebKit/mac/ChangeLog (207496 => 207497)


--- trunk/Source/WebKit/mac/ChangeLog	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebKit/mac/ChangeLog	2016-10-18 23:18:20 UTC (rev 207497)
@@ -1,3 +1,17 @@
+2016-10-18  Chris Dumez  <cdu...@apple.com>
+
+        Leverage new union type support for HTMLSelectElement.add() / HTMLOptionsCollection.add()
+        https://bugs.webkit.org/show_bug.cgi?id=163608
+
+        Reviewed by Ryosuke Niwa.
+
+        Update add() call sites now that it takes std::variant types in.
+
+        * DOM/DOMHTMLOptionsCollection.mm:
+        (-[DOMHTMLOptionsCollection add:index:]):
+        * DOM/DOMHTMLSelectElement.mm:
+        (-[DOMHTMLSelectElement add:before:]):
+
 2016-10-18  Anders Carlsson  <ander...@apple.com>
 
         Get rid of more WebHistoryItem cruft

Modified: trunk/Source/WebKit/mac/DOM/DOMHTMLOptionsCollection.mm (207496 => 207497)


--- trunk/Source/WebKit/mac/DOM/DOMHTMLOptionsCollection.mm	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebKit/mac/DOM/DOMHTMLOptionsCollection.mm	2016-10-18 23:18:20 UTC (rev 207497)
@@ -29,6 +29,7 @@
 #import "DOMInternal.h"
 #import "DOMNodeInternal.h"
 #import "ExceptionHandlers.h"
+#import <WebCore/HTMLOptGroupElement.h>
 #import <WebCore/HTMLOptionElement.h>
 #import <WebCore/HTMLOptionsCollection.h>
 #import <WebCore/JSMainThreadExecState.h>
@@ -38,6 +39,7 @@
 #import <WebCore/WebCoreObjCExtras.h>
 #import <WebCore/WebScriptObjectPrivate.h>
 #import <wtf/GetPtr.h>
+#import <wtf/Variant.h>
 
 #define IMPL reinterpret_cast<WebCore::HTMLOptionsCollection*>(_internal)
 
@@ -90,9 +92,9 @@
     WebCore::JSMainThreadNullState state;
     if (!option)
         raiseTypeErrorException();
-    WebCore::ExceptionCode ec = 0;
-    IMPL->add(*core(option), index, ec);
-    raiseOnDOMError(ec);
+    auto exception = IMPL->add(core(option), Optional<WebCore::HTMLOptionsCollection::HTMLElementOrInt>(static_cast<int>(index)));
+    if (exception.hasException())
+        raiseOnDOMError(exception.releaseException().code());
 }
 
 - (void)remove:(unsigned)index

Modified: trunk/Source/WebKit/mac/DOM/DOMHTMLSelectElement.mm (207496 => 207497)


--- trunk/Source/WebKit/mac/DOM/DOMHTMLSelectElement.mm	2016-10-18 23:04:13 UTC (rev 207496)
+++ trunk/Source/WebKit/mac/DOM/DOMHTMLSelectElement.mm	2016-10-18 23:18:20 UTC (rev 207497)
@@ -36,6 +36,7 @@
 #import <WebCore/HTMLElement.h>
 #import <WebCore/HTMLFormElement.h>
 #import <WebCore/HTMLNames.h>
+#import <WebCore/HTMLOptGroupElement.h>
 #import <WebCore/HTMLOptionsCollection.h>
 #import <WebCore/HTMLSelectElement.h>
 #import <WebCore/JSMainThreadExecState.h>
@@ -182,9 +183,20 @@
     WebCore::JSMainThreadNullState state;
     if (!element)
         raiseTypeErrorException();
-    WebCore::ExceptionCode ec = 0;
-    IMPL->add(*core(element), core(before), ec);
-    raiseOnDOMError(ec);
+
+    auto& coreElement = *core(element);
+    std::experimental::variant<RefPtr<WebCore::HTMLOptionElement>, RefPtr<WebCore::HTMLOptGroupElement>> variantElement;
+    if (is<WebCore::HTMLOptionElement>(coreElement))
+        variantElement = &downcast<WebCore::HTMLOptionElement>(coreElement);
+    else if (is<WebCore::HTMLOptGroupElement>(coreElement))
+        variantElement = &downcast<WebCore::HTMLOptGroupElement>(coreElement);
+    else {
+        raiseTypeErrorException();
+        return;
+    }
+    auto exception = IMPL->add(WTFMove(variantElement), WebCore::HTMLSelectElement::HTMLElementOrInt(core(before)));
+    if (exception.hasException())
+        raiseOnDOMError(exception.releaseException().code());
 }
 
 - (void)remove:(int)index
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to