Bug 963167 - Convert JS_SetElement() to take HandleValue rather than MutableHandleValue r=sfink r=bz
authorJon Coppeard <jcoppeard@mozilla.com>
Sat, 25 Jan 2014 09:31:17 +0000
changeset 165215 f613b4ac27f9194fb3511f200a382aa889a9fc43
parent 165214 84a0bf9566e63572181f8274404b785bb99e6bf1
child 165216 f4b552faecc8ecd0c93d99c1b8890df32fe4948d
push id4577
push userphilringnalda@gmail.com
push dateSun, 26 Jan 2014 04:01:57 +0000
treeherderfx-team@611698b4a246 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink, bz
bugs963167
milestone29.0a1
Bug 963167 - Convert JS_SetElement() to take HandleValue rather than MutableHandleValue r=sfink r=bz
content/base/src/nsFrameMessageManager.cpp
dom/camera/CameraControlImpl.cpp
dom/camera/DOMCameraCapabilities.cpp
dom/file/ArchiveRequest.cpp
dom/indexedDB/AsyncConnectionHelper.cpp
dom/indexedDB/IDBIndex.cpp
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/Key.cpp
dom/indexedDB/KeyPath.cpp
dom/mobilemessage/src/MmsMessage.cpp
dom/mobilemessage/src/MobileMessageCallback.cpp
dom/mobilemessage/src/ipc/SmsParent.cpp
js/src/jsapi-tests/testArrayBuffer.cpp
js/src/jsapi-tests/testNewObject.cpp
js/src/jsapi-tests/testTypedArrays.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/shell/js.cpp
js/src/shell/jsheaptools.cpp
js/xpconnect/public/nsTArrayHelpers.h
js/xpconnect/src/XPCConvert.cpp
storage/src/mozStorageStatementRow.cpp
toolkit/components/places/PlaceInfo.cpp
toolkit/components/telemetry/Telemetry.cpp
tools/profiler/JSObjectBuilder.cpp
--- a/content/base/src/nsFrameMessageManager.cpp
+++ b/content/base/src/nsFrameMessageManager.cpp
@@ -457,29 +457,27 @@ nsFrameMessageManager::GetDelayedFrameSc
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, mPendingScripts.Length(), nullptr));
   NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
 
   JS::Rooted<JSString*> url(aCx);
   JS::Rooted<JSObject*> pair(aCx);
-  JS::Rooted<JS::Value> pairVal(aCx);
   for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) {
     url = JS_NewUCStringCopyN(aCx, mPendingScripts[i].get(), mPendingScripts[i].Length());
     NS_ENSURE_TRUE(url, NS_ERROR_OUT_OF_MEMORY);
 
     JS::Value pairElts[] = { JS::StringValue(url),
                              JS::BooleanValue(mPendingScriptsGlobalStates[i]) };
 
     pair = JS_NewArrayObject(aCx, 2, pairElts);
     NS_ENSURE_TRUE(pair, NS_ERROR_OUT_OF_MEMORY);
 
-    pairVal = JS::ObjectValue(*pair);
-    NS_ENSURE_TRUE(JS_SetElement(aCx, array, i, &pairVal),
+    NS_ENSURE_TRUE(JS_SetElement(aCx, array, i, pair),
                    NS_ERROR_OUT_OF_MEMORY);
   }
 
   aList.setObject(*array);
   return NS_OK;
 }
 
 static bool
@@ -608,17 +606,17 @@ nsFrameMessageManager::SendMessage(const
       continue;
     }
 
     JS::Rooted<JS::Value> ret(aCx);
     if (!JS_ParseJSON(aCx, static_cast<const jschar*>(retval[i].get()),
                       retval[i].Length(), &ret)) {
       return NS_ERROR_UNEXPECTED;
     }
-    NS_ENSURE_TRUE(JS_SetElement(aCx, dataArray, i, &ret),
+    NS_ENSURE_TRUE(JS_SetElement(aCx, dataArray, i, ret),
                    NS_ERROR_OUT_OF_MEMORY);
   }
 
   aRetval.setObject(*dataArray);
   return NS_OK;
 }
 
 nsresult
--- a/dom/camera/CameraControlImpl.cpp
+++ b/dom/camera/CameraControlImpl.cpp
@@ -184,18 +184,17 @@ CameraControlImpl::Get(JSContext* aCx, u
       return NS_ERROR_FAILURE;
     }
     DOM_CAMERA_LOGI("weight=%d\n", r->weight);
     v = INT_TO_JSVAL(r->weight);
     if (!JS_SetProperty(aCx, o, "weight", v)) {
       return NS_ERROR_FAILURE;
     }
 
