diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 79479363acd..b46d44c5982 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -548,11 +548,6 @@ def typeIsSequenceOrHasSequenceMember(type): return False -def typeNeedsRooting(type, descriptorProvider): - return (type.isGeckoInterface() and - descriptorProvider.getDescriptor(type.unroll().inner.identifier.name).needsRooting) - - def union_native_type(t): name = t.unroll().name return 'UnionTypes::%s' % name @@ -1422,8 +1417,6 @@ def getRetvalDeclarationForType(returnType, descriptorProvider): nullable = returnType.nullable() dictName = returnType.inner.name if nullable else returnType.name result = CGGeneric(dictName) - if typeNeedsRooting(returnType, descriptorProvider): - raise TypeError("We don't support rootable dictionaries return values") if nullable: result = CGWrapper(result, pre="Option<", post=">") return result @@ -6122,14 +6115,19 @@ class CGBindingRoot(CGThing): # Do codegen for all the typdefs for t in typedefs: - if t.innerType.isUnion(): - cgthings.extend([CGGeneric("\npub use dom::bindings::codegen::UnionTypes::%s as %s;\n\n" % - (t.innerType, t.identifier.name))]) + typeName = getRetvalDeclarationForType(t.innerType, config.getDescriptorProvider()) + substs = { + "name": t.identifier.name, + "type": typeName.define(), + } + + if t.innerType.isUnion() and not t.innerType.nullable(): + # Allow using the typedef's name for accessing variants. + template = "pub use self::%(type)s as %(name)s;" else: - assert not typeNeedsRooting(t.innerType, config.getDescriptorProvider) - cgthings.extend([CGGeneric("\npub type %s = " % (t.identifier.name)), - getRetvalDeclarationForType(t.innerType, config.getDescriptorProvider()), - CGGeneric(";\n\n")]) + template = "pub type %(name)s = %(type)s;" + + cgthings.append(CGGeneric(template % substs)) # Do codegen for all the dictionaries. cgthings.extend([CGDictionary(d, config.getDescriptorProvider()) diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py index 14a11c139a9..0fe9bf6c004 100644 --- a/components/script/dom/bindings/codegen/Configuration.py +++ b/components/script/dom/bindings/codegen/Configuration.py @@ -201,20 +201,17 @@ class Descriptor(DescriptorProvider): # Callback and SpiderMonkey types do not use JS smart pointers, so we should not use the # built-in rooting mechanisms for them. if spiderMonkeyInterface: - self.needsRooting = False self.returnType = 'Rc<%s>' % typeName self.argumentType = '&%s' % typeName self.nativeType = typeName pathDefault = 'dom::types::%s' % typeName elif self.interface.isCallback(): - self.needsRooting = False ty = 'dom::bindings::codegen::Bindings::%sBinding::%s' % (ifaceName, ifaceName) pathDefault = ty self.returnType = "Rc<%s>" % ty self.argumentType = "???" self.nativeType = ty else: - self.needsRooting = True self.returnType = "Root<%s>" % typeName self.argumentType = "&%s" % typeName self.nativeType = "*const %s" % typeName diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl index 6920ded6301..fc6d4771366 100644 --- a/components/script/dom/webidls/TestBinding.webidl +++ b/components/script/dom/webidls/TestBinding.webidl @@ -7,6 +7,9 @@ enum TestEnum { "", "foo", "bar" }; typedef (DOMString or URL or Blob) TestTypedef; +typedef (DOMString or URL or Blob)? TestTypedefNullableUnion; +typedef DOMString TestTypedefString; +typedef Blob TestTypedefInterface; dictionary TestDictionary { required boolean requiredValue;