Title: [204143] trunk/Source/WebCore
Revision
204143
Author
[email protected]
Date
2016-08-04 15:02:21 -0700 (Thu, 04 Aug 2016)

Log Message

Add support for wrapper types in dictionaries
https://bugs.webkit.org/show_bug.cgi?id=160487

Reviewed by Sam Weinig.

Add support for nullable wrapper types in dictionaries.
A TypeError is thrown if the conversion fails.

No new tests, updated bindings tests.

* bindings/js/JSDOMConvert.h:
(WebCore::convertWrapperType):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateDictionaryImplementationContent):
* bindings/scripts/IDLParser.pm:
(parseDictionaryMember):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::convert<TestObj::Dictionary>):
* bindings/scripts/test/TestObj.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (204142 => 204143)


--- trunk/Source/WebCore/ChangeLog	2016-08-04 21:45:52 UTC (rev 204142)
+++ trunk/Source/WebCore/ChangeLog	2016-08-04 22:02:21 UTC (rev 204143)
@@ -1,3 +1,25 @@
+2016-08-04  Chris Dumez  <[email protected]>
+
+        Add support for wrapper types in dictionaries
+        https://bugs.webkit.org/show_bug.cgi?id=160487
+
+        Reviewed by Sam Weinig.
+
+        Add support for nullable wrapper types in dictionaries.
+        A TypeError is thrown if the conversion fails.
+
+        No new tests, updated bindings tests.
+
+        * bindings/js/JSDOMConvert.h:
+        (WebCore::convertWrapperType):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateDictionaryImplementationContent):
+        * bindings/scripts/IDLParser.pm:
+        (parseDictionaryMember):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::convert<TestObj::Dictionary>):
+        * bindings/scripts/test/TestObj.idl:
+
 2016-08-04  Csaba Osztrogonác  <[email protected]>
 
         [Mac][cmake] Fix the build after Objective-C bindings generator removal

Modified: trunk/Source/WebCore/bindings/js/JSDOMConvert.h (204142 => 204143)


--- trunk/Source/WebCore/bindings/js/JSDOMConvert.h	2016-08-04 21:45:52 UTC (rev 204142)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvert.h	2016-08-04 22:02:21 UTC (rev 204143)
@@ -49,6 +49,9 @@
 template<typename T, typename U> EnableIfIntegralType<T> convertOptional(JSC::ExecState&, JSC::JSValue, IntegerConversionConfiguration, U&& defaultValue);
 template<typename T, typename U> EnableIfFloatingPointType<T> convertOptional(JSC::ExecState&, JSC::JSValue, ShouldAllowNonFinite, U&& defaultValue);
 
+enum class IsNullable { No, Yes };
+template<typename T, typename JST> T* convertWrapperType(JSC::ExecState&, JSC::JSValue, IsNullable);
+
 // This is where the implementation of the things declared above begins:
 
 template<typename T> T convert(JSC::ExecState& state, JSC::JSValue value)
@@ -66,6 +69,14 @@
     return Converter<T>::convert(state, value, allow);
 }
 
+template<typename T, typename JST> inline T* convertWrapperType(JSC::ExecState& state, JSC::JSValue value, IsNullable isNullable)
+{
+    T* object = JST::toWrapped(value);
+    if (!object && (isNullable == IsNullable::No || !value.isUndefinedOrNull()))
+        throwTypeError(&state);
+    return object;
+}
+
 template<typename T> inline typename Converter<T>::OptionalValue convertOptional(JSC::ExecState& state, JSC::JSValue value)
 {
     return value.isUndefined() ? typename Converter<T>::OptionalValue() : convert<T>(state, value);

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (204142 => 204143)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-08-04 21:45:52 UTC (rev 204142)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-08-04 22:02:21 UTC (rev 204143)
@@ -923,6 +923,7 @@
         my $enumerationValueName = GetEnumerationValueName(substr($value, 1, -1));
         $value = $className . "::" . $enumerationValueName;
     }
+    $value = "nullptr" if $value eq "null";
 
     return $value;
 }
@@ -998,11 +999,19 @@
                 $result .= "        return { };\n";
             }
             # FIXME: Eventually we will want this to share a lot more code with JSValueToNative.
-            my $function = $member->isOptional ? "convertOptional" : "convert";
-            $result .= "    auto " . $member->name . " = " . $function . "<" . GetNativeTypeFromSignature($interface, $member) . ">"
-                . "(state, object->get(&state, Identifier::fromString(&state, \"" . $member->name . "\"))"
-                . GenerateConversionRuleWithLeadingComma($interface, $member)
-                . GenerateDefaultValueWithLeadingComma($interface, $member) . ");\n";
+            my $type = $member->type;
+            my $name = $member->name;
+            my $value = "object->get(&state, Identifier::fromString(&state, \"${name}\"))";
+            if ($codeGenerator->IsWrapperType($member->type)) {
+                die "Dictionary member of non-nullable wrapper types are not supported yet" unless $member->isNullable;
+                AddToImplIncludes("JS${type}.h");
+                $result .= "    auto* $name = convertWrapperType<$type, JS${type}>(state, $value, IsNullable::Yes);\n";
+            } else {
+                my $function = $member->isOptional ? "convertOptional" : "convert";
+                $result .= "    auto $name = ${function}<" . GetNativeTypeFromSignature($interface, $member) . ">(state, $value"
+                    . GenerateConversionRuleWithLeadingComma($interface, $member)
+                    . GenerateDefaultValueWithLeadingComma($interface, $member) . ");\n";
+            }
             $needExceptionCheck = 1;
         }
 

Modified: trunk/Source/WebCore/bindings/scripts/IDLParser.pm (204142 => 204143)


