Bug 952650 (part 5) - Remove JSVAL_TO_DOUBLE. r=njn.
authorRodrigo Rodriguez Jr. <rrodrigue96@hotmail.com>
Sun, 27 Apr 2014 19:38:31 -0700
changeset 181294 77173a0f4085f708941164ba3666aac9ecd3f54a
parent 181293 899b41829e76f541f19bb3fbfa6d57e2b5a3a0c7
child 181295 47e4ad6fbe3cc59e395a032c8cab0b1da4cccd8e
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersnjn
bugs952650
milestone32.0a1
Bug 952650 (part 5) - Remove JSVAL_TO_DOUBLE. r=njn.
content/canvas/src/CanvasRenderingContext2D.cpp
content/canvas/src/CanvasUtils.cpp
dom/plugins/base/nsJSNPRuntime.cpp
gfx/skia/trunk/src/xml/SkJSDisplayable.cpp
js/jsd/jsd_val.cpp
js/public/Value.h
js/src/ctypes/CTypes.cpp
js/src/jsapi-tests/testLooselyEqual.cpp
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/src/XPCWrappedJSClass.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -1330,17 +1330,17 @@ CanvasRenderingContext2D::GetMozCurrentT
 {
   if (!mTarget) {
     return MatrixToJSObject(cx, Matrix(), error);
   }
 
   Matrix ctm = mTarget->GetTransform();
 
   if (!ctm.Invert()) {
-    double NaN = JSVAL_TO_DOUBLE(JS_GetNaNValue(cx));
+    double NaN = JS_GetNaNValue(cx).toDouble();
     ctm = Matrix(NaN, NaN, NaN, NaN, NaN, NaN);
   }
 
   return MatrixToJSObject(cx, ctm, error);
 }
 
 //
 // colors
--- a/content/canvas/src/CanvasUtils.cpp
+++ b/content/canvas/src/CanvasUtils.cpp
@@ -63,17 +63,17 @@ DoDrawImageSecurityCheck(dom::HTMLCanvas
 
     aCanvasElement->SetWriteOnly();
 }
 
 bool
 CoerceDouble(JS::Value v, double* d)
 {
     if (v.isDouble()) {
-        *d = JSVAL_TO_DOUBLE(v);
+        *d = v.toDouble();
     } else if (JSVAL_IS_INT(v)) {
         *d = double(JSVAL_TO_INT(v));
     } else if (v.isUndefined()) {
         *d = 0.0;
     } else {
         return false;
     }
     return true;
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -386,17 +386,17 @@ JSValToNPVariant(NPP npp, JSContext *cx,
       VOID_TO_NPVARIANT(*variant);
     } else if (val.isNull()) {
       NULL_TO_NPVARIANT(*variant);
     } else if (JSVAL_IS_BOOLEAN(val)) {
       BOOLEAN_TO_NPVARIANT(val.toBoolean(), *variant);
     } else if (JSVAL_IS_INT(val)) {
       INT32_TO_NPVARIANT(JSVAL_TO_INT(val), *variant);
     } else if (val.isDouble()) {
-      double d = JSVAL_TO_DOUBLE(val);
+      double d = val.toDouble();
       int i;
       if (JS_DoubleIsInt32(d, &i)) {
         INT32_TO_NPVARIANT(i, *variant);
       } else {
         DOUBLE_TO_NPVARIANT(d, *variant);
       }
     } else if (JSVAL_IS_STRING(val)) {
       JSString *jsstr = JSVAL_TO_STRING(val);
--- a/gfx/skia/trunk/src/xml/SkJSDisplayable.cpp
+++ b/gfx/skia/trunk/src/xml/SkJSDisplayable.cpp
@@ -314,17 +314,17 @@ JSBool SkJSDisplayable::SetProperty(JSCo
         case SkType_S32:
             s32 = JSVAL_TO_INT(value);
             break;
         case SkType_Scalar:
             if (JSVAL_IS_INT(value))
                 scalar = SkIntToScalar(JSVAL_TO_INT(value));
             else {
                 SkASSERT(value.isDouble());
-                scalar = (float) *(double*) JSVAL_TO_DOUBLE(value);
+                scalar = (float) *(double*) value.toDouble();
             }
             break;
         case SkType_String:
             str = JS_ValueToString(cx, value);
             string.set(JS_GetStringBytes(str));
             break;
         default:
             SkASSERT(0); // !!! unimplemented
--- a/js/jsd/jsd_val.cpp
+++ b/js/jsd/jsd_val.cpp
@@ -159,17 +159,17 @@ jsd_GetValueInt(JSDContext* jsdc, JSDVal
     return JSVAL_TO_INT(val);
 }
 
 double
 jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval)
 {
     if(!jsdval->val.isDouble())
         return 0;
-    return JSVAL_TO_DOUBLE(jsdval->val);
+    return jsdval->val.toDouble();
 }
 
 JSString*
 jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval)
 {
     AutoSafeJSContext cx;
     JS::RootedValue stringval(cx);
     JS::RootedString string(cx);
--- a/js/public/Value.h
+++ b/js/public/Value.h
@@ -1835,25 +1835,16 @@ JSVAL_TO_INT(jsval v)
 }
 
 static inline JS_VALUE_CONSTEXPR jsval
 INT_TO_JSVAL(int32_t i)
 {
     return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i));
 }
 
