diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-01-20 07:08:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-20 07:08:09 -0800 |
commit | be3f35878af1d9210abc65358c99782c119ceaa6 (patch) | |
tree | a04acbce5e164c04bf71db689d2dd3054fb7d848 /components/script/dom | |
parent | 1f76aa6ef7ec7db0a0c40223874a72e8f4059deb (diff) | |
parent | 6a6f339b29907ec0a2a496fe0f477d50c38a3ddc (diff) | |
download | servo-be3f35878af1d9210abc65358c99782c119ceaa6.tar.gz servo-be3f35878af1d9210abc65358c99782c119ceaa6.zip |
Auto merge of #15125 - servo:unions-dictionaries, r=nox
Support dictionaries in unions.
Fixes #11612.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15125)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 49 | ||||
-rw-r--r-- | components/script/dom/testbinding.rs | 1 | ||||
-rw-r--r-- | components/script/dom/webidls/TestBinding.webidl | 1 |
3 files changed, 39 insertions, 12 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index f531937d05e..7c084f32400 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -758,7 +758,26 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, " _ => { %s },\n" "}" % (indent(failOrPropagate, 8), exceptionCode)) - return handleOptional(templateBody, declType, handleDefaultNull("None")) + dictionaries = [ + memberType + for memberType in type.unroll().flatMemberTypes + if memberType.isDictionary() + ] + if dictionaries: + if defaultValue: + assert isinstance(defaultValue, IDLNullValue) + dictionary, = dictionaries + default = "%s::%s(%s::%s::empty(cx))" % ( + union_native_type(type), + dictionary.name, + CGDictionary.makeModuleName(dictionary.inner), + CGDictionary.makeDictionaryName(dictionary.inner)) + else: + default = None + else: + default = handleDefaultNull("None") + + return handleOptional(templateBody, declType, default) if type.isGeckoInterface(): assert not isEnforceRange and not isClamp @@ -1076,8 +1095,6 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, handleDefaultNull("ptr::null_mut()")) if type.isDictionary(): - if failureCode is not None: - raise TypeError("Can't handle dictionaries when failureCode is not None") # There are no nullable dictionaries assert not type.nullable() @@ -2217,6 +2234,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config): """ imports = [ + 'dom', 'dom::bindings::codegen::PrototypeList', 'dom::bindings::conversions::ConversionResult', 'dom::bindings::conversions::FromJSValConvertible', @@ -2243,7 +2261,9 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config): # we need to wrap or unwrap them. unionStructs = dict() for (t, descriptor, dictionary) in getAllTypes(descriptors, dictionaries, callbacks, typedefs): - assert not descriptor or not dictionary + if dictionary: + imports.append("%s::%s" % (CGDictionary.makeModuleName(dictionary), + CGDictionary.makeDictionaryName(dictionary))) t = t.unroll() if not t.isUnion(): continue @@ -4028,6 +4048,9 @@ def getUnionTypeTemplateVars(type, descriptorProvider): elif type.isEnum(): name = type.inner.identifier.name typeName = name + elif type.isDictionary(): + name = type.name + typeName = name elif type.isSequence() or type.isMozMap(): name = type.name inner = getUnionTypeTemplateVars(innerContainerType(type), descriptorProvider) @@ -4163,16 +4186,13 @@ class CGUnionConversionStruct(CGThing): dictionaryMemberTypes = filter(lambda t: t.isDictionary(), memberTypes) if len(dictionaryMemberTypes) > 0: - raise TypeError("No support for unwrapping dictionaries as member " - "of a union") + assert len(dictionaryMemberTypes) == 1 + typeName = dictionaryMemberTypes[0].name + dictionaryObject = CGGeneric(get_match(typeName)) + names.append(typeName) else: dictionaryObject = None - if callbackObject or dictionaryObject: - assert False, "Not currently supported" - else: - nonPlatformObject = None - objectMemberTypes = filter(lambda t: t.isObject(), memberTypes) if len(objectMemberTypes) > 0: assert len(objectMemberTypes) == 1 @@ -4191,7 +4211,7 @@ class CGUnionConversionStruct(CGThing): else: mozMapObject = None - hasObjectTypes = interfaceObject or arrayObject or dateObject or nonPlatformObject or object or mozMapObject + hasObjectTypes = interfaceObject or arrayObject or dateObject or object or mozMapObject if hasObjectTypes: # "object" is not distinguishable from other types assert not object or not (interfaceObject or arrayObject or dateObject or callbackObject or mozMapObject) @@ -4203,6 +4223,11 @@ class CGUnionConversionStruct(CGThing): if mozMapObject: templateBody.append(mozMapObject) conversions.append(CGIfWrapper("value.get().is_object()", templateBody)) + + if dictionaryObject: + assert not hasObjectTypes + conversions.append(dictionaryObject) + stringTypes = [t for t in memberTypes if t.isString() or t.isEnum()] numericTypes = [t for t in memberTypes if t.isNumeric()] booleanTypes = [t for t in memberTypes if t.isBoolean()] diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 42db5f4a964..4726b82d900 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -434,6 +434,7 @@ impl TestBindingMethods for TestBinding { fn PassUnion6(&self, _: UnsignedLongOrBoolean) {} fn PassUnion7(&self, _: StringSequenceOrUnsignedLong) {} fn PassUnion8(&self, _: ByteStringSequenceOrLong) {} + fn PassUnion9(&self, _: UnionTypes::TestDictionaryOrLong) {} fn PassUnionWithTypedef(&self, _: DocumentOrTestTypedef) {} fn PassUnionWithTypedef2(&self, _: LongSequenceOrTestTypedef) {} #[allow(unsafe_code)] diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl index cfebfe2c570..6920ded6301 100644 --- a/components/script/dom/webidls/TestBinding.webidl +++ b/components/script/dom/webidls/TestBinding.webidl @@ -242,6 +242,7 @@ interface TestBinding { void passUnion6((unsigned long or boolean) bool); void passUnion7((sequence<DOMString> or unsigned long) arg); void passUnion8((sequence<ByteString> or long) arg); + void passUnion9((TestDictionary or long) arg); void passUnionWithTypedef((Document or TestTypedef) arg); void passUnionWithTypedef2((sequence<long> or TestTypedef) arg); void passAny(any arg); |