Bug 952650 (part 11) - Remove JSVAL_TO_INT. r=njn.
authorRodrigo Rodriguez Jr. <rrodrigue96@hotmail.com>
Sun, 27 Apr 2014 19:55:08 -0700
changeset 200141 d5711e3806d056664938d62ef58f2c54eeff6cf0
parent 200140 31a8179c225bd9e5763ef83595091ba81f028606
child 200142 a61fdeb956a6320950735cd4efc1c743f378d402
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs952650
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 952650 (part 11) - Remove JSVAL_TO_INT. r=njn.
content/canvas/src/CanvasUtils.cpp
dom/base/nsDOMClassInfo.cpp
dom/plugins/base/nsJSNPRuntime.cpp
dom/system/gonk/AudioManager.cpp
dom/system/gonk/AutoMounterSetting.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/testBindCallable.cpp
js/src/jsapi-tests/testChromeBuffer.cpp
js/src/jsapi-tests/testCustomIterator.cpp
js/src/jsapi-tests/testTypedArrays.cpp
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/src/XPCWrappedJSClass.cpp
security/manager/ssl/src/nsCrypto.cpp
storage/src/mozStorageStatementParams.cpp
--- a/content/canvas/src/CanvasUtils.cpp
+++ b/content/canvas/src/CanvasUtils.cpp
@@ -65,17 +65,17 @@ DoDrawImageSecurityCheck(dom::HTMLCanvas
 }
 
 bool
 CoerceDouble(JS::Value v, double* d)
 {
     if (v.isDouble()) {
         *d = v.toDouble();
     } else if (v.isInt32()) {
-        *d = double(JSVAL_TO_INT(v));
+        *d = double(v.toInt32());
     } else if (v.isUndefined()) {
         *d = 0.0;
     } else {
         return false;
     }
     return true;
 }
 
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -3548,17 +3548,17 @@ nsGenericArraySH::GetLength(nsIXPConnect
   }
 
   if (!lenval.isInt32()) {
     // This can apparently happen with some sparse array impls falling back
     // onto this code.
     return NS_OK;
   }
 
-  int32_t slen = JSVAL_TO_INT(lenval);
+  int32_t slen = lenval.toInt32();
   if (slen < 0) {
     return NS_OK;
   }
 
   *length = (uint32_t)slen;
 
   return NS_OK;
 }
