Log Message
[Web IDL] Add support for 'any' type in dictionaries https://bugs.webkit.org/show_bug.cgi?id=160511
Reviewed by Sam Weinig. Add support for 'any' type in dictionaries. It will pass the value as a JSValue to the implementation. If the member is not present, it will pass jsUndefined() to the implementation. Having 'any' support in dictionaries is a convenient workaround for types we don't support yet (e.g. union types). No new tests, updated bindings tests. * bindings/js/JSDOMConvert.h: (WebCore::Converter<JSC::JSValue>::convert): * bindings/scripts/test/JS/JSTestObj.cpp: (WebCore::convert<TestObj::Dictionary>): * bindings/scripts/test/TestObj.idl:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (204215 => 204216)
--- trunk/Source/WebCore/ChangeLog 2016-08-06 02:32:04 UTC (rev 204215)
+++ trunk/Source/WebCore/ChangeLog 2016-08-06 02:33:08 UTC (rev 204216)
@@ -1,5 +1,27 @@
2016-08-05 Chris Dumez <[email protected]>
+ [Web IDL] Add support for 'any' type in dictionaries
+ https://bugs.webkit.org/show_bug.cgi?id=160511
+
+ Reviewed by Sam Weinig.
+
+ Add support for 'any' type in dictionaries. It will pass the value as
+ a JSValue to the implementation. If the member is not present, it will
+ pass jsUndefined() to the implementation.
+
+ Having 'any' support in dictionaries is a convenient workaround for
+ types we don't support yet (e.g. union types).
+
+ No new tests, updated bindings tests.
+
+ * bindings/js/JSDOMConvert.h:
+ (WebCore::Converter<JSC::JSValue>::convert):
+ * bindings/scripts/test/JS/JSTestObj.cpp:
+ (WebCore::convert<TestObj::Dictionary>):
+ * bindings/scripts/test/TestObj.idl:
+
+2016-08-05 Chris Dumez <[email protected]>
+
[Web IDL] Add support for USVString type
https://bugs.webkit.org/show_bug.cgi?id=160608
Modified: trunk/Source/WebCore/bindings/js/JSDOMConvert.h (204215 => 204216)
--- trunk/Source/WebCore/bindings/js/JSDOMConvert.h 2016-08-06 02:32:04 UTC (rev 204215)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvert.h 2016-08-06 02:33:08 UTC (rev 204216)
@@ -129,6 +129,14 @@
}
};
+template<> struct Converter<JSC::JSValue> : DefaultConverter<JSC::JSValue> {
+ using OptionalValue = JSC::JSValue; // Use jsUndefined() to mean an optional value was not present.
+ static JSC::JSValue convert(JSC::ExecState&, JSC::JSValue value)
+ {
+ return value;
+ }
+};
+
template<typename T> struct Converter<Vector<T>> : DefaultConverter<Vector<T>> {
static Vector<T> convert(JSC::ExecState& state, JSC::JSValue value)
{
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (204215 => 204216)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2016-08-06 02:32:04 UTC (rev 204215)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2016-08-06 02:33:08 UTC (rev 204216)
@@ -924,6 +924,7 @@
$value = $className . "::" . $enumerationValueName;
}
$value = "nullptr" if $value eq "null";
+ $value = "jsUndefined()" if $value eq "undefined";
return $value;
}
@@ -978,6 +979,7 @@
$defaultValues = "";
last;
}
+ $member->default("undefined") if $member->type eq "any"; # Use undefined as default value for member of type 'any'.
$defaultValues .= $comma . (defined $member->default ? GenerateDefaultValue($interface, $member) : "{ }");
$comma = ", ";
}
Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (204215 => 204216)
--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp 2016-08-06 02:32:04 UTC (rev 204215)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp 2016-08-06 02:33:08 UTC (rev 204216)
@@ -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, nullptr };
+ return { { }, TestObj::EnumType::EnumValue1, TestObj::EnumType::EmptyString, "defaultString", { }, false, { }, { }, { }, { }, 0, 0, { }, { }, 0, 0, { }, { }, { }, 0, { }, 0, { }, 0, { }, 0, { }, 0, nullptr, jsUndefined() };
auto* object = value.getObject();
if (UNLIKELY(!object || object->type() == RegExpObjectType)) {
throwTypeError(&state);
@@ -545,7 +545,10 @@
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) };
+ if (UNLIKELY(state.hadException()))
+ return { };
+ auto anyValue = convertOptional<JSC::JSValue>(state, object->get(&state, Identifier::fromString(&state, "anyValue")), jsUndefined());
+ 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), WTFMove(anyValue) };
}
template<> TestObj::DictionaryThatShouldNotTolerateNull convert<TestObj::DictionaryThatShouldNotTolerateNull>(ExecState& state, JSValue value)
Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (204215 => 204216)
--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl 2016-08-06 02:32:04 UTC (rev 204215)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl 2016-08-06 02:33:08 UTC (rev 204216)
@@ -431,6 +431,7 @@
unsigned long long unsignedLargeInteger;
unsigned long long unsignedLargeIntegerWithDefault = 0;
Node? nullableNode = null;
+ any anyValue;
};
dictionary TestDictionaryThatShouldNotTolerateNull {
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
