Add functionality for getting the correct descriptor for an interface given context (ie, worker vs non-worker).
authorBobby Holley <bobbyholley@gmail.com>
Wed, 08 Feb 2012 13:46:41 -0800
changeset 86464 979451d9d4167e15d2eb787458652e673877e394
parent 86463 bab09b5e0e9fb52b17668a3aac86e1baf27b3138
child 86465 3d27529bc495956a38f878bb559b242bd540bd6e
push id99
push userbobbyholley@gmail.com
push dateWed, 08 Feb 2012 21:46:58 +0000
milestone13.0a1
Add functionality for getting the correct descriptor for an interface given context (ie, worker vs non-worker).
dom/bindings/Codegen.py
dom/bindings/Configuration.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -695,16 +695,25 @@ class PerSignatureCall():
     def getArgv(self):
         assert(False) # Override me
     def getArgc(self):
         assert(False) # Override me
     def getErrorReport(self):
         assert(False) # Override me
 
     def unwrap_arguments(self):
+
+        # XXXbholley - This is just proof of concept code for bz to do something
+        # useful with.
+        for i in range(len(self.arguments)):
+            argType = self.arguments[i].type
+            if argType.isInterface():
+                argDescriptor = self.descriptor.getDescriptor(str(argType))
+                assert self.descriptor.workers == argDescriptor.workers
+
         args = [ArgumentConverter(self.arguments[i], i, self.getArgv(),
                                   self.getArgc()) for
                 i in range(len(self.arguments))]
         return "".join([str(arg) for arg in args])
 
     def generate_call(self):
         # XXXbz add provisions for infallible calls here?
         nativeArgs = ["arg" + str(i) for i in range(len(self.arguments))]
--- a/dom/bindings/Configuration.py
+++ b/dom/bindings/Configuration.py
@@ -24,38 +24,39 @@ class Configuration:
         for iface in parseData:
             if not iface.isInterface(): continue
             self.interfaces[iface.identifier.name] = iface
             if iface.identifier.name not in config: continue
             entry = config[iface.identifier.name]
             if not isinstance(entry, list):
                 assert isinstance(entry, dict)
                 entry = [entry]
-            self.descriptors.extend([Descriptor(iface, x) for x in entry])
+            self.descriptors.extend([Descriptor(self, iface, x) for x in entry])
 
         # Keep the descriptor list sorted for determinism.
         self.descriptors.sort(lambda x,y: cmp(x.name, y.name))
 
     def getInterface(self, ifname):
         return self.interfaces[ifname]
     def getAllDescriptors(self, webIDLFile=None):
         if not webIDLFile:
             return self.descriptors
         else:
             return filter(lambda x: x.interface.filename() == webIDLFile, self.descriptors)
     def getConcreteDescriptors(self, webIDLFile=None):
         return filter(lambda x: x.concrete, self.getAllDescriptors(webIDLFile))
-    def getDesciptorsForInterface(self, iface):
+    def getDescriptorsForInterface(self, iface):
         return filter(lambda x: x.interface is iface, self.descriptors)
 
 class Descriptor:
     """
     Represents a single descriptor for an interface. See Bindings.conf.
     """
-    def __init__(self, interface, desc):
+    def __init__(self, config, interface, desc):
+        self.config = config
         self.interface = interface
 
         # Read the desc, and fill in the relevant defaults.
         self.concrete = desc['concrete']
         self.workers = desc.get('workers', False)
         self.nativeIsISupports = not self.workers
         if self.concrete:
             self.nativeClass = desc['nativeClass']
@@ -75,8 +76,23 @@ class Descriptor:
 
         # Build the prototype chain.
         self.prototypeChain = []
         parent = interface
         while parent:
             self.prototypeChain.insert(0, make_name(parent.identifier.name))
             parent = parent.parent
 
+    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.
+        """
+        iface = self.config.getInterface(interfaceName)
+        descriptors = self.config.getDescriptorsForInterface(iface)
+
+        # The only filter we currently have is workers vs non-workers.
+        matches = filter(lambda x: x.workers is self.workers, descriptors)
+
+        # After filtering, we should have exactly one result.
+        assert len(matches) is 1
+        return matches[0]