@@ -3580,17 +3580,17 @@ nsGenericArraySH::Enumerate(nsIXPConnect
   }
 
   sCurrentlyEnumerating = true;
 
   JS::Rooted<JS::Value> len_val(cx);
   bool ok = ::JS_GetProperty(cx, obj, "length", &len_val);
 
   if (ok && len_val.isInt32()) {
-    int32_t length = JSVAL_TO_INT(len_val);
+    int32_t length = len_val.toInt32();
 
     for (int32_t i = 0; ok && i < length; ++i) {
       ok = ::JS_DefineElement(cx, obj, i, JSVAL_VOID, nullptr, nullptr,
                               JSPROP_ENUMERATE | JSPROP_SHARED);
     }
   }
 
   sCurrentlyEnumerating = false;
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -384,17 +384,17 @@ JSValToNPVariant(NPP npp, JSContext *cx,
   if (JSVAL_IS_PRIMITIVE(val)) {
     if (val == JSVAL_VOID) {
       VOID_TO_NPVARIANT(*variant);
     } else if (val.isNull()) {
       NULL_TO_NPVARIANT(*variant);
     } else if (val.isBoolean()) {
       BOOLEAN_TO_NPVARIANT(val.toBoolean(), *variant);
     } else if (val.isInt32()) {
-      INT32_TO_NPVARIANT(JSVAL_TO_INT(val), *variant);
+      INT32_TO_NPVARIANT(val.toInt32(), *variant);
     } else if (val.isDouble()) {
       double d = val.toDouble();
       int i;
       if (JS_DoubleIsInt32(d, &i)) {
         INT32_TO_NPVARIANT(i, *variant);
       } else {
         DOUBLE_TO_NPVARIANT(d, *variant);
       }
@@ -898,17 +898,17 @@ nsJSObjWrapper::NP_Enumerate(NPObject *n
       if (!str) {
         PR_Free(*idarray);
         return false;
       }
       id = StringToNPIdentifier(cx, str);
     } else {
       NS_ASSERTION(v.isInt32(),
                    "The element in ida must be either string or int!\n");
-      id = IntToNPIdentifier(JSVAL_TO_INT(v));
+      id = IntToNPIdentifier(v.toInt32());
     }
 
     (*idarray)[i] = id;
   }
 
   return true;
 }
 
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -122,17 +122,17 @@ public:
   AudioChannelVolInitCallback() {}
 
   NS_IMETHOD Handle(const nsAString& aName, JS::Handle<JS::Value> aResult)
   {
     nsCOMPtr<nsIAudioManager> audioManager =
       do_GetService(NS_AUDIOMANAGER_CONTRACTID);
     NS_ENSURE_TRUE(aResult.isInt32(), NS_OK);
 
-    int32_t volIndex = JSVAL_TO_INT(aResult);
+    int32_t volIndex = aResult.toInt32();
     if (aName.EqualsLiteral("audio.volume.content")) {
       audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Content,
                                           volIndex);
     } else if (aName.EqualsLiteral("audio.volume.notification")) {
       audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Notification,
                                           volIndex);
     } else if (aName.EqualsLiteral("audio.volume.alarm")) {
       audioManager->SetAudioChannelVolume((int32_t)AudioChannel::Alarm,
--- a/dom/system/gonk/AutoMounterSetting.cpp
+++ b/dom/system/gonk/AutoMounterSetting.cpp
@@ -39,17 +39,17 @@ class SettingsServiceCallback MOZ_FINAL 
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
 
   SettingsServiceCallback() {}
 
   NS_IMETHOD Handle(const nsAString& aName, JS::Handle<JS::Value> aResult)
   {
     if (aResult.isInt32()) {
-      int32_t mode = JSVAL_TO_INT(aResult);
+      int32_t mode = aResult.toInt32();
       SetAutoMounterMode(mode);
     }
     return NS_OK;
   }
 
   NS_IMETHOD HandleError(const nsAString& aName)
   {
     ERR("SettingsCallback::HandleError: %s\n", NS_LossyConvertUTF16toASCII(aName).get());
--- a/gfx/skia/trunk/src/xml/SkJSDisplayable.cpp
+++ b/gfx/skia/trunk/src/xml/SkJSDisplayable.cpp
@@ -220,17 +220,17 @@ JSBool SkJSDisplayable::GetProperty(JSCo
 {
     if (id.isInt32() == 0)
         return JS_TRUE;
     SkJSDisplayable *p = (SkJSDisplayable *) JS_GetPrivate(cx, obj);
     SkDisplayable* displayable = p->fDisplayable;
     SkDisplayTypes displayableType = displayable->getType();
     int members;
     const SkMemberInfo* info = SkDisplayType::GetMembers(NULL /* fMaker */, displayableType, &members);
-    int idIndex = JSVAL_TO_INT(id);
+    int idIndex = id.toInt32();
     SkASSERT(idIndex >= 0 && idIndex < members);
     info = &info[idIndex];
     SkDisplayTypes infoType = (SkDisplayTypes) info->fType;
     SkScalar scalar = 0;
     S32 s32 = 0;
     SkString* string= NULL;
     JSString *str;
     if (infoType == SkType_MemberProperty) {
@@ -292,36 +292,36 @@ JSBool SkJSDisplayable::GetProperty(JSCo
 JSBool SkJSDisplayable::SetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) {
     if (id.isInt32() == 0)
         return JS_TRUE;
     SkJSDisplayable *p = (SkJSDisplayable *) JS_GetPrivate(cx, obj);
     SkDisplayable* displayable = p->fDisplayable;
     SkDisplayTypes displayableType = displayable->getType();
     int members;
     const SkMemberInfo* info = SkDisplayType::GetMembers(NULL /* fMaker */, displayableType, &members);
-    int idIndex = JSVAL_TO_INT(id);
+    int idIndex = id.toInt32();
     SkASSERT(idIndex >= 0 && idIndex < members);
     info = &info[idIndex];
     SkDisplayTypes infoType = info->getType();
     SkScalar scalar = 0;
     S32 s32 = 0;
     SkString string;
     JSString* str;
     jsval value = *vp;
     switch (infoType) {
         case SkType_Boolean:
             s32 = value.toBoolean();
             break;
         case SkType_Color:
         case SkType_S32:
-            s32 = JSVAL_TO_INT(value);
+            s32 = value.toInt32();
             break;
         case SkType_Scalar:
             if (value.isInt32())
-                scalar = SkIntToScalar(JSVAL_TO_INT(value));
+                scalar = SkIntToScalar(value.toInt32());
             else {
                 SkASSERT(value.isDouble());
                 scalar = (float) *(double*) value.toDouble();
             }
             break;
         case SkType_String:
             str = JS_ValueToString(cx, value);
             string.set(JS_GetStringBytes(str));
--- a/js/jsd/jsd_val.cpp
+++ b/js/jsd/jsd_val.cpp
@@ -151,17 +151,17 @@ jsd_GetValueBoolean(JSDContext* jsdc, JS
 }
 
 int32_t
 jsd_GetValueInt(JSDContext* jsdc, JSDValue* jsdval)
 {
     jsval val = jsdval->val;
     if(!val.isInt32())
         return 0;
-    return JSVAL_TO_INT(val);
+    return val.toInt32();
 }
 
 double
 jsd_GetValueDouble(JSDContext* jsdc, JSDValue* jsdval)
 {
     if(!jsdval->val.isDouble())
         return 0;
     return jsdval->val.toDouble();
--- a/js/public/Value.h
+++ b/js/public/Value.h
@@ -1816,23 +1816,16 @@ static_assert(sizeof(LayoutAlignmentTest
  */
 typedef JS::Value jsval;
 
 static_assert(sizeof(jsval_layout) == sizeof(JS::Value),
               "jsval_layout and JS::Value must have identical layouts");
 
 /************************************************************************/
 
-static inline int32_t
-JSVAL_TO_INT(jsval v)
-{
-    MOZ_ASSERT(v.isInt32());
-    return JSVAL_TO_INT32_IMPL(JSVAL_TO_IMPL(v));
-}
-
 static inline JS_VALUE_CONSTEXPR jsval
 INT_TO_JSVAL(int32_t i)
 {
     return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i));
 }
 
 static inline JS_VALUE_CONSTEXPR jsval
 DOUBLE_TO_JSVAL(double d)
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -816,17 +816,17 @@ static ABICode
 GetABICode(JSObject* obj)
 {
   // make sure we have an object representing a CABI class,
   // and extract the enumerated class type from the reserved slot.
   if (JS_GetClass(obj) != &sCABIClass)
     return INVALID_ABI;
 
   jsval result = JS_GetReservedSlot(obj, SLOT_ABICODE);
-  return ABICode(JSVAL_TO_INT(result));
+  return ABICode(result.toInt32());
 }
 
 static const JSErrorFormatString ErrorFormatString[CTYPESERR_LIMIT] = {
 #define MSG_DEF(name, number, count, exception, format) \
   { format, count, exception } ,
 #include "ctypes/ctypes.msg"
 #undef MSG_DEF
 };
@@ -1575,17 +1575,17 @@ static MOZ_ALWAYS_INLINE bool IsNegative
 static bool
 jsvalToBool(JSContext* cx, jsval val, bool* result)
 {
   if (val.isBoolean()) {
     *result = val.toBoolean();
     return true;
   }
   if (val.isInt32()) {
-    int32_t i = JSVAL_TO_INT(val);
+    int32_t i = val.toInt32();
     *result = i != 0;
     return i == 0 || i == 1;
   }
   if (val.isDouble()) {
     double d = val.toDouble();
     *result = d != 0;
     // Allow -0.
     return d == 1 || d == 0;
@@ -1601,17 +1601,17 @@ template<class IntegerType>
 static bool
 jsvalToInteger(JSContext* cx, jsval val, IntegerType* result)
 {
   JS_STATIC_ASSERT(NumericLimits<IntegerType>::is_exact);
 
   if (val.isInt32()) {
     // Make sure the integer fits in the alotted precision, and has the right
     // sign.
-    int32_t i = JSVAL_TO_INT(val);
+    int32_t i = val.toInt32();
     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 = val.toDouble();
     return ConvertExact(d, result);
   }
@@ -1692,17 +1692,17 @@ jsvalToFloat(JSContext *cx, jsval val, F
 {
   JS_STATIC_ASSERT(!NumericLimits<FloatType>::is_exact);
 
   // The following casts may silently throw away some bits, but there's
   // 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 (val.isInt32()) {
-    *result = FloatType(JSVAL_TO_INT(val));
+    *result = FloatType(val.toInt32());
     return true;
   }
   if (val.isDouble()) {
     *result = FloatType(val.toDouble());
     return true;
   }
   if (!JSVAL_IS_PRIMITIVE(val)) {
     JSObject* obj = JSVAL_TO_OBJECT(val);
@@ -1806,17 +1806,17 @@ jsvalToBigInteger(JSContext* cx,
                   bool allowString,
                   IntegerType* result)
 {
   JS_STATIC_ASSERT(NumericLimits<IntegerType>::is_exact);
 
   if (val.isInt32()) {
     // Make sure the integer fits in the alotted precision, and has the right
     // sign.
-    int32_t i = JSVAL_TO_INT(val);
+    int32_t i = val.toInt32();
     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 = val.toDouble();
     return ConvertExact(d, result);
   }
@@ -1969,17 +1969,17 @@ jsvalToIntegerExplicit(jsval val, Intege
 
 // Forcefully convert val to a pointer value when explicitly requested.
 static bool
 jsvalToPtrExplicit(JSContext* cx, jsval val, uintptr_t* result)
 {
   if (val.isInt32()) {
     // 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);
+    int32_t i = val.toInt32();
     *result = i < 0 ? uintptr_t(intptr_t(i)) : uintptr_t(i);
     return true;
   }
   if (val.isDouble()) {
     double d = val.toDouble();
     if (d < 0) {
       // Cast through an intptr_t intermediate to sign-extend.
       intptr_t i = Convert<intptr_t>(d);
@@ -3291,17 +3291,17 @@ void
 CType::Finalize(JSFreeOp *fop, JSObject* obj)
 {
   // Make sure our TypeCode slot is legit. If it's not, bail.
   jsval slot = JS_GetReservedSlot(obj, SLOT_TYPECODE);
   if (slot.isUndefined())
     return;
 
   // The contents of our slots depends on what kind of type we are.
-  switch (TypeCode(JSVAL_TO_INT(slot))) {
+  switch (TypeCode(slot.toInt32())) {
   case TYPE_function: {
     // Free the FunctionInfo.
     slot = JS_GetReservedSlot(obj, SLOT_FNINFO);
     if (!slot.isUndefined())
       FreeOp::get(fop)->delete_(static_cast<FunctionInfo*>(JSVAL_TO_PRIVATE(slot)));
     break;
   }
 
@@ -3336,17 +3336,17 @@ void
 CType::Trace(JSTracer* trc, JSObject* obj)
 {
   // Make sure our TypeCode slot is legit. If it's not, bail.
   jsval slot = obj->getSlot(SLOT_TYPECODE);
   if (slot.isUndefined())
     return;
 
   // The contents of our slots depends on what kind of type we are.
-  switch (TypeCode(JSVAL_TO_INT(slot))) {
+  switch (TypeCode(slot.toInt32())) {
   case TYPE_struct: {
     slot = obj->getReservedSlot(SLOT_FIELDINFO);
     if (slot.isUndefined())
       return;
 
     FieldInfoHash* fields =
       static_cast<FieldInfoHash*>(JSVAL_TO_PRIVATE(slot));
     for (FieldInfoHash::Enum e(*fields); !e.empty(); e.popFront()) {
@@ -3395,17 +3395,17 @@ CType::IsCTypeProto(JSObject* obj)
 }
 
 TypeCode
 CType::GetTypeCode(JSObject* typeObj)
 {
   JS_ASSERT(IsCType(typeObj));
 
   jsval result = JS_GetReservedSlot(typeObj, SLOT_TYPECODE);
-  return TypeCode(JSVAL_TO_INT(result));
+  return TypeCode(result.toInt32());
 }
 
 bool
 CType::TypesEqual(JSObject* t1, JSObject* t2)
 {
   JS_ASSERT(IsCType(t1) && IsCType(t2));
 
   // Fast path: check for object equality.
@@ -3477,17 +3477,17 @@ CType::GetSafeSize(JSObject* obj, size_t
 {
   JS_ASSERT(CType::IsCType(obj));
 
   jsval size = JS_GetReservedSlot(obj, SLOT_SIZE);
 
   // 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 (size.isInt32()) {
-    *result = JSVAL_TO_INT(size);
+    *result = size.toInt32();
     return true;
   }
   if (size.isDouble()) {
     *result = Convert<size_t>(size.toDouble());
     return true;
   }
 
   JS_ASSERT(size.isUndefined());
@@ -3502,17 +3502,17 @@ CType::GetSize(JSObject* obj)
   jsval size = JS_GetReservedSlot(obj, SLOT_SIZE);
 
   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 (size.isInt32())
-    return JSVAL_TO_INT(size);
+    return size.toInt32();
   return Convert<size_t>(size.toDouble());
 }
 
 bool
 CType::IsSizeDefined(JSObject* obj)
 {
   JS_ASSERT(CType::IsCType(obj));
 
@@ -3525,17 +3525,17 @@ CType::IsSizeDefined(JSObject* obj)
 }
 
 size_t
 CType::GetAlignment(JSObject* obj)
 {
   JS_ASSERT(CType::IsCType(obj));
 
   jsval slot = JS_GetReservedSlot(obj, SLOT_ALIGN);
-  return static_cast<size_t>(JSVAL_TO_INT(slot));
+  return static_cast<size_t>(slot.toInt32());
 }
 
 ffi_type*
 CType::GetFFIType(JSContext* cx, JSObject* obj)
 {
   JS_ASSERT(CType::IsCType(obj));
 
   jsval slot = JS_GetReservedSlot(obj, SLOT_FFITYPE);
--- a/js/src/jsapi-tests/testBindCallable.cpp
+++ b/js/src/jsapi-tests/testBindCallable.cpp
@@ -21,12 +21,12 @@ BEGIN_TEST(test_BindCallable)
 
   JS::RootedValue retval(cx);
   JS::RootedValue fun(cx, JS::ObjectValue(*newCallable));
   bool called = JS_CallFunctionValue(cx, JS::NullPtr(), fun, JS::HandleValueArray::empty(), &retval);
   CHECK(called);
 
   CHECK(retval.isInt32());
 
-  CHECK(JSVAL_TO_INT(retval) == 1717);
+  CHECK(retval.toInt32() == 1717);
   return true;
 }
 END_TEST(test_BindCallable)
--- a/js/src/jsapi-tests/testChromeBuffer.cpp
+++ b/js/src/jsapi-tests/testChromeBuffer.cpp
@@ -93,17 +93,17 @@ BEGIN_TEST(testChromeBuffer)
                             "}                                          ";
         JS::CompileOptions options(cx);
         options.setFileAndLine("", 0);
         CHECK(fun = JS_CompileFunction(cx, global, "untrusted", 1, &paramName,
                                        bytes, strlen(bytes), options));
 
         JS::RootedValue rval(cx);
         CHECK(JS_CallFunction(cx, JS::NullPtr(), fun, v, &rval));
-        CHECK(JSVAL_TO_INT(rval) == 100);
+        CHECK(rval.toInt32() == 100);
     }
 
     /*
      * Check that content called from chrome in the reserved-buffer space
      * immediately ooms.
      */
     {
         {
@@ -171,17 +171,17 @@ BEGIN_TEST(testChromeBuffer)
         JS::CompileOptions options(cx);
         options.setFileAndLine("", 0);
         CHECK(fun = JS_CompileFunction(cx, global, "untrusted", 1, &paramName,
                                        bytes, strlen(bytes), options));
 
         JS::RootedValue arg(cx, JS::ObjectValue(*callTrusted));
         JS::RootedValue rval(cx);
         CHECK(JS_CallFunction(cx, JS::NullPtr(), fun, arg, &rval));
-        CHECK(JSVAL_TO_INT(rval) == 42);
+        CHECK(rval.toInt32() == 42);
     }
 
     return true;
 }
 virtual void uninit() {
     trusted_glob = nullptr;
     trusted_fun = nullptr;
     JS::RemoveObjectRoot(cx, &trusted_glob);
--- a/js/src/jsapi-tests/testCustomIterator.cpp
+++ b/js/src/jsapi-tests/testCustomIterator.cpp
@@ -70,14 +70,14 @@ BEGIN_TEST(testCustomIterator_bug612523)
 
     JS::RootedValue result(cx);
     EVAL("var o = new HasCustomIter(); \n"
          "var j = 0; \n"
          "for (var i in o) { ++j; }; \n"
          "j;", &result);
 
     CHECK(result.isInt32());
-    CHECK_EQUAL(JSVAL_TO_INT(result), 100);
+    CHECK_EQUAL(result.toInt32(), 100);
     CHECK_EQUAL(iterCount, 101);
 
     return true;
 }
 END_TEST(testCustomIterator_bug612523)
--- a/js/src/jsapi-tests/testTypedArrays.cpp
+++ b/js/src/jsapi-tests/testTypedArrays.cpp
@@ -132,33 +132,33 @@ TestArrayFromBuffer(JSContext *cx)
     // Make sure all 3 views reflect the same buffer at the expected locations
     JS::RootedValue v(cx, INT_TO_JSVAL(39));
     JS_SetElement(cx, array, 0, v);
     JS::RootedValue v2(cx);
     CHECK(JS_GetElement(cx, array, 0, &v2));
     CHECK_SAME(v, v2);
     CHECK(JS_GetElement(cx, shortArray, 0, &v2));
     CHECK_SAME(v, v2);
-    CHECK_EQUAL(long(JSVAL_TO_INT(v)), long(reinterpret_cast<Element*>(data)[0]));
+    CHECK_EQUAL(long(v.toInt32()), long(reinterpret_cast<Element*>(data)[0]));
 
     v = INT_TO_JSVAL(40);
     JS_SetElement(cx, array, elts / 2, v);
     CHECK(JS_GetElement(cx, array, elts / 2, &v2));
     CHECK_SAME(v, v2);
     CHECK(JS_GetElement(cx, ofsArray, 0, &v2));
     CHECK_SAME(v, v2);
-    CHECK_EQUAL(long(JSVAL_TO_INT(v)), long(reinterpret_cast<Element*>(data)[elts / 2]));
+    CHECK_EQUAL(long(v.toInt32()), long(reinterpret_cast<Element*>(data)[elts / 2]));
 
     v = INT_TO_JSVAL(41);
     JS_SetElement(cx, array, elts - 1, v);
     CHECK(JS_GetElement(cx, array, elts - 1, &v2));
     CHECK_SAME(v, v2);
     CHECK(JS_GetElement(cx, ofsArray, elts / 2 - 1, &v2));
     CHECK_SAME(v, v2);
-    CHECK_EQUAL(long(JSVAL_TO_INT(v)), long(reinterpret_cast<Element*>(data)[elts - 1]));
+    CHECK_EQUAL(long(v.toInt32()), long(reinterpret_cast<Element*>(data)[elts - 1]));
 
     JS::RootedObject copy(cx, CreateFromArray(cx, array));
     CHECK(JS_GetElement(cx, array, 0, &v));
     CHECK(JS_GetElement(cx, copy, 0, &v2));
     CHECK_SAME(v, v2);
 
     /* The copy should not see changes in the original */
     v2 = INT_TO_JSVAL(42);
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -254,17 +254,17 @@ nsXPCComponents_Interfaces::NewEnumerate
 
             *statep = JSVAL_ZERO;
             if (idp)
                 *idp = INT_TO_JSID(mInterfaces.Length());
             return NS_OK;
         }
         case JSENUMERATE_NEXT:
         {
-            uint32_t idx = JSVAL_TO_INT(*statep);
+            uint32_t idx = statep->toInt32();
             nsIInterfaceInfo* interface = mInterfaces.SafeElementAt(idx);
             *statep = UINT_TO_JSVAL(idx + 1);
 
             if (interface) {
                 const char* name;
 
                 RootedId id(cx);
                 if (NS_SUCCEEDED(interface->GetNameShared(&name)) && name) {
@@ -502,17 +502,17 @@ nsXPCComponents_InterfacesByID::NewEnume
 
             *statep = JSVAL_ZERO;
             if (idp)
                 *idp = INT_TO_JSID(mInterfaces.Length());
             return NS_OK;
         }
         case JSENUMERATE_NEXT:
         {
-            uint32_t idx = JSVAL_TO_INT(*statep);
+            uint32_t idx = statep->toInt32();
             nsIInterfaceInfo* interface = mInterfaces.SafeElementAt(idx);
             *statep = UINT_TO_JSVAL(idx + 1);
             if (interface) {
                 nsIID const *iid;
                 char idstr[NSID_LENGTH];
 
                 if (NS_SUCCEEDED(interface->GetIIDShared(&iid))) {
                     iid->ToProvidedString(idstr);
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -1218,21 +1218,21 @@ XPCConvert::JSValToXPCException(MutableH
 
     if (s.isNumber()) {
         // lets see if it looks like an nsresult
         nsresult rv;
         double number;
         bool isResult = false;
 
         if (s.isInt32()) {
-            rv = (nsresult) JSVAL_TO_INT(s);
+            rv = (nsresult) s.toInt32();
             if (NS_FAILED(rv))
                 isResult = true;
             else
-                number = (double) JSVAL_TO_INT(s);
+                number = (double) s.toInt32();
         } else {
             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.
--- a/js/xpconnect/src/XPCWrappedJSClass.cpp
+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
@@ -244,17 +244,17 @@ nsXPCWrappedJSClass::CallQueryInterfaceO
                 } else if (jsexception.isNumber()) {
                     // 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)(jsexception.toDouble());
                     else
-                        rv = (nsresult)(JSVAL_TO_INT(jsexception));
+                        rv = (nsresult)(jsexception.toInt32());
 
                     if (rv == NS_NOINTERFACE)
                         JS_ClearPendingException(cx);
                 }
             }
 
             // Don't report if reporting was disabled by someone else.
             if (!ContextOptionsRef(cx).dontReportUncaught())
--- a/security/manager/ssl/src/nsCrypto.cpp
+++ b/security/manager/ssl/src/nsCrypto.cpp
@@ -940,17 +940,17 @@ cryptojs_ReadArgsAndGenerateKey(JSContex
   int    keySize;
   nsresult  rv;
 
   if (!argv[0].isInt32()) {
     JS_ReportError(cx, "%s%s", JS_ERROR,
                    "passed in non-integer for key size");
     return NS_ERROR_FAILURE;
   }
-  keySize = JSVAL_TO_INT(argv[0]);
+  keySize = argv[0].toInt32();
   if (!argv[1].isNull()) {
     JS::Rooted<JS::Value> v(cx, argv[1]);
     jsString = JS::ToString(cx, v);
     NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
     argv[1] = STRING_TO_JSVAL(jsString);
     params.encodeLatin1(cx, jsString);
     NS_ENSURE_TRUE(!!params, NS_ERROR_OUT_OF_MEMORY);
   }
--- a/storage/src/mozStorageStatementParams.cpp
+++ b/storage/src/mozStorageStatementParams.cpp
@@ -106,17 +106,17 @@ StatementParams::NewEnumerate(nsIXPConne
 
       break;
     }
     case JSENUMERATE_NEXT:
     {
       NS_ASSERTION(*_statep != JSVAL_NULL, "Internal state is null!");
 
       // Make sure we are in range first.
-      uint32_t index = static_cast<uint32_t>(JSVAL_TO_INT(*_statep));
+      uint32_t index = static_cast<uint32_t>(_statep->toInt32());
       if (index >= mParamCount) {
         *_statep = JSVAL_NULL;
         return NS_OK;
       }
 
       // Get the name of our parameter.
       nsAutoCString name;
       nsresult rv = mStatement->GetParameterName(index, name);