Pass the full descriptor and idl node instead of scriptableInterfaceAndName.
authorBobby Holley <bobbyholley@gmail.com>
Wed, 08 Feb 2012 13:46:41 -0800
changeset 86462 6fb6b364892fe283c35433e454613ba492d263f5
parent 86461 6cf8fbd470bacafccf8ff7c0b812d51c4fee5f39
child 86463 bab09b5e0e9fb52b17668a3aac86e1baf27b3138
push id99
push userbobbyholley@gmail.com
push dateWed, 08 Feb 2012 21:46:58 +0000
milestone13.0a1
Pass the full descriptor and idl node instead of scriptableInterfaceAndName.
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -663,35 +663,39 @@ class PerSignatureCall():
     1) A return type, which can be None to indicate that there is no
        actual return value (e.g. this is an attribute setter) or an
        IDLType if there's an IDL type involved (including |void|).
     2) An argument list, which is allowed to be empty.
     3) A name of a native method to call.
 
     We also need to know whether this is a method or a getter/setter
     to do error reporting correctly.
+
+    The idlNode parameter can be either a method or an attr. We can query
+    |idlNode.identifier| in both cases, so we can be agnostic between the two.
     """
     # XXXbz For now each entry in the argument list is either an
     # IDLArgument or a FakeArgument, but longer-term we may want to
     # have ways of flagging things like JSContext* or optional_argc in
     # there.
     
     # XXXbz void methods have a signature with a isVoid() type object
     #       as first element.  Methods with no args have length-0 arg
     #       lists as second element in signaure.
     # XXXbz if isInterface() true on a type, type.inner is the interface object
     # XXXbz is isPrimitive() true on a type, then .tag() will return an
     #       IDLType.Tags value.  So you can compare
     #       type.tag() == IDLType.Tags.int8 or whatever.
     def __init__(self, returnType, arguments, nativeMethodName,
-                 scriptableInterfaceAndName):
+                 descriptor, idlNode):
         self.returnType = returnType
         self.arguments = arguments
         self.nativeMethodName = nativeMethodName
-        self.scriptableInterfaceAndName = scriptableInterfaceAndName
+        self.descriptor = descriptor
+        self.idlNode = idlNode
 
     def getArgv(self):
         assert(False) # Override me
     def getArgc(self):
         assert(False) # Override me
     def getErrorReport(self):
         assert(False) # Override me
 
@@ -728,27 +732,28 @@ class PerSignatureCall():
     def wrap_return_value(self):
         resultTemplateValues = {'jsvalRef': '*vp', 'jsvalPtr': 'vp'}
         return string.Template(
             getWrapTemplateForType(self.returnType)
             ).substitute(resultTemplateValues)
 
     def getErrorReport(self):
         return """
-    return xpc_qsThrowMethodFailedWithDetails(cx, rv, "%s", "%s");""" % self.scriptableInterfaceAndName
+    return xpc_qsThrowMethodFailedWithDetails(cx, rv, "%s", "%s");""" % (self.descriptor.name,
+                                                                         self.idlNode.identifier.name)
 
     def __str__(self):
         return (self.unwrap_arguments() + self.generate_call() +
                 self.wrap_return_value())
 
 class PerSignatureMethodCall(PerSignatureCall):
     def __init__(self, returnType, arguments, nativeMethodName,
-                 scriptableInterfaceAndName):
+                 descriptor, method):
         PerSignatureCall.__init__(self, returnType, arguments, nativeMethodName,
-                                  scriptableInterfaceAndName)
+                                  descriptor, method)
     def getArgv(self):
         return "argv" if len(self.arguments) > 0 else ""
     def getArgc(self):
         return "argc"
     def unwrap_arguments(self):
         requiredArgs = len(self.arguments)
         while requiredArgs and self.arguments[requiredArgs-1].optional:
             requiredArgs -= 1
@@ -758,39 +763,39 @@ class PerSignatureMethodCall(PerSignatur
   // up-front somewhere, not per-signature?
   if (argc < %d) {
     return xpc_qsThrow(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
   }
   %s""" % (requiredArgs, argv)) + PerSignatureCall.unwrap_arguments(self)
 
 class GetterSetterCall(PerSignatureCall):
     def __init__(self, returnType, arguments, nativeMethodName,
-                 scriptableInterfaceAndName):
+                 descriptor, attr):
         PerSignatureCall.__init__(self, returnType, arguments, nativeMethodName,
-                                  scriptableInterfaceAndName)
+                                  descriptor, attr)
     def getArgv(self):
         return "vp"
 
 class GetterCall(GetterSetterCall):
     def __init__(self, returnType, nativeMethodName,
-                 scriptableInterfaceAndName):
+                 descriptor, attr):
         GetterSetterCall.__init__(self, returnType, [], nativeMethodName,
-                                  scriptableInterfaceAndName)
+                                  descriptor, attr)
     def getArgc(self):
         return "0"
 
 class FakeArgument():
     def __init__(self, type):
         self.type = type
         self.optional = False
 
 class SetterCall(GetterSetterCall):
-    def __init__(self, argType, nativeMethodName, scriptableInterfaceAndName):
+    def __init__(self, argType, nativeMethodName, descriptor, attr):
         GetterSetterCall.__init__(self, None, [FakeArgument(argType)],
-                                  nativeMethodName, scriptableInterfaceAndName)
+                                  nativeMethodName, descriptor, attr)
     def wrap_return_value(self):
         # We have no return value
         return "\n  return true;"
     def getArgc(self):
         return "1"
 
 class CGAbstractBindingMethod(CGAbstractStaticMethod):
     def __init__(self, descriptor, name, returnType, args):
@@ -826,51 +831,49 @@ class CGNativeMethod(CGAbstractBindingMe
          return """
   JSObject *obj = JS_THIS_OBJECT(cx, vp);
   if (!obj)
     return false;""" + CGAbstractBindingMethod.unwrap_this(self)
 
     def generate_code(self):
         signatures = self.method.signatures()
         nativeName = MakeNativeName(self.method.identifier.name)
-        callGenerators = [PerSignatureMethodCall(s[0], s[1], nativeName,
-                                                 (self.descriptor.name,
-                                                  self.method.identifier.name))
+        callGenerators = [PerSignatureMethodCall(s[0], s[1], nativeName, self.descriptor, self.method)
                           for s in signatures]
         if len(callGenerators) != 1:
             raise TypeError("Don't know how to handle overloads yet.  Will need to generate code to pick the right overload based on the arguments, then jump to the right generated code")
 
         return str(callGenerators[0]);
 
 class CGNativeGetter(CGAbstractBindingMethod):
     def __init__(self, descriptor, attr):
         self.attr = attr
         args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'obj'),
                 Argument('jsid', 'id'), Argument('JS::Value*', 'vp')]
         CGAbstractBindingMethod.__init__(self, descriptor,
                                          'get_'+attr.identifier.name,
                                          'JSBool', args)
     def generate_code(self):
         nativeMethodName = "Get" + MakeNativeName(self.attr.identifier.name)
-        return str(GetterCall(self.attr.type, nativeMethodName,
-                              (self.descriptor.name, self.attr.identifier.name)))
+        return str(GetterCall(self.attr.type, nativeMethodName, self.descriptor,
+                              self.attr))
 
 class CGNativeSetter(CGAbstractBindingMethod):
     def __init__(self, descriptor, attr):
         self.attr = attr
         args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'obj'),
                 Argument('jsid', 'id'), Argument('JSBool', 'strict'),
                 Argument('JS::Value*', 'vp')]
         CGAbstractBindingMethod.__init__(self, descriptor,
                                          'set_'+attr.identifier.name,
                                          'JSBool', args)
     def generate_code(self):
         nativeMethodName = "Set" + MakeNativeName(self.attr.identifier.name)
-        return str(SetterCall(self.attr.type, nativeMethodName,
-                              (self.descriptor.name, self.attr.identifier.name)))
+        return str(SetterCall(self.attr.type, nativeMethodName, self.descriptor,
+                              self.attr))
 
 class CGDescriptor(CGThing):
     def __init__(self, descriptor):
         CGThing.__init__(self)
 
         # XXXbholley - Not everything should actually have a jsclass.
         cgThings = [CGNativeMethod(descriptor, m) for m in
                     descriptor.interface.members if m.isMethod()]