Wrap string return values.
authorMs2ger <ms2ger@gmail.com>
Sun, 12 Feb 2012 18:03:36 +0100
changeset 86761 107a869cc8618ed6c0863b08bb49e5dd10c6aafb
parent 86760 ca2b13f5f434665d26b6ff56efc612d39ab8ee55
child 86762 b91d5bfbf6587600c194ce7c98adf945574e07ec
push id109
push userMs2ger@gmail.com
push dateSun, 12 Feb 2012 17:09:25 +0000
milestone13.0a1
Wrap string return values.
dom/bindings/Codegen.py
js/xpconnect/src/XPCQuickStubs.cpp
js/xpconnect/src/xpcpublic.h
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -737,16 +737,24 @@ def getWrapTemplateForTypeImpl(type, res
   return true;"""
 
     if type.isInterface() and not type.isArrayBuffer():
         # Wrap the object
         return """
   // XXXbz need to learn to wrap objects
   return false;"""
 
+    if type.isString():
+        if type.nullable():
+            return """
+  return xpc::StringToJsval(cx, %s, ${jsvalPtr});""" % result
+        else:
+            return """
+  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")
     
@@ -853,16 +861,18 @@ class PerSignatureCall():
         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()]
+        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' \
                                % self.getErrorReport()
         else:
--- a/js/xpconnect/src/XPCQuickStubs.cpp
+++ b/js/xpconnect/src/XPCQuickStubs.cpp
@@ -1043,24 +1043,30 @@ xpc_qsJsvalToWcharStr(JSContext *cx, jsv
 
     *pstr = static_cast<const PRUnichar *>(chars);
     return true;
 }
 
 namespace xpc {
 
 bool
-StringToJsval(JSContext *cx, nsString &str, JS::Value *rval)
+StringToJsval(JSContext *cx, nsAString &str, JS::Value *rval)
 {
     // From the T_DOMSTRING case in XPCConvert::NativeData2JS.
     if (str.IsVoid()) {
         *rval = JSVAL_NULL;
         return true;
     }
+    return NonVoidStringToJsval(cx, str, rval);
+}
 
+bool
+NonVoidStringToJsval(JSContext *cx, nsAString &str, JS::Value *rval)
+{
+    MOZ_ASSERT(!str.IsVoid());
     nsStringBuffer* sharedBuffer;
     jsval jsstr = XPCStringConvert::ReadableToJSVal(cx, str, &sharedBuffer);
     if (JSVAL_IS_NULL(jsstr))
         return false;
     *rval = jsstr;
     if (sharedBuffer) {
         // The string was shared but ReadableToJSVal didn't addref it.
         // Move the ownership from str to jsstr.
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -206,17 +206,18 @@ namespace xpc {
 bool Base64Encode(JSContext *cx, JS::Value val, JS::Value *out);
 bool Base64Decode(JSContext *cx, JS::Value val, JS::Value *out);
 
 /**
  * Convert an nsString to jsval, returning true on success.
  * Note, the ownership of the string buffer may be moved from str to rval.
  * If that happens, str will point to an empty string after this call.
  */
-bool StringToJsval(JSContext *cx, nsString &str, JS::Value *rval);
+bool StringToJsval(JSContext *cx, nsAString &str, JS::Value *rval);
+bool NonVoidStringToJsval(JSContext *cx, nsAString &str, JS::Value *rval);
 
 void *GetCompartmentName(JSContext *cx, JSCompartment *c);
 void DestroyCompartmentName(void *string);
 
 #ifdef DEBUG
 void DumpJSHeap(FILE* file);
 #endif
 } // namespace xpc