Allow wrapping a variable with a different name.
authorMs2ger <ms2ger@gmail.com>
Sun, 12 Feb 2012 18:03:34 +0100
changeset 86760 ca2b13f5f434665d26b6ff56efc612d39ab8ee55
parent 86759 f95692cc4c97fe5f048e2196a42d956cd90d86c8
child 86761 107a869cc8618ed6c0863b08bb49e5dd10c6aafb
push id109
push userMs2ger@gmail.com
push dateSun, 12 Feb 2012 17:09:25 +0000
milestone13.0a1
Allow wrapping a variable with a different name.
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -725,17 +725,17 @@ class ArgumentConverter():
                 self.replacementVariables["typeName"] = descriptor.nativeInterface
 
     def __str__(self):
         return string.Template(
             "\n" + getArgumentConversionTemplate(self.argument.type,
                                                  self.descriptor)
             ).substitute(self.replacementVariables)
 
-def getWrapTemplateForType(type):
+def getWrapTemplateForTypeImpl(type, result):
     if type.isVoid():
         return """
   ${jsvalRef} = JSVAL_VOID;
   return true;"""
 
     if type.isInterface() and not type.isArrayBuffer():
         # Wrap the object
         return """
@@ -750,41 +750,44 @@ def getWrapTemplateForType(type):
     if type.nullable():
         raise TypeError("We don't support nullable primitive return types yet")
     
     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(result));
-  return true;"""
+  ${jsvalRef} = INT_TO_JSVAL(int32_t(%s));
+  return true;""" % result
 
     elif tag in [IDLType.Tags.int64, IDLType.Tags.uint64, IDLType.Tags.float,
                  IDLType.Tags.double]:
         # XXXbz will cast to double do the "even significand" thing that webidl
         # calls for for 64-bit ints?  Do we care?
         return """
-  return JS_NewNumberValue(cx, double(result), ${jsvalPtr});"""
+  return JS_NewNumberValue(cx, double(%s), ${jsvalPtr});""" % result
 
     elif tag == IDLType.Tags.uint32:
         return """
-  ${jsvalRef} = UINT_TO_JSVAL(result);
-  return true;"""
+  ${jsvalRef} = UINT_TO_JSVAL(%s);
+  return true;""" % result
 
     elif tag == IDLType.Tags.bool:
         return """
-  ${jsvalRef} = BOOLEAN_TO_JSVAL(result);
-  return true;"""
+  ${jsvalRef} = BOOLEAN_TO_JSVAL(%s);
+  return true;""" % result
 
     else:
         return """
   // XXXbz need to learn to wrap other things
   return false;"""
 
+def getWrapTemplateForType(type):
+    return getWrapTemplateForTypeImpl(type, "result")
+
 
 class PerSignatureCall():
     """
     This class handles the guts of generating code for a particular
     call signature.  A call signature consists of three things:
 
     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