Move all the wrap template getting into the helper function
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 07 Feb 2012 15:55:55 -0500
changeset 86011 9a987b9287c584246387b9470211b0bf2eba2312
parent 86010 61b7ed2e15b26d8ae45d8e617e2f1cfa1d438b34
child 86012 c22458a8e35d46f417c1b1938444c69f6d9fb2e5
push id91
push userbzbarsky@mozilla.com
push dateTue, 07 Feb 2012 20:56:01 +0000
milestone13.0a1
Move all the wrap template getting into the helper function
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -397,17 +397,35 @@ builtinNames = {
     IDLType.Tags.int64: 'int64_t',
     IDLType.Tags.uint16: 'uint16_t',
     IDLType.Tags.uint32: 'uint32_t',
     IDLType.Tags.uint64: 'uint64_t',
     IDLType.Tags.float: 'float',
     IDLType.Tags.double: 'double'
 }
 
-def getWrapTemplateForTag(tag):
+def getWrapTemplateForType(type):
+    if type.isVoid():
+        return """
+  ${jsvalRef} = JSVAL_VOID;
+  return true;"""
+
+    if type.isInterface():
+        # Wrap the object
+            return """
+  // XXXbz need to learn to wrap objects
+  return false;"""
+
+    if not type.isPrimitive():
+        return """
+  // XXXbz need to learn to wrap other things
+  return false;"""
+
+    tag = type.tag()
+    
     if tag in [IDLType.Tags.uint8, IDLType.Tags.int16, IDLType.Tags.int32, IDLType.Tags.uint16]:
         return """
   ${jsvalRef} = INT_TO_JSVAL(int32_t(result));
   return true;"""
 
     elif tag in [IDLType.Tags.int64, IDLType.Tags.uint64, IDLType.Tags.float, IDLType.Tags.double]:
         return """
   return JS_NewNumberValue(cx, double(result), ${jsvalPtr});"""
@@ -483,34 +501,20 @@ class PerSignatureCall():
   // XXXbz need to actually make those methods exist!
 #if 0
   self->%s(%s);
 #endif
   if (NS_FAILED(rv)) {%s
   }""" % (resultDeclaration, self.nativeMethodName, ', '.join(nativeArgs), self.getErrorReport())
 
     def wrap_return_value(self):
-        if self.returnType.isVoid():
-            return """
-  *vp = JSVAL_VOID;
-  return true;"""
-
-        if self.returnType.isInterface():
-            # Wrap the object
-            return """
-  // XXXbz need to learn to wrap objects
-  return false;"""
-
         resultTemplateValues = {'jsvalRef': '*vp', 'jsvalPtr': 'vp'}
-        if self.returnType.isPrimitive():
-            return "\n" + string.Template(getWrapTemplateForTag(self.returnType.tag())).substitute(resultTemplateValues)
-
-        return """
-  // XXXbz need to learn to wrap other things
-  return false;"""
+        return string.Template(
+            getWrapTemplateForType(self.returnType)
+            ).substitute(resultTemplateValues)
 
     def getErrorReport(self):
         return """
     return xpc_qsThrowMethodFailedWithDetails(cx, rv, "%s", "%s");""" % self.scriptableInterfaceAndName
 
     def __str__(self):
         return (self.unwrap_arguments() + self.generate_call() +
                 self.wrap_return_value())
@@ -534,17 +538,17 @@ class GetterCall(GetterSetterCall):
                                   scriptableInterfaceAndName)
 
 class SetterCall(GetterSetterCall):
     def __init__(self, argType, nativeMethodName, scriptableInterfaceAndName):
         GetterSetterCall.__init__(self, None, [argType], nativeMethodName,
                                   scriptableInterfaceAndName)
     def wrap_return_value(self):
         # We have no return value
-        return "\n return true;"
+        return "\n  return true;"
 
 class CGAbstractBindingMethod(CGAbstractStaticMethod):
     def __init__(self, descriptor, name, returnType, args):
         CGAbstractStaticMethod.__init__(self, descriptor, name,
                                         returnType, args)
     def definition_body(self):
         return (self.unwrap_this() + self.generate_code())