-static inline double
-JSVAL_TO_DOUBLE(jsval v)
-{
-    jsval_layout l;
-    MOZ_ASSERT(v.isDouble());
-    l = JSVAL_TO_IMPL(v);
-    return l.asDouble;
-}
-
 static inline JS_VALUE_CONSTEXPR jsval
 DOUBLE_TO_JSVAL(double d)
 {
     /*
      * This is a manually inlined version of:
      *    d = JS_CANONICALIZE_NAN(d);
      *    return IMPL_TO_JSVAL(DOUBLE_TO_JSVAL_IMPL(d));
      * because GCC from XCode 3.1.4 miscompiles the above code.
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -1580,17 +1580,17 @@ jsvalToBool(JSContext* cx, jsval val, bo
     return true;
   }
   if (JSVAL_IS_INT(val)) {
     int32_t i = JSVAL_TO_INT(val);
     *result = i != 0;
     return i == 0 || i == 1;
   }
   if (val.isDouble()) {
-    double d = JSVAL_TO_DOUBLE(val);
+    double d = val.toDouble();
     *result = d != 0;
     // Allow -0.
     return d == 1 || d == 0;
   }
   // Don't silently convert null to bool. It's probably a mistake.
   return false;
 }
 
@@ -1607,17 +1607,17 @@ jsvalToInteger(JSContext* cx, jsval val,
     // Make sure the integer fits in the alotted precision, and has the right
     // sign.
     int32_t i = JSVAL_TO_INT(val);
     return ConvertExact(i, result);
   }
   if (val.isDouble()) {
     // Don't silently lose bits here -- check that val really is an
     // integer value, and has the right sign.
-    double d = JSVAL_TO_DOUBLE(val);
+    double d = val.toDouble();
     return ConvertExact(d, result);
   }
   if (!JSVAL_IS_PRIMITIVE(val)) {
     JSObject* obj = JSVAL_TO_OBJECT(val);
     if (CData::IsCData(obj)) {
       JSObject* typeObj = CData::GetCType(obj);
       void* data = CData::GetData(obj);
 
@@ -1696,17 +1696,17 @@ jsvalToFloat(JSContext *cx, jsval val, F
   // no good way around it. Sternly requiring that the 64-bit double
   // argument be exactly representable as a 32-bit float is
   // unrealistic: it would allow 1/2 to pass but not 1/3.
   if (JSVAL_IS_INT(val)) {
     *result = FloatType(JSVAL_TO_INT(val));
     return true;
   }
   if (val.isDouble()) {
-    *result = FloatType(JSVAL_TO_DOUBLE(val));
+    *result = FloatType(val.toDouble());
     return true;
   }
   if (!JSVAL_IS_PRIMITIVE(val)) {
     JSObject* obj = JSVAL_TO_OBJECT(val);
     if (CData::IsCData(obj)) {
       JSObject* typeObj = CData::GetCType(obj);
       void* data = CData::GetData(obj);
 
@@ -1812,17 +1812,17 @@ jsvalToBigInteger(JSContext* cx,
     // Make sure the integer fits in the alotted precision, and has the right
     // sign.
     int32_t i = JSVAL_TO_INT(val);
     return ConvertExact(i, result);
   }
   if (val.isDouble()) {
     // Don't silently lose bits here -- check that val really is an
     // integer value, and has the right sign.
-    double d = JSVAL_TO_DOUBLE(val);
+    double d = val.toDouble();
     return ConvertExact(d, result);
   }
   if (allowString && JSVAL_IS_STRING(val)) {
     // Allow conversion from base-10 or base-16 strings, provided the result
     // fits in IntegerType. (This allows an Int64 or UInt64 object to be passed
     // to the JS array element operator, which will automatically call
     // toString() on the object for us.)
     return StringToInteger(cx, JSVAL_TO_STRING(val), result);
@@ -1941,17 +1941,17 @@ SizeTojsval(JSContext* cx, size_t size, 
 template<class IntegerType>
 static bool
 jsvalToIntegerExplicit(jsval val, IntegerType* result)
 {
   JS_STATIC_ASSERT(NumericLimits<IntegerType>::is_exact);
 
   if (val.isDouble()) {
     // Convert -Inf, Inf, and NaN to 0; otherwise, convert by C-style cast.
-    double d = JSVAL_TO_DOUBLE(val);
+    double d = val.toDouble();
     *result = mozilla::IsFinite(d) ? IntegerType(d) : 0;
     return true;
   }
   if (!JSVAL_IS_PRIMITIVE(val)) {
     // Convert Int64 and UInt64 values by C-style cast.
     JSObject* obj = JSVAL_TO_OBJECT(val);
     if (Int64::IsInt64(obj)) {
       int64_t i = Int64Base::GetInt(obj);
@@ -1974,17 +1974,17 @@ jsvalToPtrExplicit(JSContext* cx, jsval 
   if (JSVAL_IS_INT(val)) {
     // int32_t always fits in intptr_t. If the integer is negative, cast through
     // an intptr_t intermediate to sign-extend.
     int32_t i = JSVAL_TO_INT(val);
     *result = i < 0 ? uintptr_t(intptr_t(i)) : uintptr_t(i);
     return true;
   }
   if (val.isDouble()) {
-    double d = JSVAL_TO_DOUBLE(val);
+    double d = val.toDouble();
     if (d < 0) {
       // Cast through an intptr_t intermediate to sign-extend.
       intptr_t i = Convert<intptr_t>(d);
       if (double(i) != d)
         return false;
 
       *result = uintptr_t(i);
       return true;
@@ -3481,17 +3481,17 @@ CType::GetSafeSize(JSObject* obj, size_t
 
   // The "size" property can be an int, a double, or JSVAL_VOID
   // (for arrays of undefined length), and must always fit in a size_t.
   if (JSVAL_IS_INT(size)) {
     *result = JSVAL_TO_INT(size);
     return true;
   }
   if (size.isDouble()) {
-    *result = Convert<size_t>(JSVAL_TO_DOUBLE(size));
+    *result = Convert<size_t>(size.toDouble());
     return true;
   }
 
   JS_ASSERT(size.isUndefined());
   return false;
 }
 
 size_t
@@ -3503,17 +3503,17 @@ CType::GetSize(JSObject* obj)
 
   JS_ASSERT(!size.isUndefined());
 
   // The "size" property can be an int, a double, or JSVAL_VOID
   // (for arrays of undefined length), and must always fit in a size_t.
   // For callers who know it can never be JSVAL_VOID, return a size_t directly.
   if (JSVAL_IS_INT(size))
     return JSVAL_TO_INT(size);
-  return Convert<size_t>(JSVAL_TO_DOUBLE(size));
+  return Convert<size_t>(size.toDouble());
 }
 
 bool
 CType::IsSizeDefined(JSObject* obj)
 {
   JS_ASSERT(CType::IsCType(obj));
 
   jsval size = JS_GetReservedSlot(obj, SLOT_SIZE);
--- a/js/src/jsapi-tests/testLooselyEqual.cpp
+++ b/js/src/jsapi-tests/testLooselyEqual.cpp
@@ -58,18 +58,18 @@ struct LooseEqualityData
         undef = JSVAL_VOID;
         null = JSVAL_NULL;
         obj = OBJECT_TO_JSVAL(JS::CurrentGlobalOrNull(cx));
         poszero = DOUBLE_TO_JSVAL(0.0);
         negzero = DOUBLE_TO_JSVAL(-0.0);
 #ifdef XP_WIN
 # define copysign _copysign
 #endif
-        JS_ASSERT(copysign(1.0, JSVAL_TO_DOUBLE(poszero)) == 1.0);
-        JS_ASSERT(copysign(1.0, JSVAL_TO_DOUBLE(negzero)) == -1.0);
+        JS_ASSERT(copysign(1.0, poszero.toDouble()) == 1.0);
+        JS_ASSERT(copysign(1.0, negzero.toDouble()) == -1.0);
 #ifdef XP_WIN
 # undef copysign
 #endif
     }
 };
 
 // 11.9.3 1a
 BEGIN_FIXTURE_TEST(LooseEqualityFixture, test_undef_leq_undef)
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -1225,17 +1225,17 @@ XPCConvert::JSValToXPCException(MutableH
 
         if (JSVAL_IS_INT(s)) {
             rv = (nsresult) JSVAL_TO_INT(s);
             if (NS_FAILED(rv))
                 isResult = true;
             else
                 number = (double) JSVAL_TO_INT(s);
         } else {
-            number = JSVAL_TO_DOUBLE(s);
+            number = s.toDouble();
             if (number > 0.0 &&
                 number < (double)0xffffffff &&
                 0.0 == fmod(number,1)) {
                 // Visual Studio 9 doesn't allow casting directly from a
                 // double to an enumeration type, contrary to 5.2.9(10) of
                 // C++11, so add an intermediate cast.
                 rv = (nsresult)(uint32_t) number;
                 if (NS_FAILED(rv))
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -242,17 +242,17 @@ nsXPCWrappedJSClass::CallQueryInterfaceO
                         JS_ClearPendingException(cx);
                     }
                 } else if (JSVAL_IS_NUMBER(jsexception)) {
                     // JS often throws an nsresult.
                     if (jsexception.isDouble())
                         // Visual Studio 9 doesn't allow casting directly from
                         // a double to an enumeration type, contrary to
                         // 5.2.9(10) of C++11, so add an intermediate cast.
-                        rv = (nsresult)(uint32_t)(JSVAL_TO_DOUBLE(jsexception));
+                        rv = (nsresult)(uint32_t)(jsexception.toDouble());
                     else
                         rv = (nsresult)(JSVAL_TO_INT(jsexception));
 
                     if (rv == NS_NOINTERFACE)
                         JS_ClearPendingException(cx);
                 }
             }