[xpcom] Unfortunately for us, non-decimal JS numbers get autoconverted
authorKalle Vahlman <kalle.vahlman@movial.com>
Thu, 23 Apr 2009 08:46:11 +0000 (11:46 +0300)
committerKalle Vahlman <kalle.vahlman@movial.com>
Thu, 23 Apr 2009 09:13:32 +0000 (12:13 +0300)
to integers while our default autoconversion is always to double. This
means that we need to convert the array contents to double when setting
them in chunks.

xpcom-dbusservice/DBusMarshaling.cpp

index 69c1f0d11e7f7472704be862fb16033227f29531..51382702d6e4a72ec9136537b3f9675b4a87b58c 100644 (file)
@@ -741,6 +741,11 @@ void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32
 #define ADD_DATA \
             for (PRUint32 i = start; i < count; i++) \
                 dbus_message_iter_append_basic(aIter, aDBusType, data+i)
+#define ADD_DATA_AS_DOUBLE  do { \
+            for (PRUint32 i = start; i < count; i++) { \
+                double t = *(data+i); \
+                dbus_message_iter_append_basic(aIter, aDBusType, &t); \
+            } } while (0)
         case nsIDataType::VTYPE_BOOL:
         {
             PRBool *data = (PRBool *)data_ptr;
@@ -751,28 +756,40 @@ void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32
         case nsIDataType::VTYPE_UINT8:
         {
             char *data = (char *)data_ptr;
-            ADD_DATA;
+            if (aDBusType == DBUS_TYPE_DOUBLE)
+                ADD_DATA_AS_DOUBLE;
+            else
+                ADD_DATA;
             break;
         }
         case nsIDataType::VTYPE_INT16:
         case nsIDataType::VTYPE_UINT16:
         {
             PRInt16 *data = (PRInt16 *)data_ptr;
-            ADD_DATA;
+            if (aDBusType == DBUS_TYPE_DOUBLE)
+                ADD_DATA_AS_DOUBLE;
+            else
+                ADD_DATA;
             break;
         }
         case nsIDataType::VTYPE_INT32:
         case nsIDataType::VTYPE_UINT32:
         {
             PRInt32 *data = (PRInt32 *)data_ptr;
-            ADD_DATA;
+            if (aDBusType == DBUS_TYPE_DOUBLE)
+                ADD_DATA_AS_DOUBLE;
+            else
+                ADD_DATA;
             break;
         }
         case nsIDataType::VTYPE_INT64:
         case nsIDataType::VTYPE_UINT64:
         {
             PRInt64 *data = (PRInt64 *)data_ptr;
-            ADD_DATA;
+            if (aDBusType == DBUS_TYPE_DOUBLE)
+                ADD_DATA_AS_DOUBLE;
+            else
+                ADD_DATA;
             break;
         }
         case nsIDataType::VTYPE_DOUBLE: