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/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)