--- trunk/Source/WebCore/bindings/scripts/IDLParser.pm	2016-08-04 21:45:52 UTC (rev 204142)
+++ trunk/Source/WebCore/bindings/scripts/IDLParser.pm	2016-08-04 22:02:21 UTC (rev 204143)
@@ -683,7 +683,14 @@
             $member->isOptional(0);
         }
         $member->extendedAttributes($extendedAttributeList);
-        $member->type($self->parseType());
+        my $type = $self->parseType();
+        if (typeHasNullableSuffix($type)) {
+            $member->isNullable(1);
+        } else {
+            $member->isNullable(0);
+        }
+        $member->type(typeRemoveNullableSuffix($type));
+
         my $nameToken = $self->getToken();
         $self->assertTokenType($nameToken, IdentifierToken);
         $member->name($nameToken->value);

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (204142 => 204143)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2016-08-04 21:45:52 UTC (rev 204142)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2016-08-04 22:02:21 UTC (rev 204143)
@@ -454,7 +454,7 @@
 template<> TestObj::Dictionary convert<TestObj::Dictionary>(ExecState& state, JSValue value)
 {
     if (value.isUndefinedOrNull())
-        return { { }, TestObj::EnumType::EnumValue1, TestObj::EnumType::EmptyString, "defaultString", { }, false, { }, { }, { }, { }, 0, 0, { }, { }, 0, 0, { }, { }, { }, 0, { }, 0, { }, 0, { }, 0, { }, 0 };
+        return { { }, TestObj::EnumType::EnumValue1, TestObj::EnumType::EmptyString, "defaultString", { }, false, { }, { }, { }, { }, 0, 0, { }, { }, 0, 0, { }, { }, { }, 0, { }, 0, { }, 0, { }, 0, { }, 0, nullptr };
     auto* object = value.getObject();
     if (UNLIKELY(!object || object->type() == RegExpObjectType)) {
         throwTypeError(&state);
@@ -542,7 +542,10 @@
     if (UNLIKELY(state.hadException()))
         return { };
     auto unsignedLargeIntegerWithDefault = convertOptional<uint64_t>(state, object->get(&state, Identifier::fromString(&state, "unsignedLargeIntegerWithDefault")), NormalConversion, 0);
-    return { WTFMove(enumerationValueWithoutDefault), WTFMove(enumerationValueWithDefault), WTFMove(enumerationValueWithEmptyStringDefault), WTFMove(stringWithDefault), WTFMove(stringWithoutDefault), WTFMove(booleanWithDefault), WTFMove(booleanWithoutDefault), WTFMove(sequenceOfStrings), WTFMove(restrictedDouble), WTFMove(unrestrictedDouble), WTFMove(restrictedDoubleWithDefault), WTFMove(unrestrictedDoubleWithDefault), WTFMove(restrictedFloat), WTFMove(unrestrictedFloat), WTFMove(restrictedFloatWithDefault), WTFMove(unrestrictedFloatWithDefault), WTFMove(smallIntegerClamped), WTFMove(smallIntegerWithDefault), WTFMove(smallUnsignedIntegerEnforcedRange), WTFMove(smallUnsignedIntegerWithDefault), WTFMove(integer), WTFMove(integerWithDefault), WTFMove(unsignedInteger), WTFMove(unsignedIntegerWithDefault), WTFMove(largeInteger), WTFMove(largeIntegerWithDefault), WTFMove(unsignedLargeInteger), WTFMove(unsignedLargeIntegerWithDefault) };
+    if (UNLIKELY(state.hadException()))
+        return { };
+    auto* nullableNode = convertWrapperType<Node, JSNode>(state, object->get(&state, Identifier::fromString(&state, "nullableNode")), IsNullable::Yes);
+    return { WTFMove(enumerationValueWithoutDefault), WTFMove(enumerationValueWithDefault), WTFMove(enumerationValueWithEmptyStringDefault), WTFMove(stringWithDefault), WTFMove(stringWithoutDefault), WTFMove(booleanWithDefault), WTFMove(booleanWithoutDefault), WTFMove(sequenceOfStrings), WTFMove(restrictedDouble), WTFMove(unrestrictedDouble), WTFMove(restrictedDoubleWithDefault), WTFMove(unrestrictedDoubleWithDefault), WTFMove(restrictedFloat), WTFMove(unrestrictedFloat), WTFMove(restrictedFloatWithDefault), WTFMove(unrestrictedFloatWithDefault), WTFMove(smallIntegerClamped), WTFMove(smallIntegerWithDefault), WTFMove(smallUnsignedIntegerEnforcedRange), WTFMove(smallUnsignedIntegerWithDefault), WTFMove(integer), WTFMove(integerWithDefault), WTFMove(unsignedInteger), WTFMove(unsignedIntegerWithDefault), WTFMove(largeInteger), WTFMove(largeIntegerWithDefault), WTFMove(unsignedLargeInteger), WTFMove(unsignedLargeIntegerWithDefault), WTFMove(nullableNode) };
 }
 
 template<> TestObj::DictionaryThatShouldNotTolerateNull convert<TestObj::DictionaryThatShouldNotTolerateNull>(ExecState& state, JSValue value)

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (204142 => 204143)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2016-08-04 21:45:52 UTC (rev 204142)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2016-08-04 22:02:21 UTC (rev 204143)
@@ -403,6 +403,7 @@
     long long largeIntegerWithDefault = 0;
     unsigned long long unsignedLargeInteger;
     unsigned long long unsignedLargeIntegerWithDefault = 0;
+    Node? nullableNode = null;
 };
 
 dictionary TestDictionaryThatShouldNotTolerateNull {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to