Bug 812783. Add support for flagging callbacks as worker-only. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 29 Nov 2012 11:14:40 -0500
changeset 123612 a56c5c4bb2bd00529cecf0c73ad929e9f28e43c1
parent 123611 3e1e34df0e83fd06abf98e7c44301fc840860ef5
child 123613 d263e80907f9c1334db6312247a8f056c7909c6a
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs812783
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 812783. Add support for flagging callbacks as worker-only. r=khuey
dom/bindings/Codegen.py
dom/bindings/parser/WebIDL.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -6620,33 +6620,39 @@ class CGBindingRoot(CGThing):
                                             skipGen=False)
         dictionaries = config.getDictionaries(webIDLFile)
         callbacks = config.getCallbacks(webIDLFile)
 
         forwardDeclares = [CGClassForwardDeclare('XPCWrappedNativeScope')]
 
         descriptorsForForwardDeclaration = list(descriptors)
         ifaces = []
+        workerIfaces = []
         for dictionary in dictionaries:
-            ifaces.extend(type.unroll().inner
-                          for type in getTypesFromDictionary(dictionary)
-                          if type.unroll().isGeckoInterface())
+            dictionaryIfaces = [ type.unroll().inner
+                                 for type in getTypesFromDictionary(dictionary)
+                                 if type.unroll().isGeckoInterface() ]
+            ifaces.extend(dictionaryIfaces)
+            workerIfaces.extend(dictionaryIfaces)
 
         for callback in callbacks:
-            ifaces.extend(t.unroll().inner
-                          for t in getTypesFromCallback(callback)
-                          if t.unroll().isGeckoInterface())
+            callbackIfaces = [ t.unroll().inner
+                               for t in getTypesFromCallback(callback)
+                               if t.unroll().isGeckoInterface() ]
+            workerIfaces.extend(callbackIfaces)
+            if not callback.isWorkerOnly():
+                ifaces.extend(callbackIfaces)
 
         # Put in all the non-worker descriptors
         descriptorsForForwardDeclaration.extend(
             config.getDescriptor(iface.identifier.name, False) for
             iface in ifaces)
         # And now the worker ones.  But these may not exist, so we
         # have to be more careful.
-        for iface in ifaces:
+        for iface in workerIfaces:
             try:
                 descriptorsForForwardDeclaration.append(
                     config.getDescriptor(iface.identifier.name, True))
             except NoSuchDescriptorError:
                 # just move along
                 pass
 
         def declareNativeType(nativeType):
@@ -7343,16 +7349,19 @@ class CGExampleRoot(CGThing):
     def declare(self):
         return self.root.declare()
 
     def define(self):
         return self.root.define()
 
 class CGCallbackFunction(CGClass):
     def __init__(self, callback, descriptorProvider):
+        if callback.isWorkerOnly() and not descriptorProvider.workers:
+            self.generatable = False
+            return
         name = callback.identifier.name
         if descriptorProvider.workers:
             name += "Workers"
         try:
             # For our public Call() method we want most of the same args and the
             # same return type as what CallCallback generates.  So we want to
             # take advantage of all its CGNativeMember infrastructure, but that
             # infrastructure can't deal with templates and most especially
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -2274,16 +2274,17 @@ class IDLCallbackType(IDLType, IDLObject
 
         IDLObjectWithScope.__init__(self, location, parentScope, identifier)
 
         for (returnType, arguments) in self.signatures():
             for argument in arguments:
                 argument.resolve(self)
 
         self._treatNonCallableAsNull = False
+        self._workerOnly = False
 
     def isCallback(self):
         return True
 
     def signatures(self):
         return [(self._returnType, self._arguments)]
 
     def tag(self):
@@ -2314,21 +2315,26 @@ class IDLCallbackType(IDLType, IDLObject
 
     def isDistinguishableFrom(self, other):
         if other.isUnion():
             # Just forward to the union; it'll deal
             return other.isDistinguishableFrom(self)
         return (other.isPrimitive() or other.isString() or other.isEnum() or
                 other.isNonCallbackInterface() or other.isDate())
 
+    def isWorkerOnly(self):
+        return self._workerOnly
+
     def addExtendedAttributes(self, attrs):
         unhandledAttrs = []
         for attr in attrs:
             if attr.identifier() == "TreatNonCallableAsNull":
                 self._treatNonCallableAsNull = True
+            elif attr.identifier() == "WorkerOnly":
+                self._workerOnly = True
             else:
                 unhandledAttrs.append(attr)
         if len(unhandledAttrs) != 0:
             IDLType.addExtendedAttributes(self, unhandledAttrs)
 
 class IDLMethodOverload:
     """
     A class that represents a single overload of a WebIDL method.  This is not