[xpcom] Fix string handling in getJSValueFromIter()
[browser-dbus-bridge.git] / xpcom-dbusservice / DBusMarshaling.cpp
index 71e8f3d1be6bde82f740c6457979d27a12dcc51f..cfb66453a837333ca693323cbea3008269d21791 100644 (file)
@@ -105,7 +105,6 @@ getSignatureFromJSValue(JSContext *cx, jsval *aValue, nsCString &aResult)
     {
         nsISupports* supports;
         JSClass* clazz;
-        JSObject* parent;
         JSObject* glob = JSVAL_TO_OBJECT(*aValue);
 
         clazz = JS_GET_CLASS(cx, JS_GetParent(cx, glob));
@@ -533,7 +532,7 @@ addVariantToIter(JSContext* cx, nsIVariant *aVariant, DBusMessageIter *aIter, DB
                  * nsIVariants directly, but no API to that effect seems to be
                  * available...
                  */
-                for (int i = 0; i < count; i++)
+                for (PRUint32 i = 0; i < count; i++)
                 {
                     nsCOMPtr<nsIWritableVariant> variant = do_CreateInstance("@mozilla.org/variant;1");
                     
@@ -727,7 +726,7 @@ void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32
     switch (type)
     {
 #define ADD_DATA \
-            for (int i = start; i < count; i++) \
+            for (PRUint32 i = start; i < count; i++) \
                 dbus_message_iter_append_basic(aIter, aDBusType, data+i)
         case nsIDataType::VTYPE_INT8:
         case nsIDataType::VTYPE_UINT8:
@@ -766,7 +765,7 @@ void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32
         case nsIDataType::VTYPE_WCHAR_STR:
         {
             PRUnichar **data = (PRUnichar **)data_ptr;
-            for (int i = start; i < count; i++)
+            for (PRUint32 i = start; i < count; i++)
             {
                 const char *val_ptr;
                 nsCAutoString val = NS_ConvertUTF16toUTF8(data[i]);
@@ -784,7 +783,7 @@ void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32
         case nsIDataType::VTYPE_INTERFACE_IS:
         {
             nsISupports **data = (nsISupports **)data_ptr;
-            for (int i = start; i < count; i++)
+            for (PRUint32 i = start; i < count; i++)
             {
                 nsCOMPtr<nsIVariant> data_variant = do_QueryInterface(data[i]);
                 if (data_variant)
@@ -907,7 +906,8 @@ void getJSValueFromIter(JSContext* cx, DBusMessageIter *aIter, int aDBusType, js
             dbus_message_iter_get_basic(aIter, &val);
             if (val != nsnull)
             {
-                JSString *str = JS_NewStringCopyN(cx, val, strlen(val));
+                nsAutoString uval = NS_ConvertUTF8toUTF16(val);
+                JSString *str = JS_NewUCStringCopyN(cx, uval.get(), uval.Length());
                 *v = STRING_TO_JSVAL(str);
             }
             break;
@@ -1086,7 +1086,9 @@ already_AddRefed<nsIWritableVariant> getVariantFromIter(JSContext* cx, DBusMessa
 
                 // Convert to variant and return
                 nsIVariant *var = nsnull;
-                nsresult rs = xpc->JSToVariant(cx, OBJECT_TO_JSVAL(obj), &var);
+                rv = xpc->JSToVariant(cx, OBJECT_TO_JSVAL(obj), &var);
+                if(NS_FAILED(rv))
+                    return nsnull;
                 variant->SetFromVariant(var);
                 var = nsnull;
                 NS_ADDREF(retval = variant);
@@ -1107,7 +1109,7 @@ already_AddRefed<nsIWritableVariant> getVariantFromIter(JSContext* cx, DBusMessa
                 BDBLOG(("    array: %d items\n", item_count));
 
                 nsIVariant **item_array = new nsIVariant*[item_count];
-                for (int i = 0; i < item_count; i++)
+                for (PRUint32 i = 0; i < item_count; i++)
                 {
                     nsCOMPtr<nsIVariant> item = do_QueryElementAt(items, i);
                     item_array[i] = item;
@@ -1117,7 +1119,7 @@ already_AddRefed<nsIWritableVariant> getVariantFromIter(JSContext* cx, DBusMessa
                                     &NS_GET_IID(nsIVariant),
                                     item_count,
                                     item_array);
-                for (int i = 0; i < item_count; i++)
+                for (PRUint32 i = 0; i < item_count; i++)
                     NS_RELEASE(item_array[i]);
                 delete[] item_array;
             }