Fix for bug 818219 (Replace HTMLElement quickstubs with new binding methods) - Support castable types in unions. r=bz.
authorPeter Van der Beken <peterv@propagandism.org>
Thu, 06 Dec 2012 11:41:14 +0100
changeset 120773 a0e79206a110f38c5c6e29bf21c00b4d9f85bd5f
parent 120772 f0112085d83683e7c6c781ece342a0eb08cebbc6
child 120774 92187bc8ec482fc7b86992d45946f77a8eb6de25
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs818219
milestone20.0a1
Fix for bug 818219 (Replace HTMLElement quickstubs with new binding methods) - Support castable types in unions. r=bz.
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -602,50 +602,55 @@ def UnionTypes(descriptors, dictionaries
                     declarations.add((f.inner.identifier.name, True))
                     implheaders.add(CGHeaders.getDeclarationFilename(f.inner))
 
     callForEachType(descriptors, dictionaries, callbacks, addInfoForType)
 
     return (headers, implheaders, declarations,
             CGList(SortedDictValues(unionStructs), "\n"))
 
-def UnionConversions(descriptors):
+def UnionConversions(descriptors, dictionaries, callbacks, config):
     """
     Returns a CGThing to declare all union argument conversion helper structs.
     """
     # Now find all the things we'll need as arguments because we
     # need to unwrap them.
+    headers = set()
     unionConversions = dict()
-    for d in descriptors:
-        if d.interface.isExternal():
-            continue
-
-        def addUnionTypes(type):
-            if type.isUnion():
-                type = type.unroll()
-                name = str(type)
-                if not name in unionConversions:
-                    unionConversions[name] = CGUnionConversionStruct(type, d)
-
-        members = [m for m in d.interface.members]
-        if d.interface.ctor():
-            members.append(d.interface.ctor())
-        signatures = [s for m in members if m.isMethod() for s in m.signatures()]
-        for s in signatures:
-            assert len(s) == 2
-            (_, arguments) = s
-            for a in arguments:
-                addUnionTypes(a.type)
-
-        for m in members:
-            if m.isAttr() and not m.readonly:
-                addUnionTypes(m.type)
-
-    return CGWrapper(CGList(SortedDictValues(unionConversions), "\n"),
-                     post="\n\n")
+
+    def addInfoForType(t, descriptor=None, dictionary=None):
+        """
+        Add info for the given type.  descriptor and dictionary, if passed, are
+        used to figure out what to do with interface types.
+        """
+        assert not descriptor or not dictionary
+        t = t.unroll()
+        if not t.isUnion():
+            return
+        name = str(t)
+        if not name in unionConversions:
+            providers = getRelevantProviders(descriptor, dictionary,
+                                             config)
+            unionConversions[name] = CGUnionConversionStruct(t, providers[0])
+            for f in t.flatMemberTypes:
+                f = f.unroll()
+                if f.isInterface():
+                    if f.isSpiderMonkeyInterface():
+                        headers.add("jsfriendapi.h")
+                        headers.add("mozilla/dom/TypedArray.h")
+                    elif not f.inner.isExternal():
+                        headers.add(CGHeaders.getDeclarationFilename(f.inner))
+                elif f.isDictionary():
+                    headers.add(CGHeaders.getDeclarationFilename(f.inner))
+
+    callForEachType(descriptors, dictionaries, callbacks, addInfoForType)
+
+    return (headers,
+            CGWrapper(CGList(SortedDictValues(unionConversions), "\n"),
+                      post="\n\n"))
 
 class Argument():
     """
     A class for outputting the type and name of an argument
     """
     def __init__(self, argType, name):
         self.argType = argType
         self.name = name
@@ -7771,22 +7776,26 @@ struct PrototypeIDMap;
         curr = CGIncludeGuard('UnionTypes', curr)
 
         # Done.
         return curr
 
     @staticmethod
     def UnionConversions(config):
 
-        unions = UnionConversions(config.getDescriptors())
+        (headers, unions) = UnionConversions(config.getDescriptors(),
+                                             config.getDictionaries(),
+                                             config.getCallbacks(),
+                                             config)
 
         # Wrap all of that in our namespaces.
         curr = CGNamespace.build(['mozilla', 'dom'], unions)
 
         curr = CGWrapper(curr, post='\n')
 
-        curr = CGHeaders([], [], [], ["nsDebug.h", "mozilla/dom/UnionTypes.h", "nsDOMQS.h", "XPCWrapper.h"], [], curr)
+        headers.update(["nsDebug.h", "mozilla/dom/UnionTypes.h", "nsDOMQS.h", "XPCWrapper.h"])
+        curr = CGHeaders([], [], [], headers, [], curr)
 
         # Add include guards.
         curr = CGIncludeGuard('UnionConversions', curr)
 
         # Done.
         return curr