Bug 711404 - Part a: Correctly handle unsigned long long as PRUint64 instead of PRInt64; r=bholley
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Sat, 24 Dec 2011 09:25:54 +0100
changeset 84506 b59760807d25cae7c496eb23af440a08e71191b6
parent 84505 c0791b275f7f0dcc513ca7ef3bf16c36c8e809b1
child 84507 f6d0b8d7ab3e3eab99ebaf97cd6f790cf89decc0
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs711404
milestone12.0a1
Bug 711404 - Part a: Correctly handle unsigned long long as PRUint64 instead of PRInt64; r=bholley
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/src/XPCQuickStubs.h
js/xpconnect/tests/unit/test_bug711404.js
js/xpconnect/tests/unit/xpcshell.ini
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -147,42 +147,16 @@ XPCConvert::RemoveXPCOMUCStringFinalizer
     sXPCOMUCStringFinalizerIndex = -1;
 }
 
 
 #define FIT_U32(i)     ((i) <= JSVAL_INT_MAX                                  \
                         ? INT_TO_JSVAL(i)                                     \
                         : DOUBLE_TO_JSVAL(i))
 
-/*
- * Support for 64 bit conversions where 'long long' not supported.
- * (from John Fairhurst <mjf35@cam.ac.uk>)
- */
-
-#ifdef HAVE_LONG_LONG
-
-#define INT64_TO_DOUBLE(i)      ((jsdouble) (i))
-// Win32 can't handle uint64 to double conversion
-#define UINT64_TO_DOUBLE(u)     ((jsdouble) (int64) (u))
-
-#else
-
-inline jsdouble
-INT64_TO_DOUBLE(const int64 &v)
-{
-    jsdouble d;
-    LL_L2D(d, v);
-    return d;
-}
-
-// if !HAVE_LONG_LONG, then uint64 is a typedef of int64
-#define UINT64_TO_DOUBLE INT64_TO_DOUBLE
-
-#endif
-
 // static
 JSBool
 XPCConvert::NativeData2JS(XPCLazyCallContext& lccx, jsval* d, const void* s,
                           const nsXPTType& type, const nsID* iid, nsresult* pErr)
 {
     NS_PRECONDITION(s, "bad param");
     NS_PRECONDITION(d, "bad param");
 
@@ -196,21 +170,21 @@ XPCConvert::NativeData2JS(XPCLazyCallCon
 
     if (pErr)
         *pErr = NS_ERROR_XPC_BAD_CONVERT_NATIVE;
 
     switch (type.TagPart()) {
     case nsXPTType::T_I8    : *d = INT_TO_JSVAL(int32_t(*((int8_t*)s)));             break;
     case nsXPTType::T_I16   : *d = INT_TO_JSVAL(int32_t(*((int16_t*)s)));            break;
     case nsXPTType::T_I32   : *d = INT_TO_JSVAL(*((int32_t*)s));                     break;
-    case nsXPTType::T_I64   : *d = DOUBLE_TO_JSVAL(INT64_TO_DOUBLE(*((int64*)s)));   break;
+    case nsXPTType::T_I64   : *d = DOUBLE_TO_JSVAL(jsdouble(*((int64_t*)s)));        break;
     case nsXPTType::T_U8    : *d = INT_TO_JSVAL(int32_t(*((uint8*)s)));              break;
     case nsXPTType::T_U16   : *d = INT_TO_JSVAL(int32_t(*((uint16_t*)s)));           break;
     case nsXPTType::T_U32   : *d = FIT_U32(*((uint32_t*)s));                         break;
-    case nsXPTType::T_U64   : *d = DOUBLE_TO_JSVAL(UINT64_TO_DOUBLE(*((uint64*)s))); break;
+    case nsXPTType::T_U64   : *d = DOUBLE_TO_JSVAL(jsdouble(*((uint64_t*)s)));       break;
     case nsXPTType::T_FLOAT : *d = DOUBLE_TO_JSVAL(*((float*)s));                    break;
     case nsXPTType::T_DOUBLE: *d = DOUBLE_TO_JSVAL(*((double*)s));                   break;
     case nsXPTType::T_BOOL  :
         {
             bool b = *((bool*)s);
 
             NS_WARN_IF_FALSE(b == 1 || b == 0,
                              "Passing a malformed bool through XPConnect");
@@ -522,26 +496,21 @@ XPCConvert::JSData2Native(XPCCallContext
     case nsXPTType::T_U32    :
         if (!JS_ValueToECMAUint32(cx, s, (uint32_t*)d))
             return false;
         break;
     case nsXPTType::T_U64    :
         if (JSVAL_IS_INT(s)) {
             if (!JS_ValueToECMAUint32(cx, s, &tu))
                 return false;
-            *((int64_t*)d) = tu;
+            *((uint64_t*)d) = tu;
         } else {
             if (!JS_ValueToNumber(cx, s, &td))
                 return false;
-#ifdef XP_WIN
-            // Note: Win32 can't handle double to uint64 directly
-            *((uint64_t*)d) = uint64_t(int64_t(td));
-#else
             *((uint64_t*)d) = uint64_t(td);
-#endif
         }
         break;
     case nsXPTType::T_FLOAT  :
         if (!JS_ValueToNumber(cx, s, &td))
             return false;
         *((float*)d) = (float) td;
         break;
     case nsXPTType::T_DOUBLE :
--- a/js/xpconnect/src/XPCQuickStubs.h
+++ b/js/xpconnect/src/XPCQuickStubs.h
@@ -242,49 +242,26 @@ xpc_qsUint32ToJsval(JSContext *cx, PRUin
 {
     if (u <= JSVAL_INT_MAX)
         *rv = INT_TO_JSVAL(u);
     else
         *rv = DOUBLE_TO_JSVAL(u);
     return true;
 }
 
-#ifdef HAVE_LONG_LONG
-
-#define INT64_TO_DOUBLE(i)      ((jsdouble) (i))
-// Win32 can't handle uint64 to double conversion
-#define UINT64_TO_DOUBLE(u)     ((jsdouble) (int64) (u))
-
-#else
-
-inline jsdouble
-INT64_TO_DOUBLE(const int64 &v)
-{
-    jsdouble d;
-    LL_L2D(d, v);
-    return d;
-}
-
-// if !HAVE_LONG_LONG, then uint64 is a typedef of int64
-#define UINT64_TO_DOUBLE INT64_TO_DOUBLE
-
-#endif
-
 inline JSBool
 xpc_qsInt64ToJsval(JSContext *cx, PRInt64 i, jsval *rv)
 {
-    double d = INT64_TO_DOUBLE(i);
-    return JS_NewNumberValue(cx, d, rv);
+    return JS_NewNumberValue(cx, static_cast<jsdouble>(i), rv);
 }
 
 inline JSBool
 xpc_qsUint64ToJsval(JSContext *cx, PRUint64 u, jsval *rv)
 {
-    double d = UINT64_TO_DOUBLE(u);
-    return JS_NewNumberValue(cx, d, rv);
+    return JS_NewNumberValue(cx, static_cast<jsdouble>(u), rv);
 }
 
 
 /* Classes for converting jsvals to string types. */
 
 template <class S, class T>
 class xpc_qsBasicString
 {
@@ -722,22 +699,17 @@ xpc_qsValueToInt64(JSContext *cx,
 }
 
 /**
  * Convert a jsdouble to PRUint64. Needed for traceable quickstubs too.
  */
 inline PRUint64
 xpc_qsDoubleToUint64(jsdouble doubleval)
 {
-#ifdef XP_WIN
-    // Note: Win32 can't handle double to uint64 directly
-    return static_cast<PRUint64>(static_cast<PRInt64>(doubleval));
-#else
     return static_cast<PRUint64>(doubleval);
-#endif
 }
 
 /**
  * Convert a jsval to PRUint64. Return true on success.
  */
 inline JSBool
 xpc_qsValueToUint64(JSContext *cx,
                     jsval v,
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_bug711404.js
@@ -0,0 +1,10 @@
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+function run_test()
+{
+  var p = Cc["@mozilla.org/hash-property-bag;1"].
+          createInstance(Ci.nsIWritablePropertyBag2);
+  p.setPropertyAsInt64("a", -4000);
+  do_check_neq(p.getPropertyAsUint64("a"), -4000);
+}
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -5,16 +5,17 @@ tail =
 [test_bogus_files.js]
 [test_bug408412.js]
 [test_bug451678.js]
 [test_bug596580.js]
 [test_bug604362.js]
 [test_bug608142.js]
 [test_bug641378.js]
 [test_bug677864.js]
+[test_bug711404.js]
 [test_bug_442086.js]
 [test_file.js]
 [test_import.js]
 [test_js_weak_references.js]
 [test_reflect_parse.js]
 [test_localeCompare.js]
 # Bug 676965: test fails consistently on Android
 fail-if = os == "android"