Pass references for non-nullable interface args
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 11 Feb 2012 23:20:06 -0500
changeset 86755 6532286d5c6192898603ba1af901b81e507b7ee0
parent 86754 147cdb4f2a852a96fbaa1fcae4cf3d38ceaeda1e
child 86756 8cf0a37a7936f39e3d2b507d5820fe5979e67f3f
push id107
push userbzbarsky@mozilla.com
push dateSun, 12 Feb 2012 04:20:12 +0000
milestone13.0a1
Pass references for non-nullable interface args
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -531,36 +531,47 @@ class FailureFatalConcreteObjectUnwrappe
     As ConcreteObjectUnwrapper, but defaulting to throwing if unwrapping fails
     """
     def __init__(self, descriptor, source, target):
         ConcreteObjectUnwrapper.__init__(self, descriptor, source, target,
                                          "xpc_qsThrow(cx, rv);")
 
 def getArgumentConversionTemplate(type, descriptor):
     if descriptor is not None:
+        assert(type.isInterface())
         # This is an interface that we implement as a concrete class
         # or an XPCOM interface.
-        template = ("  ${typeName} *${name};\n"
-                    "  if (${argVal}.isObject()) {")
+        if type.nullable():
+            nameSuffix = ""
+        else:
+            nameSuffix = "_ptr"
+        template = "  ${typeName} *${name}%s;\n" % nameSuffix
+
+        template += "  if (${argVal}.isObject()) {"
         if descriptor.concrete:
-            template += str(FailureFatalConcreteObjectUnwrapper(descriptor,
-                                                                "&${argVal}.toObject()",
-                                                                "${name}")).replace("\n", "\n  ") + "\n"
+            template += str(FailureFatalConcreteObjectUnwrapper(
+                    descriptor,
+                    "&${argVal}.toObject()",
+                    "${name}"+nameSuffix)).replace("\n", "\n  ") + "\n"
         else:
             raise TypeError("Can't handle this interface type yet, becase we "
                             "have no support for unwrapping non-concrete types: " + type)
         if type.nullable():
-            template = template + (
+            template += (
                 "  } else if (${argVal}.isNullOrUndefined()) {\n"
-                "    ${name} = NULL;\n")
+                "    ${name}%s = NULL;\n" % nameSuffix)
 
-        template = template + (
+        template += (
             "  } else {\n"
             "    return xpc_qsThrow(cx, NS_ERROR_XPC_BAD_CONVERT_JS);\n"
             "  }\n")
+
+        if not type.nullable():
+            template += "  ${typeName} &${name} = *${name}_ptr;\n"
+            
         return template
 
     try:
         if type.tag() is IDLType.Tags.domstring:
             # XXXbz Need to figure out string behavior?  Also, how to
             # detect them?  Also, nullability?
             
             return (