-    v = OBJECT_TO_JSVAL(o);
-    if (!JS_SetElement(aCx, array, i, &v)) {
+    if (!JS_SetElement(aCx, array, i, o)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   *aValue = JS::ObjectValue(*array);
   return NS_OK;
 }
 
--- a/dom/camera/DOMCameraCapabilities.cpp
+++ b/dom/camera/DOMCameraCapabilities.cpp
@@ -39,42 +39,39 @@ ParseZoomRatioItemAndAdd(JSContext* aCx,
    * The by-100 divisor is Gonk-specific.  For now, assume other platforms
    * return actual fractional multipliers.
    */
   double d = strtod(aStart, aEnd);
 #if MOZ_WIDGET_GONK
   d /= 100;
 #endif
 
-  JS::Rooted<JS::Value> v(aCx, JS_NumberValue(d));
-
-  if (!JS_SetElement(aCx, aArray, aIndex, &v)) {
+  if (!JS_SetElement(aCx, aArray, aIndex, d)) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 static nsresult
 ParseStringItemAndAdd(JSContext* aCx, JS::Handle<JSObject*> aArray,
                       uint32_t aIndex, const char* aStart, char** aEnd)
 {
-  JSString* s;
+  JS::Rooted<JSString*> s(aCx);
 
   if (*aEnd) {
     s = JS_NewStringCopyN(aCx, aStart, *aEnd - aStart);
   } else {
     s = JS_NewStringCopyZ(aCx, aStart);
   }
   if (!s) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  JS::Rooted<JS::Value> v(aCx, STRING_TO_JSVAL(s));
-  if (!JS_SetElement(aCx, aArray, aIndex, &v)) {
+  if (!JS_SetElement(aCx, aArray, aIndex, s)) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 static nsresult
 ParseDimensionItemAndAdd(JSContext* aCx, JS::Handle<JSObject*> aArray,
@@ -97,18 +94,17 @@ ParseDimensionItemAndAdd(JSContext* aCx,
 
   if (!JS_SetProperty(aCx, o, "width", w)) {
     return NS_ERROR_FAILURE;
   }
   if (!JS_SetProperty(aCx, o, "height", h)) {
     return NS_ERROR_FAILURE;
   }
 
-  JS::Rooted<JS::Value> v(aCx, OBJECT_TO_JSVAL(o));
-  if (!JS_SetElement(aCx, aArray, aIndex, &v)) {
+  if (!JS_SetElement(aCx, aArray, aIndex, o)) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 nsresult
 DOMCameraCapabilities::ParameterListToNewArray(JSContext* aCx,
@@ -393,18 +389,17 @@ DOMCameraCapabilities::GetVideoSizes(JSC
     if (!JS_SetProperty(cx, o, "width", v)) {
       return NS_ERROR_FAILURE;
     }
     v = INT_TO_JSVAL(sizes[i].height);
     if (!JS_SetProperty(cx, o, "height", v)) {
       return NS_ERROR_FAILURE;
     }
 
-    v = OBJECT_TO_JSVAL(o);
-    if (!JS_SetElement(cx, array, i, &v)) {
+    if (!JS_SetElement(cx, array, i, o)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   aVideoSizes.setObject(*array);
   return NS_OK;
 }
 
--- a/dom/file/ArchiveRequest.cpp
+++ b/dom/file/ArchiveRequest.cpp
@@ -176,29 +176,28 @@ ArchiveRequest::GetFilenamesResult(JSCon
 {
   JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, aFileList.Length(), nullptr));
   nsresult rv;
 
   if (!array) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
+  JS::Rooted<JSString*> str(aCx);
   for (uint32_t i = 0; i < aFileList.Length(); ++i) {
     nsCOMPtr<nsIDOMFile> file = aFileList[i];
 
     nsString filename;
     rv = file->GetName(filename);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    JSString* str = JS_NewUCStringCopyZ(aCx, filename.get());
+    str = JS_NewUCStringCopyZ(aCx, filename.get());
     NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
 
-    JS::Rooted<JS::Value> item(aCx, STRING_TO_JSVAL(str));
-
-    if (NS_FAILED(rv) || !JS_SetElement(aCx, array, i, &item)) {
+    if (NS_FAILED(rv) || !JS_SetElement(aCx, array, i, str)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   if (!JS_FreezeObject(aCx, array)) {
     return NS_ERROR_FAILURE;
   }
 
@@ -241,17 +240,17 @@ ArchiveRequest::GetFilesResult(JSContext
   for (uint32_t i = 0; i < aFileList.Length(); ++i) {
     nsCOMPtr<nsIDOMFile> file = aFileList[i];
 
     JS::Rooted<JS::Value> value(aCx);
     JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
     nsresult rv = nsContentUtils::WrapNative(aCx, global, file,
                                              &NS_GET_IID(nsIDOMFile),
                                              &value);
-    if (NS_FAILED(rv) || !JS_SetElement(aCx, array, i, &value)) {
+    if (NS_FAILED(rv) || !JS_SetElement(aCx, array, i, value)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   aValue.setObject(*array);
   return NS_OK;
 }
 
--- a/dom/indexedDB/AsyncConnectionHelper.cpp
+++ b/dom/indexedDB/AsyncConnectionHelper.cpp
@@ -74,17 +74,17 @@ ConvertCloneReadInfosToArrayInternal(
       StructuredCloneReadInfo& readInfo = aReadInfos[index];
 
       JS::Rooted<JS::Value> val(aCx);
       if (!IDBObjectStore::DeserializeValue(aCx, readInfo, &val)) {
         NS_WARNING("Failed to decode!");
         return NS_ERROR_DOM_DATA_CLONE_ERR;
       }
 
-      if (!JS_SetElement(aCx, array, index, &val)) {
+      if (!JS_SetElement(aCx, array, index, val)) {
         NS_WARNING("Failed to set array element!");
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
     }
   }
 
   aResult.setObject(*array);
   return NS_OK;
--- a/dom/indexedDB/IDBIndex.cpp
+++ b/dom/indexedDB/IDBIndex.cpp
@@ -1462,17 +1462,17 @@ GetAllKeysHelper::GetSuccessResult(JSCon
 
       JS::Rooted<JS::Value> value(aCx);
       nsresult rv = key.ToJSVal(aCx, &value);
       if (NS_FAILED(rv)) {
         NS_WARNING("Failed to get jsval for key!");
         return rv;
       }
 
-      if (!JS_SetElement(aCx, array, index, &value)) {
+      if (!JS_SetElement(aCx, array, index, value)) {
         NS_WARNING("Failed to set array element!");
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
     }
   }
 
   aVal.setObject(*array);
   return NS_OK;
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -4942,17 +4942,17 @@ GetAllKeysHelper::GetSuccessResult(JSCon
 
       JS::Rooted<JS::Value> value(aCx);
       nsresult rv = key.ToJSVal(aCx, &value);
       if (NS_FAILED(rv)) {
         NS_WARNING("Failed to get jsval for key!");
         return rv;
       }
 
-      if (!JS_SetElement(aCx, array, index, &value)) {
+      if (!JS_SetElement(aCx, array, index, value)) {
         NS_WARNING("Failed to set array element!");
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
     }
   }
 
   aVal.setObject(*array);
   return NS_OK;
--- a/dom/indexedDB/Key.cpp
+++ b/dom/indexedDB/Key.cpp
@@ -203,17 +203,17 @@ Key::DecodeJSValInternal(const unsigned 
     JS::Rooted<JS::Value> val(aCx);
     while (aPos < aEnd && *aPos - aTypeOffset != eTerminator) {
       nsresult rv = DecodeJSValInternal(aPos, aEnd, aCx, aTypeOffset,
                                         &val, aRecursionDepth + 1);
       NS_ENSURE_SUCCESS(rv, rv);
 
       aTypeOffset = 0;
 
-      if (!JS_SetElement(aCx, array, index++, &val)) {
+      if (!JS_SetElement(aCx, array, index++, val)) {
         NS_WARNING("Failed to set array element!");
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
     }
 
     NS_ASSERTION(aPos >= aEnd || (*aPos % eMaxType) == eTerminator,
                  "Should have found end-of-array marker");
     ++aPos;
--- a/dom/indexedDB/KeyPath.cpp
+++ b/dom/indexedDB/KeyPath.cpp
@@ -394,17 +394,17 @@ KeyPath::ExtractKeyAsJSVal(JSContext* aC
     nsresult rv = GetJSValFromKeyPathString(aCx, aValue, mStrings[i],
                                             value.address(),
                                             DoNotCreateProperties, nullptr,
                                             nullptr);
     if (NS_FAILED(rv)) {
       return rv;
     }
 
-    if (!JS_SetElement(aCx, arrayObj, i, &value)) {
+    if (!JS_SetElement(aCx, arrayObj, i, value)) {
       return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
     }
   }
 
   *aOutVal = OBJECT_TO_JSVAL(arrayObj);
   return NS_OK;
 }
 
@@ -503,17 +503,17 @@ KeyPath::ToJSVal(JSContext* aCx, JS::Mut
 
     for (uint32_t i = 0; i < len; ++i) {
       JS::Rooted<JS::Value> val(aCx);
       nsString tmp(mStrings[i]);
       if (!xpc::StringToJsval(aCx, tmp, &val)) {
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
 
-      if (!JS_SetElement(aCx, array, i, &val)) {
+      if (!JS_SetElement(aCx, array, i, val)) {
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
     }
 
     aValue.setObject(*array);
     return NS_OK;
   }
 
--- a/dom/mobilemessage/src/MmsMessage.cpp
+++ b/dom/mobilemessage/src/MmsMessage.cpp
@@ -541,18 +541,17 @@ MmsMessage::GetDeliveryInfo(JSContext* a
 
     // Get |info.readTimestamp|.
     tmpJsVal.setNumber(static_cast<double>(info.readTimestamp));
     if (!JS_DefineProperty(aCx, infoJsObj, "readTimestamp", tmpJsVal,
                            nullptr, nullptr, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
 
-    tmpJsVal = OBJECT_TO_JSVAL(infoJsObj);
-    if (!JS_SetElement(aCx, deliveryInfo, i, &tmpJsVal)) {
+    if (!JS_SetElement(aCx, deliveryInfo, i, infoJsObj)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   aDeliveryInfo.setObject(*deliveryInfo);
   return NS_OK;
 }
 
@@ -661,18 +660,17 @@ MmsMessage::GetAttachments(JSContext* aC
                                              &tmpJsVal);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!JS_DefineProperty(aCx, attachmentObj, "content", tmpJsVal,
                            nullptr, nullptr, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
 
-    tmpJsVal = OBJECT_TO_JSVAL(attachmentObj);
-    if (!JS_SetElement(aCx, attachments, i, &tmpJsVal)) {
+    if (!JS_SetElement(aCx, attachments, i, attachmentObj)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   aAttachments.setObject(*attachments);
   return NS_OK;
 }
 
--- a/dom/mobilemessage/src/MobileMessageCallback.cpp
+++ b/dom/mobilemessage/src/MobileMessageCallback.cpp
@@ -163,20 +163,18 @@ MobileMessageCallback::NotifyMessageDele
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(sc, NS_ERROR_FAILURE);
 
   AutoPushJSContext cx(sc->GetNativeContext());
   NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
 
   JS::Rooted<JSObject*> deleteArrayObj(cx,
                                        JS_NewArrayObject(cx, aSize, nullptr));
-  JS::Rooted<JS::Value> value(cx);
   for (uint32_t i = 0; i < aSize; i++) {
-    value.setBoolean(aDeleted[i]);
-    JS_SetElement(cx, deleteArrayObj, i, &value);
+    JS_SetElement(cx, deleteArrayObj, i, aDeleted[i]);
   }
 
   JS::Rooted<JS::Value> deleteArrayVal(cx, JS::ObjectValue(*deleteArrayObj));
   return NotifySuccess(deleteArrayVal);
 }
 
 NS_IMETHODIMP
 MobileMessageCallback::NotifyDeleteMessageFailed(int32_t aError)
--- a/dom/mobilemessage/src/ipc/SmsParent.cpp
+++ b/dom/mobilemessage/src/ipc/SmsParent.cpp
@@ -116,18 +116,17 @@ GetParamsFromSendMmsMessageRequest(JSCon
   // attachments
   JS::Rooted<JSObject*> attachmentArray(aCx, JS_NewArrayObject(aCx,
                                                                aRequest.attachments().Length(),
                                                                nullptr));
   for (uint32_t i = 0; i < aRequest.attachments().Length(); i++) {
     JS::Rooted<JSObject*> obj(aCx,
       MmsAttachmentDataToJSObject(aCx, aRequest.attachments().ElementAt(i)));
     NS_ENSURE_TRUE(obj, false);
-    JS::Rooted<JS::Value> val(aCx, JS::ObjectValue(*obj));
-    if (!JS_SetElement(aCx, attachmentArray, i, &val)) {
+    if (!JS_SetElement(aCx, attachmentArray, i, obj)) {
       return false;
     }
   }
 
   if (!JS_DefineProperty(aCx, paramsObj, "attachments",
                          JS::ObjectValue(*attachmentArray), nullptr, nullptr, 0)) {
     return false;
   }
--- a/js/src/jsapi-tests/testArrayBuffer.cpp
+++ b/js/src/jsapi-tests/testArrayBuffer.cpp
@@ -18,18 +18,17 @@ BEGIN_TEST(testArrayBuffer_bug720949_ste
     uint32_t sizes[NUM_TEST_BUFFERS] = { sizeof(uint32_t), 200 * sizeof(uint32_t) };
     JS::HandleObject testBuf[NUM_TEST_BUFFERS] = { buf_len1, buf_len200 };
     JS::HandleObject testArray[NUM_TEST_BUFFERS] = { tarray_len1, tarray_len200 };
 
     // Single-element ArrayBuffer (uses fixed slots for storage)
     CHECK(buf_len1 = JS_NewArrayBuffer(cx, sizes[0]));
     CHECK(tarray_len1 = JS_NewInt32ArrayWithBuffer(cx, testBuf[0], 0, -1));
 
-    JS::RootedValue dummy(cx, INT_TO_JSVAL(MAGIC_VALUE_1));
-    JS_SetElement(cx, testArray[0], 0, &dummy);
+    JS_SetElement(cx, testArray[0], 0, MAGIC_VALUE_1);
 
     // Many-element ArrayBuffer (uses dynamic storage)
     CHECK(buf_len200 = JS_NewArrayBuffer(cx, 200 * sizeof(uint32_t)));
     CHECK(tarray_len200 = JS_NewInt32ArrayWithBuffer(cx, testBuf[1], 0, -1));
 
     for (unsigned i = 0; i < NUM_TEST_BUFFERS; i++) {
         JS::HandleObject obj = testBuf[i];
         JS::HandleObject view = testArray[i];
--- a/js/src/jsapi-tests/testNewObject.cpp
+++ b/js/src/jsapi-tests/testNewObject.cpp
@@ -34,17 +34,17 @@ constructHook(JSContext *cx, unsigned ar
     if (!args.isConstructing()) {
         JS_ReportError(cx, "test failed, not constructing");
         return false;
     }
 
     // Perform a side-effect to indicate that this hook was actually called.
     JS::RootedValue value(cx, args[0]);
     JS::RootedObject callee(cx, &args.callee());
-    if (!JS_SetElement(cx, callee, 0, &value))
+    if (!JS_SetElement(cx, callee, 0, value))
         return false;
 
     args.rval().setObject(*obj);
 
     // trash the argv, perversely
     args[0].setUndefined();
     args[1].setUndefined();
     args[2].setUndefined();
--- a/js/src/jsapi-tests/testTypedArrays.cpp
+++ b/js/src/jsapi-tests/testTypedArrays.cpp
@@ -126,47 +126,47 @@ TestArrayFromBuffer(JSContext *cx)
 
     RootedObject ofsArray(cx, CreateWithBuffer(cx, buffer, nbytes / 2, -1));
     CHECK_EQUAL(JS_GetTypedArrayLength(ofsArray), elts / 2);
     CHECK_EQUAL(JS_GetTypedArrayByteOffset(ofsArray), nbytes / 2);
     CHECK_EQUAL(JS_GetTypedArrayByteLength(ofsArray), nbytes / 2);
 
     // 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_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]));
 
     v = INT_TO_JSVAL(40);
-    JS_SetElement(cx, array, elts / 2, &v);
+    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]));
 
     v = INT_TO_JSVAL(41);
-    JS_SetElement(cx, array, elts - 1, &v);
+    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]));
 
     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);
-    JS_SetElement(cx, array, 0, &v2);
+    JS_SetElement(cx, array, 0, v2);
     CHECK(JS_GetElement(cx, copy, 0, &v2));
     CHECK_SAME(v2, v); /* v is still the original value from 'array' */
 
     return true;
 }
 
 END_TEST(testTypedArrays)
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3432,28 +3432,70 @@ JS_SetPropertyById(JSContext *cx, Handle
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, obj, id);
     JSAutoResolveFlags rf(cx, JSRESOLVE_ASSIGNING);
 
     return JSObject::setGeneric(cx, obj, obj, id, &value, false);
 }
 
-JS_PUBLIC_API(bool)
-JS_SetElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleValue vp)
+static bool
+SetElement(JSContext *cx, HandleObject obj, uint32_t index, MutableHandleValue vp)
 {
     AssertHeapIsIdle(cx);
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, obj, vp);
     JSAutoResolveFlags rf(cx, JSRESOLVE_ASSIGNING);
 
     return JSObject::setElement(cx, obj, obj, index, vp, false);
 }
 
 JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, HandleObject obj, uint32_t index, HandleValue v)
+{
+    RootedValue value(cx, v);
+    return SetElement(cx, obj, index, &value);
+}
+
+JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, HandleObject obj, uint32_t index, HandleObject v)
+{
+    RootedValue value(cx, ObjectOrNullValue(v));
+    return SetElement(cx, obj, index, &value);
+}
+
+JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, HandleObject obj, uint32_t index, HandleString v)
+{
+    RootedValue value(cx, StringValue(v));
+    return SetElement(cx, obj, index, &value);
+}
+
+JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, HandleObject obj, uint32_t index, int32_t v)
+{
+    RootedValue value(cx, NumberValue(v));
+    return SetElement(cx, obj, index, &value);
+}
+
+JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, HandleObject obj, uint32_t index, uint32_t v)
+{
+    RootedValue value(cx, NumberValue(v));
+    return SetElement(cx, obj, index, &value);
+}
+
+JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, HandleObject obj, uint32_t index, double v)
+{
+    RootedValue value(cx, NumberValue(v));
+    return SetElement(cx, obj, index, &value);
+}
+
+JS_PUBLIC_API(bool)
 JS_SetProperty(JSContext *cx, HandleObject obj, const char *name, HandleValue v)
 {
     JSAtom *atom = Atomize(cx, name, strlen(name));
     RootedId id(cx, AtomToId(atom));
     return atom && JS_SetPropertyById(cx, obj, id, v);
 }
 
 JS_PUBLIC_API(bool)
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -3110,17 +3110,32 @@ JS_LookupElement(JSContext *cx, JS::Hand
 extern JS_PUBLIC_API(bool)
 JS_GetElement(JSContext *cx, JSObject *obj, uint32_t index, JS::MutableHandleValue vp);
 
 extern JS_PUBLIC_API(bool)
 JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf,
                        JS::MutableHandleValue vp);
 
 extern JS_PUBLIC_API(bool)
-JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::MutableHandleValue vp);
+JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleValue v);
+
+extern JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleObject v);
+
+extern JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, JS::HandleString v);
+
+extern JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, int32_t v);
+
+extern JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, uint32_t v);
+
+extern JS_PUBLIC_API(bool)
+JS_SetElement(JSContext *cx, JS::HandleObject obj, uint32_t index, double v);
 
 extern JS_PUBLIC_API(bool)
 JS_DeleteElement(JSContext *cx, JS::HandleObject obj, uint32_t index);
 
 extern JS_PUBLIC_API(bool)
 JS_DeleteElement2(JSContext *cx, JS::HandleObject obj, uint32_t index, bool *succeeded);
 
 /*
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2353,19 +2353,17 @@ GetPDA(JSContext *cx, unsigned argc, jsv
     for (uint32_t i = 0; i < pda.length; i++, pd++) {
         pdobj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
         if (!pdobj) {
             ok = false;
             break;
         }
 
         /* Protect pdobj from GC by setting it as an element of aobj now */
-        RootedValue v(cx);
-        v.setObject(*pdobj);
-        ok = !!JS_SetElement(cx, aobj, i, &v);
+        ok = !!JS_SetElement(cx, aobj, i, pdobj);
         if (!ok)
             break;
 
         id = pd->id;
         value = pd->value;
         flags.setInt32(pd->flags);
         alias = pd->alias;
         ok = JS_SetProperty(cx, pdobj, "id", id) &&
--- a/js/src/shell/jsheaptools.cpp
+++ b/js/src/shell/jsheaptools.cpp
@@ -518,17 +518,17 @@ ReferenceFinder::addReferrer(jsval refer
 
     /* The property's value had better be an array. */
     RootedObject array(context, &v.toObject());
     JS_ASSERT(JS_IsArrayObject(context, array));
 
     /* Append our referrer to this array. */
     uint32_t length;
     return JS_GetArrayLength(context, array, &length) &&
-           JS_SetElement(context, array, length, &referrer);
+           JS_SetElement(context, array, length, referrer);
 }
 
 JSObject *
 ReferenceFinder::findReferences(HandleObject target)
 {
     result = JS_NewObject(context, nullptr, JS::NullPtr(), JS::NullPtr());
     if (!result)
         return nullptr;
--- a/js/xpconnect/public/nsTArrayHelpers.h
+++ b/js/xpconnect/public/nsTArrayHelpers.h
@@ -30,17 +30,17 @@ nsTArrayToJSArray(JSContext* aCx, const 
     nsCOMPtr<nsISupports> obj;
     nsresult rv = aSourceArray[index]->QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(obj));
     NS_ENSURE_SUCCESS(rv, rv);
 
     JS::RootedValue wrappedVal(aCx);
     rv = nsContentUtils::WrapNative(aCx, global, obj, &wrappedVal, true);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    if (!JS_SetElement(aCx, arrayObj, index, &wrappedVal)) {
+    if (!JS_SetElement(aCx, arrayObj, index, wrappedVal)) {
       NS_WARNING("JS_SetElement failed!");
       return NS_ERROR_FAILURE;
     }
   }
 
   if (!JS_FreezeObject(aCx, arrayObj)) {
     NS_WARNING("JS_FreezeObject failed!");
     return NS_ERROR_FAILURE;
@@ -60,28 +60,27 @@ nsTArrayToJSArray<nsString>(JSContext* a
 
   JS::Rooted<JSObject*> arrayObj(aCx,
     JS_NewArrayObject(aCx, aSourceArray.Length(), nullptr));
   if (!arrayObj) {
     NS_WARNING("JS_NewArrayObject failed!");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
+  JS::Rooted<JSString*> s(aCx);
   for (uint32_t index = 0; index < aSourceArray.Length(); index++) {
-    JSString* s = JS_NewUCStringCopyN(aCx, aSourceArray[index].BeginReading(),
-                                      aSourceArray[index].Length());
+    s = JS_NewUCStringCopyN(aCx, aSourceArray[index].BeginReading(),
+                            aSourceArray[index].Length());
 
     if(!s) {
       NS_WARNING("Memory allocation error!");
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
-    JS::Rooted<JS::Value> wrappedVal(aCx, STRING_TO_JSVAL(s));
-
-    if (!JS_SetElement(aCx, arrayObj, index, &wrappedVal)) {
+    if (!JS_SetElement(aCx, arrayObj, index, s)) {
       NS_WARNING("JS_SetElement failed!");
       return NS_ERROR_FAILURE;
     }
   }
 
   if (!JS_FreezeObject(aCx, arrayObj)) {
     NS_WARNING("JS_FreezeObject failed!");
     return NS_ERROR_FAILURE;
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -1371,17 +1371,17 @@ XPCConvert::NativeArray2JS(MutableHandle
 
     uint32_t i;
     RootedValue current(cx, JSVAL_NULL);
 
 #define POPULATE(_t)                                                                    \
     PR_BEGIN_MACRO                                                                      \
         for (i = 0; i < count; i++) {                                                   \
             if (!NativeData2JS(&current, ((_t*)*s)+i, type, iid, pErr) ||               \
-                !JS_SetElement(cx, array, i, &current))                                 \
+                !JS_SetElement(cx, array, i, current))                                  \
                 goto failure;                                                           \
         }                                                                               \
     PR_END_MACRO
 
     // XXX check IsPtr - esp. to handle array of nsID (as opposed to nsID*)
 
     switch (type.TagPart()) {
     case nsXPTType::T_I8            : POPULATE(int8_t);         break;
--- a/storage/src/mozStorageStatementRow.cpp
+++ b/storage/src/mozStorageStatementRow.cpp
@@ -89,20 +89,18 @@ StatementRow::GetProperty(nsIXPConnectWr
       JSObject *obj = ::JS_NewArrayObject(aCtx, length, nullptr);
       if (!obj) {
         *_retval = false;
         return NS_OK;
       }
       *_vp = OBJECT_TO_JSVAL(obj);
 
       // Copy the blob over to the JS array.
-      JS::Rooted<JS::Value> val(aCtx);
       for (uint32_t i = 0; i < length; i++) {
-        val.setInt32(blob[i]);
-        if (!::JS_SetElement(aCtx, scope, i, &val)) {
+        if (!::JS_SetElement(aCtx, scope, i, blob[i])) {
           *_retval = false;
           return NS_OK;
         }
       }
     }
     else if (type == mozIStorageValueArray::VALUE_TYPE_NULL) {
       *_vp = JSVAL_NULL;
     }
--- a/toolkit/components/places/PlaceInfo.cpp
+++ b/toolkit/components/places/PlaceInfo.cpp
@@ -113,19 +113,18 @@ PlaceInfo::GetVisits(JSContext* aContext
     nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
     nsresult rv = xpc->WrapNative(aContext, global, mVisits[idx],
                                   NS_GET_IID(mozIVisitInfo),
                                   getter_AddRefs(wrapper));
     NS_ENSURE_SUCCESS(rv, rv);
 
     JS::Rooted<JSObject*> jsobj(aContext, wrapper->GetJSObject());
     NS_ENSURE_STATE(jsobj);
-    JS::Rooted<JS::Value> wrappedVisit(aContext, OBJECT_TO_JSVAL(jsobj));
 
-    bool rc = JS_SetElement(aContext, visits, idx, &wrappedVisit);
+    bool rc = JS_SetElement(aContext, visits, idx, jsobj);
     NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED);
   }
 
   _visits.setObject(*visits);
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -998,25 +998,23 @@ TelemetryImpl::ReflectSQL(const SlowSQLE
                           const Stat *stat,
                           JSContext *cx,
                           JS::Handle<JSObject*> obj)
 {
   if (stat->hitCount == 0)
     return true;
 
   const nsACString &sql = entry->GetKey();
-  JS::Rooted<JS::Value> hitCount(cx, UINT_TO_JSVAL(stat->hitCount));
-  JS::Rooted<JS::Value> totalTime(cx, UINT_TO_JSVAL(stat->totalTime));
 
   JS::Rooted<JSObject*> arrayObj(cx, JS_NewArrayObject(cx, 0, nullptr));
   if (!arrayObj) {
     return false;
   }
-  return (JS_SetElement(cx, arrayObj, 0, &hitCount)
-          && JS_SetElement(cx, arrayObj, 1, &totalTime)
+  return (JS_SetElement(cx, arrayObj, 0, stat->hitCount)
+          && JS_SetElement(cx, arrayObj, 1, stat->totalTime)
           && JS_DefineProperty(cx, obj,
                                sql.BeginReading(),
                                OBJECT_TO_JSVAL(arrayObj),
                                nullptr, nullptr, JSPROP_ENUMERATE));
 }
 
 bool
 TelemetryImpl::ReflectMainThreadSQL(SlowSQLEntryType *entry, JSContext *cx,
@@ -1508,18 +1506,17 @@ TelemetryImpl::GetChromeHangs(JSContext 
                               OBJECT_TO_JSVAL(durationArray),
                               nullptr, nullptr, JSPROP_ENUMERATE);
   if (!ok) {
     return NS_ERROR_FAILURE;
   }
 
   const size_t length = stacks.GetStackCount();
   for (size_t i = 0; i < length; ++i) {
-    JS::Rooted<JS::Value> duration(cx, INT_TO_JSVAL(mHangReports.GetDuration(i)));
-    if (!JS_SetElement(cx, durationArray, i, &duration)) {
+    if (!JS_SetElement(cx, durationArray, i, mHangReports.GetDuration(i))) {
       return NS_ERROR_FAILURE;
     }
   }
 
   return NS_OK;
 }
 
 static JSObject *
@@ -1545,40 +1542,37 @@ CreateJSStackObject(JSContext *cx, const
     // Current module
     const Telemetry::ProcessedStack::Module& module =
       stacks.GetModule(moduleIndex);
 
     JS::Rooted<JSObject*> moduleInfoArray(cx, JS_NewArrayObject(cx, 0, nullptr));
     if (!moduleInfoArray) {
       return nullptr;
     }
-    JS::Rooted<JS::Value> val(cx, OBJECT_TO_JSVAL(moduleInfoArray));
-    if (!JS_SetElement(cx, moduleArray, moduleIndex, &val)) {
+    if (!JS_SetElement(cx, moduleArray, moduleIndex, moduleInfoArray)) {
       return nullptr;
     }
 
     unsigned index = 0;
 
     // Module name
-    JSString *str = JS_NewStringCopyZ(cx, module.mName.c_str());
+    JS::Rooted<JSString*> str(cx, JS_NewStringCopyZ(cx, module.mName.c_str()));
     if (!str) {
       return nullptr;
     }
-    val = STRING_TO_JSVAL(str);
-    if (!JS_SetElement(cx, moduleInfoArray, index++, &val)) {
+    if (!JS_SetElement(cx, moduleInfoArray, index++, str)) {
       return nullptr;
     }
 
     // Module breakpad identifier
-    JSString *id = JS_NewStringCopyZ(cx, module.mBreakpadId.c_str());
+    JS::Rooted<JSString*> id(cx, JS_NewStringCopyZ(cx, module.mBreakpadId.c_str()));
     if (!id) {
       return nullptr;
     }
-    val = STRING_TO_JSVAL(id);
-    if (!JS_SetElement(cx, moduleInfoArray, index++, &val)) {
+    if (!JS_SetElement(cx, moduleInfoArray, index++, id)) {
       return nullptr;
     }
   }
 
   JS::Rooted<JSObject*> reportArray(cx, JS_NewArrayObject(cx, 0, nullptr));
   if (!reportArray) {
     return nullptr;
   }
@@ -1592,41 +1586,37 @@ CreateJSStackObject(JSContext *cx, const
   const size_t length = stacks.GetStackCount();
   for (size_t i = 0; i < length; ++i) {
     // Represent call stack PCs as (module index, offset) pairs.
     JS::Rooted<JSObject*> pcArray(cx, JS_NewArrayObject(cx, 0, nullptr));
     if (!pcArray) {
       return nullptr;
     }
 
-    JS::Rooted<JS::Value> pcArrayVal(cx, OBJECT_TO_JSVAL(pcArray));
-    if (!JS_SetElement(cx, reportArray, i, &pcArrayVal)) {
+    if (!JS_SetElement(cx, reportArray, i, pcArray)) {
       return nullptr;
     }
 
     const CombinedStacks::Stack& stack = stacks.GetStack(i);
     const uint32_t pcCount = stack.size();
     for (size_t pcIndex = 0; pcIndex < pcCount; ++pcIndex) {
       const Telemetry::ProcessedStack::Frame& frame = stack[pcIndex];
       JS::Rooted<JSObject*> framePair(cx, JS_NewArrayObject(cx, 0, nullptr));
       if (!framePair) {
         return nullptr;
       }
       int modIndex = (std::numeric_limits<uint16_t>::max() == frame.mModIndex) ?
         -1 : frame.mModIndex;
-      JS::Rooted<JS::Value> modIndexVal(cx, INT_TO_JSVAL(modIndex));
-      if (!JS_SetElement(cx, framePair, 0, &modIndexVal)) {
+      if (!JS_SetElement(cx, framePair, 0, modIndex)) {
         return nullptr;
       }
-      JS::Rooted<JS::Value> mOffsetVal(cx, INT_TO_JSVAL(frame.mOffset));
-      if (!JS_SetElement(cx, framePair, 1, &mOffsetVal)) {
+      if (!JS_SetElement(cx, framePair, 1, static_cast<double>(frame.mOffset))) {
         return nullptr;
       }
-      JS::Rooted<JS::Value> framePairVal(cx, OBJECT_TO_JSVAL(framePair));
-      if (!JS_SetElement(cx, pcArray, pcIndex, &framePairVal)) {
+      if (!JS_SetElement(cx, pcArray, pcIndex, framePair)) {
         return nullptr;
       }
     }
   }
 
   return ret;
 }
 
@@ -1754,27 +1744,23 @@ CreateJSTimeHistogram(JSContext* cx, con
     cx, JS_NewArrayObject(cx, ArrayLength(time) + 1, nullptr));
   JS::RootedObject counts(
     cx, JS_NewArrayObject(cx, ArrayLength(time) + 1, nullptr));
   if (!ranges || !counts) {
     return nullptr;
   }
   /* In a Chromium-style histogram, the first bucket is an "under" bucket
      that represents all values below the histogram's range. */
-  JS::RootedValue underRange(cx, INT_TO_JSVAL(time.GetBucketMin(0)));
-  JS::RootedValue underCount(cx, INT_TO_JSVAL(0));
-  if (!JS_SetElement(cx, ranges, 0, &underRange) ||
-      !JS_SetElement(cx, counts, 0, &underCount)) {
+  if (!JS_SetElement(cx, ranges, 0, time.GetBucketMin(0)) ||
+      !JS_SetElement(cx, counts, 0, 0)) {
     return nullptr;
   }
   for (size_t i = 0; i < ArrayLength(time); i++) {
-    JS::RootedValue range(cx, UINT_TO_JSVAL(time.GetBucketMax(i)));
-    JS::RootedValue count(cx, UINT_TO_JSVAL(time[i]));
-    if (!JS_SetElement(cx, ranges, i + 1, &range) ||
-        !JS_SetElement(cx, counts, i + 1, &count)) {
+    if (!JS_SetElement(cx, ranges, i + 1, time.GetBucketMax(i)) ||
+        !JS_SetElement(cx, counts, i + 1, time[i])) {
       return nullptr;
     }
   }
   if (!JS_DefineProperty(cx, ret, "ranges", OBJECT_TO_JSVAL(ranges),
                          nullptr, nullptr, JSPROP_ENUMERATE) ||
       !JS_DefineProperty(cx, ret, "counts", OBJECT_TO_JSVAL(counts),
                          nullptr, nullptr, JSPROP_ENUMERATE)) {
     return nullptr;
@@ -1793,18 +1779,17 @@ CreateJSHangHistogram(JSContext* cx, con
   const Telemetry::HangHistogram::Stack& hangStack = hang.GetStack();
   JS::RootedObject stack(cx,
     JS_NewArrayObject(cx, hangStack.length(), nullptr));
   if (!ret) {
     return nullptr;
   }
   for (size_t i = 0; i < hangStack.length(); i++) {
     JS::RootedString string(cx, JS_NewStringCopyZ(cx, hangStack[i]));
-    JS::RootedValue frame(cx, STRING_TO_JSVAL(string));
-    if (!JS_SetElement(cx, stack, i, &frame)) {
+    if (!JS_SetElement(cx, stack, i, string)) {
       return nullptr;
     }
   }
 
   JS::RootedObject time(cx, CreateJSTimeHistogram(cx, hang));
   if (!time ||
       !JS_DefineProperty(cx, ret, "stack", OBJECT_TO_JSVAL(stack),
                          nullptr, nullptr, JSPROP_ENUMERATE) ||
@@ -1837,18 +1822,17 @@ CreateJSThreadHangStats(JSContext* cx, c
   }
 
   JS::RootedObject hangs(cx, JS_NewArrayObject(cx, 0, nullptr));
   if (!hangs) {
     return nullptr;
   }
   for (size_t i = 0; i < thread.mHangs.length(); i++) {
     JS::RootedObject obj(cx, CreateJSHangHistogram(cx, thread.mHangs[i]));
-    JS::RootedValue hang(cx, OBJECT_TO_JSVAL(obj));
-    if (!JS_SetElement(cx, hangs, i, &hang)) {
+    if (!JS_SetElement(cx, hangs, i, obj)) {
       return nullptr;
     }
   }
   if (!JS_DefineProperty(cx, ret, "hangs", OBJECT_TO_JSVAL(hangs),
                          nullptr, nullptr, JSPROP_ENUMERATE)) {
     return nullptr;
   }
   return ret;
@@ -1867,29 +1851,27 @@ TelemetryImpl::GetThreadHangStats(JSCont
      throughout this method to avoid a race condition where a thread can
      be recorded twice if the thread is destroyed while this method is
      running */
   BackgroundHangMonitor::ThreadHangStatsIterator iter;
   for (Telemetry::ThreadHangStats* histogram = iter.GetNext();
        histogram; histogram = iter.GetNext()) {
     JS::RootedObject obj(cx,
       CreateJSThreadHangStats(cx, *histogram));
-    JS::RootedValue thread(cx, JS::ObjectValue(*obj));
-    if (!JS_SetElement(cx, retObj, threadIndex++, &thread)) {
+    if (!JS_SetElement(cx, retObj, threadIndex++, obj)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   // Add saved threads next
   MutexAutoLock autoLock(mThreadHangStatsMutex);
   for (size_t i = 0; i < mThreadHangStats.length(); i++) {
     JS::RootedObject obj(cx,
       CreateJSThreadHangStats(cx, mThreadHangStats[i]));
-    JS::RootedValue thread(cx, JS::ObjectValue(*obj));
-    if (!JS_SetElement(cx, retObj, threadIndex++, &thread)) {
+    if (!JS_SetElement(cx, retObj, threadIndex++, obj)) {
       return NS_ERROR_FAILURE;
     }
   }
   ret.setObject(*retObj);
   return NS_OK;
 }
 
 void
--- a/tools/profiler/JSObjectBuilder.cpp
+++ b/tools/profiler/JSObjectBuilder.cpp
@@ -81,18 +81,17 @@ JSObjectBuilder::ArrayPush(JS::HandleObj
     return;
 
   uint32_t length;
   mOk = JS_GetArrayLength(mCx, aArray, &length);
 
   if (!mOk)
     return;
 
-  JS::RootedValue objval(mCx, INT_TO_JSVAL(value));
-  mOk = JS_SetElement(mCx, aArray, length, &objval);
+  mOk = JS_SetElement(mCx, aArray, length, value);
 }
 
 void
 JSObjectBuilder::ArrayPush(JS::HandleObject aArray, const char *value)
 {
   if (!mOk)
     return;
 
@@ -103,34 +102,32 @@ JSObjectBuilder::ArrayPush(JS::HandleObj
   }
 
   uint32_t length;
   mOk = JS_GetArrayLength(mCx, aArray, &length);
 
   if (!mOk)
     return;
 
-  JS::RootedValue objval(mCx, STRING_TO_JSVAL(string));
-  mOk = JS_SetElement(mCx, aArray, length, &objval);
+  mOk = JS_SetElement(mCx, aArray, length, string);
 }
 
 void
 JSObjectBuilder::ArrayPush(JS::HandleObject aArray, JS::HandleObject aObject)
 {
   if (!mOk)
     return;
 
   uint32_t length;
   mOk = JS_GetArrayLength(mCx, aArray, &length);
 
   if (!mOk)
     return;
 
-  JS::RootedValue objval(mCx, OBJECT_TO_JSVAL(aObject));
-  mOk = JS_SetElement(mCx, aArray, length, &objval);
+  mOk = JS_SetElement(mCx, aArray, length, aObject);
 }
 
 JSObject*
 JSObjectBuilder::CreateArray() {
   JSObject *array = JS_NewArrayObject(mCx, 0, nullptr);
   if (!array)
     mOk = false;