Add support for Any results, sorta
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 13 Feb 2012 18:02:01 -0500
changeset 86819 0f84963ad48e9175134e557e3ec8b743d783f202
parent 86818 0824a12c5564992db4685507c0915273afbf87cd
child 86820 61d5493255ff9a8ed1d71546efcbfd9b00d8d089
push id122
push userbzbarsky@mozilla.com
push dateMon, 13 Feb 2012 23:02:48 +0000
milestone13.0a1
Add support for Any results, sorta
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -610,18 +610,17 @@ def getArgumentConversionTemplate(type, 
             "  JSObject *${name};\n"
             "  if (${argVal}.isObject() && JS_ObjectIsCallable(cx, &${argVal}.toObject())) {\n"
             "    ${name} = &${argVal}.toObject();\n"
             "  } else {\n"
             "    ${name} = NULL;\n"
             "  }\n")
 
     if not type.isPrimitive():
-        return """
-  // XXXbz Need conversion for argument type '%s'""" % type
+        raise TypeError("Need conversion for argument type '%s'" % type)
 
     tag = type.tag()
     replacements = dict()
     if type.nullable():
         replacements["declareArg"] = (
             "  Nullable<${typeName}> ${name};\n"
             "  if (${argVal}.isNullOrUndefined()) {\n"
             "    ${name}.SetNull();\n"
@@ -810,20 +809,23 @@ def getWrapTemplateForTypeImpl(type, res
 
     if type.isCallback() and not type.isInterface():
         # XXXbz we're going to assume that callback types are always
         # nullable and always have [TreatNonCallableAsNull] for now.
         return """
   ${jsvalRef} = JS::ObjectOrNullValue(%s);
   return true;""" % result
 
-    if not type.isPrimitive():
+    if type.tag() == IDLType.Tags.any:
         return """
-  // XXXbz need to learn to wrap %s
-  return false;""" % type
+  ${jsvalRef} = %s;\n
+  return true;""" % result
+
+    if not type.isPrimitive():
+        raise TypeError("Need to learn to wrap %s" % type)
 
     if type.nullable():
         return """
   if (%s.IsNull()) {
     ${jsvalRef} = JSVAL_NULL;
     return true;
   }
 %s""" % (result, getWrapTemplateForTypeImpl(type.inner, "%s.Value()" % result,
@@ -851,19 +853,17 @@ def getWrapTemplateForTypeImpl(type, res
   return true;""" % result
 
     elif tag == IDLType.Tags.bool:
         return """
   ${jsvalRef} = BOOLEAN_TO_JSVAL(%s);
   return true;""" % result
 
     else:
-        return """
-  // XXXbz need to learn to wrap other things
-  return false;"""
+        raise TypeError("Need to learn to wrap primitive: %s" % type)
 
 def getWrapTemplateForType(type, descriptorProvider, resultAlreadyAddRefed):
     return getWrapTemplateForTypeImpl(type, "result", descriptorProvider,
                                       resultAlreadyAddRefed)
 
 
 class PerSignatureCall():
     """
@@ -948,18 +948,21 @@ class PerSignatureCall():
                 resultDeclaration = "  nsRefPtr<%s> result;\n"
             resultDescriptor = self.descriptor.getDescriptor(
                 self.returnType.inner.identifier.name)
             resultDeclaration = resultDeclaration % resultDescriptor.typeName
         elif self.returnType.isCallback():
             # XXXbz we're going to assume that callback types are always
             # nullable for now.
             resultDeclaration = "  JSObject* result = NULL;\n"
+        elif self.returnType.tag() == IDLType.Tags.any:
+            resultDeclaration = "  jsval result;\n"
         else:
-            resultDeclaration = "  // XXX need to declare |result| for type %s.\n" % self.returnType
+            raise TypeError("Don't know how to declare return value for %s" %
+                            self.returnType)
 
         if self.returnType is None or self.returnType.isVoid():
             resultAssignment = ""
         else:
             resultAssignment = "result = "
 
         if self.isFallible():
             rvDeclaration =  '  nsresult rv = NS_OK;\n'