Bug 1257037 part 8. Remove Configuration.getDescriptorProvider. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 08 Jul 2016 00:37:54 -0400
changeset 385446 4c5ea0b7a3d109be6e8f20e623c3530205432f63
parent 385445 2de33eb0bb321a55cd66168d2440281b5420d466
child 385447 4565bfc8b866fd71c33201179daeb9ead66419fd
push id22506
push userbmo:lissyx+mozillians@lissyx.dyndns.org
push dateFri, 08 Jul 2016 10:46:25 +0000
reviewerskhuey
bugs1257037
milestone50.0a1
Bug 1257037 part 8. Remove Configuration.getDescriptorProvider. r=khuey
dom/bindings/Codegen.py
dom/bindings/Configuration.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -976,21 +976,17 @@ class CGIncludeGuard(CGWrapper):
         CGWrapper.__init__(self, child,
                            declarePre='#ifndef %s\n#define %s\n\n' % (define, define),
                            declarePost='\n#endif // %s\n' % define)
 
 
 def getRelevantProviders(descriptor, config):
     if descriptor is not None:
         return [descriptor]
-    # Do both the non-worker and worker versions
-    return [
-        config.getDescriptorProvider(False),
-        config.getDescriptorProvider(True)
-    ]
+    return [config]
 
 
 class CGHeaders(CGWrapper):
     """
     Generates the appropriate include statements.
     """
     def __init__(self, descriptors, dictionaries, callbacks,
                  callbackDescriptors,
@@ -13462,19 +13458,16 @@ class CGBindingRoot(CGThing):
         callbackDescriptors = config.getDescriptors(webIDLFile=webIDLFile,
                                                     isCallback=True)
         jsImplemented = config.getDescriptors(webIDLFile=webIDLFile,
                                               isJSImplemented=True)
         bindingDeclareHeaders["nsWeakReference.h"] = jsImplemented
         bindingHeaders["nsIGlobalObject.h"] = jsImplemented
         bindingHeaders["AtomList.h"] = hasNonEmptyDictionaries or jsImplemented or callbackDescriptors
 
-        # Only mainthread things can have hasXPConnectImpls
-        provider = config.getDescriptorProvider(False)
-
         def descriptorClearsPropsInSlots(descriptor):
             if not descriptor.wrapperCache:
                 return False
             return any(m.isAttr() and m.getExtendedAttribute("StoreInSlot")
                        for m in descriptor.interface.members)
         bindingHeaders["nsJSUtils.h"] = any(descriptorClearsPropsInSlots(d) for d in descriptors)
 
         # Do codegen for all the enums
@@ -13542,31 +13535,29 @@ class CGBindingRoot(CGThing):
             if isinstance(unionTypeOrDictionary, IDLDictionary):
                 return unionTypeOrDictionary.identifier.name
 
             assert unionTypeOrDictionary.isType() and unionTypeOrDictionary.isUnion()
             return unionTypeOrDictionary.name
 
         for t in dependencySortObjects(dictionaries + unionStructs, getDependencies, getName):
             if t.isDictionary():
-                cgthings.append(CGDictionary(t, config.getDescriptorProvider(False)))
+                cgthings.append(CGDictionary(t, config))
             else:
                 assert t.isUnion()
-                # FIXME: Unions are broken in workers.  See bug 809899.
-                cgthings.append(CGUnionStruct(t, config.getDescriptorProvider(False)))
-                cgthings.append(CGUnionStruct(t, config.getDescriptorProvider(False), True))
+                cgthings.append(CGUnionStruct(t, config))
+                cgthings.append(CGUnionStruct(t, config, True))
 
         # Do codegen for all the callbacks.
-        cgthings.extend(CGCallbackFunction(c, config.getDescriptorProvider(False))
-                        for c in mainCallbacks)
+        cgthings.extend(CGCallbackFunction(c, config) for c in mainCallbacks)
 
         cgthings.extend([CGNamespace('binding_detail', CGFastCallback(c))
                          for c in mainCallbacks])
 
-        cgthings.extend(CGCallbackFunction(c, config.getDescriptorProvider(True))
+        cgthings.extend(CGCallbackFunction(c, config)
                         for c in workerCallbacks if c not in mainCallbacks)
 
         cgthings.extend([CGNamespace('binding_detail', CGFastCallback(c))
                          for c in workerCallbacks if c not in mainCallbacks])
 
         # Do codegen for all the descriptors
         cgthings.extend([CGDescriptor(x) for x in descriptors])
 
@@ -16443,18 +16434,18 @@ class GlobalGenRoots():
     def UnionTypes(config):
         unionTypes = UnionsForFile(config, None)
         (includes, implincludes, declarations,
          traverseMethods, unlinkMethods,
          unionStructs) = UnionTypes(unionTypes, config)
 
         unions = CGList(traverseMethods +
                         unlinkMethods +
-                        [CGUnionStruct(t, config.getDescriptorProvider(False)) for t in unionStructs] +
-                        [CGUnionStruct(t, config.getDescriptorProvider(False), True) for t in unionStructs],
+                        [CGUnionStruct(t, config) for t in unionStructs] +
+                        [CGUnionStruct(t, config, True) for t in unionStructs],
                         "\n")
 
         includes.add("mozilla/OwningNonNull.h")
         includes.add("mozilla/dom/UnionMember.h")
         includes.add("mozilla/dom/BindingDeclarations.h")
         # Need BindingUtils.h for FakeString
         includes.add("mozilla/dom/BindingUtils.h")
         implincludes.add("mozilla/dom/PrimitiveConversions.h")
--- a/dom/bindings/Configuration.py
+++ b/dom/bindings/Configuration.py
@@ -6,38 +6,30 @@ from WebIDL import IDLImplementsStatemen
 import os
 from collections import defaultdict
 
 autogenerated_comment = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n"
 
 
 class DescriptorProvider:
     """
-    A way of getting descriptors for interface names
+    A way of getting descriptors for interface names.  Subclasses must
+    have a getDescriptor method callable with the interface name only.
     """
-    def __init__(self, config, workers):
-        self.config = config
-        self.workers = workers
-
-    def getDescriptor(self, interfaceName):
-        """
-        Gets the appropriate descriptor for the given interface name given the
-        context of the current descriptor. This selects the appropriate
-        implementation for cases like workers.
-        """
-        return self.config.getDescriptor(interfaceName, self.workers)
+    def __init__(self):
+        pass
 
 
 class Configuration(DescriptorProvider):
     """
     Represents global configuration state based on IDL parse data and
     the configuration file.
     """
     def __init__(self, filename, parseData, generatedEvents=[]):
-        DescriptorProvider.__init__(self, self, False)
+        DescriptorProvider.__init__(self)
 
         # Read the configuration file.
         glbl = {}
         execfile(filename, glbl)
         config = glbl['DOMInterfaces']
 
         # Build descriptors for all the interfaces we have in the parse data.
         # This allows callers to specify a subset of interfaces by filtering
@@ -279,17 +271,17 @@ class Configuration(DescriptorProvider):
         return items
 
     def getDictionaries(self, **filters):
         return self._filterForFileAndWorkers(self.dictionaries, filters)
 
     def getCallbacks(self, **filters):
         return self._filterForFileAndWorkers(self.callbacks, filters)
 
-    def getDescriptor(self, interfaceName, workers):
+    def getDescriptor(self, interfaceName, workers=False):
         """
         Gets the appropriate descriptor for the given interface name
         and the given workers boolean.
         """
         # We may have optimized out this descriptor, but the chances of anyone
         # asking about it are then slim.  Put the check for that _after_ we've
         # done our normal lookups.  But that means we have to do our normal
         # lookups in a way that will not throw if they fail.
@@ -304,23 +296,16 @@ class Configuration(DescriptorProvider):
         if interfaceName in self.optimizedOutDescriptorNames:
             raise NoSuchDescriptorError(
                 "No descriptor for '%s', which is a mixin ([NoInterfaceObject] "
                 "and a consequential interface) without an explicit "
                 "Bindings.conf annotation." % interfaceName)
 
         raise NoSuchDescriptorError("For " + interfaceName + " found no matches")
 
-    def getDescriptorProvider(self, workers):
-        """
-        Gets a descriptor provider that can provide descriptors as needed,
-        for the given workers boolean
-        """
-        return DescriptorProvider(self, workers)
-
 
 class NoSuchDescriptorError(TypeError):
     def __init__(self, str):
         TypeError.__init__(self, str)
 
 
 def methodReturnsJSObject(method):
     assert method.isMethod()
@@ -346,17 +331,19 @@ def MemberIsUnforgeable(member, descript
                  descriptor.interface.getExtendedAttribute("Unforgeable")))
 
 
 class Descriptor(DescriptorProvider):
     """
     Represents a single descriptor for an interface. See Bindings.conf.
     """
     def __init__(self, config, interface, desc):
-        DescriptorProvider.__init__(self, config, desc.get('workers', False))
+        DescriptorProvider.__init__(self)
+        self.config = config
+        self.workers = desc.get('workers', False)
         self.interface = interface
 
         if self.workers:
             assert 'wantsXrays' not in desc
             self.wantsXrays = False
         else:
             self.wantsXrays = desc.get('wantsXrays', True)
 
@@ -832,16 +819,24 @@ class Descriptor(DescriptorProvider):
     @property
     def registersGlobalNamesOnWindow(self):
         return (not self.interface.isExternal() and
                 self.interface.hasInterfaceObject() and
                 not self.workers and
                 self.interface.isExposedInWindow() and
                 self.register)
 
+    def getDescriptor(self, interfaceName):
+        """
+        Gets the appropriate descriptor for the given interface name given the
+        context of the current descriptor. This selects the appropriate
+        implementation for cases like workers.
+        """
+        return self.config.getDescriptor(interfaceName, self.workers)
+
 
 # Some utility methods
 def getTypesFromDescriptor(descriptor):
     """
     Get all argument and return types for all members of the descriptor
     """
     members = [m for m in descriptor.interface.members]
     if descriptor.interface.ctor():