Support wrapping nullable primitive types.
authorMs2ger <ms2ger@gmail.com>
Sun, 12 Feb 2012 18:08:33 +0100
changeset 86762 b91d5bfbf6587600c194ce7c98adf945574e07ec
parent 86761 107a869cc8618ed6c0863b08bb49e5dd10c6aafb
child 86763 e1bd74e88ad2d4b5e369113a633fe2ebc5fbbce9
push id109
push userMs2ger@gmail.com
push dateSun, 12 Feb 2012 17:09:25 +0000
milestone13.0a1
Support wrapping nullable primitive types.
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -751,17 +751,22 @@ def getWrapTemplateForTypeImpl(type, res
   return xpc::NonVoidStringToJsval(cx, %s, ${jsvalPtr});""" % result
 
     if not type.isPrimitive():
         return """
   // XXXbz need to learn to wrap other things
   return false;"""
 
     if type.nullable():
-        raise TypeError("We don't support nullable primitive return types yet")
+        return """
+  if (%s.IsNull()) {
+    ${jsvalRef} = JSVAL_NULL;
+    return true;
+  }
+%s""" % (result, getWrapTemplateForTypeImpl(type.inner, "%s.Value()" % result))
     
     tag = type.tag()
     
     if tag in [IDLType.Tags.int8, IDLType.Tags.uint8, IDLType.Tags.int16,
                IDLType.Tags.uint16, IDLType.Tags.int32]:
         return """
   ${jsvalRef} = INT_TO_JSVAL(int32_t(%s));
   return true;""" % result
@@ -860,17 +865,20 @@ class PerSignatureCall():
         # XXXbz arguments that have to go in outparams go here?
         if self.isFallible():
             nativeArgs.append("rv")
         # XXXbz need to have full config to do this retval business right
         if self.returnType is None or self.returnType.isVoid():
             # Nothing to declare.
             resultDeclaration = ""
         elif self.returnType.isPrimitive() and self.returnType.tag() in builtinNames:
-            resultDeclaration = "  %s result = 0;\n" % builtinNames[self.returnType.tag()]
+            if self.returnType.nullable():
+                resultDeclaration = "  Nullable<%s> result;\n" % builtinNames[self.returnType.tag()]
+            else:
+                resultDeclaration = "  %s result = 0;\n" % builtinNames[self.returnType.tag()]
         elif self.returnType.isString():
             resultDeclaration = "  nsAutoString result;\n"
         else:
             resultDeclaration = "  // XXX need to declare |result| for type %s.\n" % self.returnType
 
         if self.isFallible():
             rvDeclaration =  '  nsresult rv = NS_OK;\n'
             errorCheckClause = '  if (NS_FAILED(rv)) {\n    %s\n  }\n' \