Bug 963921 - Clients of the JS API should use JS_DefineElement where appropriate r=smaug
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 02 Mar 2015 13:31:15 +0000
changeset 260153 0d6720105fbb0863b1f1ff020ed26f5cf5a9f14f
parent 260152 4fe43cd0ac7defaf5e57ec1dd1287bbdcf653052
child 260154 e36fa665ed2320d3a317898d35921a73853c5bcb
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs963921
milestone39.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 963921 - Clients of the JS API should use JS_DefineElement where appropriate r=smaug
dom/base/nsFrameMessageManager.cpp
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/Key.cpp
dom/indexedDB/KeyPath.cpp
dom/mobilemessage/MmsMessage.cpp
dom/mobilemessage/MobileMessageCallback.cpp
dom/mobilemessage/ipc/SmsParent.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
--- a/dom/base/nsFrameMessageManager.cpp
+++ b/dom/base/nsFrameMessageManager.cpp
@@ -509,17 +509,17 @@ nsFrameMessageManager::GetDelayedScripts
 
     JS::AutoValueArray<2> pairElts(aCx);
     pairElts[0].setString(url);
     pairElts[1].setBoolean(mPendingScriptsGlobalStates[i]);
 
     pair = JS_NewArrayObject(aCx, pairElts);
     NS_ENSURE_TRUE(pair, NS_ERROR_OUT_OF_MEMORY);
 
-    NS_ENSURE_TRUE(JS_SetElement(aCx, array, i, pair),
+    NS_ENSURE_TRUE(JS_DefineElement(aCx, array, i, pair, JSPROP_ENUMERATE),
                    NS_ERROR_OUT_OF_MEMORY);
   }
 
   aList.setObject(*array);
   return NS_OK;
 }
 
 // nsIFrameScriptLoader
@@ -691,17 +691,17 @@ nsFrameMessageManager::SendMessage(const
       continue;
     }
 
     JS::Rooted<JS::Value> ret(aCx);
     if (!JS_ParseJSON(aCx, static_cast<const char16_t*>(retval[i].get()),
                       retval[i].Length(), &ret)) {
       return NS_ERROR_UNEXPECTED;
     }
-    NS_ENSURE_TRUE(JS_SetElement(aCx, dataArray, i, ret),
+    NS_ENSURE_TRUE(JS_DefineElement(aCx, dataArray, i, ret, JSPROP_ENUMERATE),
                    NS_ERROR_OUT_OF_MEMORY);
   }
 
   aRetval.setObject(*dataArray);
   return NS_OK;
 }
 
 nsresult
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -447,17 +447,18 @@ private:
 
         JS::Rooted<JS::Value> value(aCx);
 
         nsresult rv = GetResult(aCx, &cloneInfo, &value);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
 
-        if (NS_WARN_IF(!JS_SetElement(aCx, array, index, value))) {
+        if (NS_WARN_IF(!JS_DefineElement(aCx, array, index, value,
+                                         JSPROP_ENUMERATE))) {
           IDB_REPORT_INTERNAL_ERR();
           return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
         }
       }
     }
 
     aResult.setObject(*array);
     return NS_OK;
@@ -500,17 +501,18 @@ private:
 
         JS::Rooted<JS::Value> value(aCx);
 
         nsresult rv = GetResult(aCx, &key, &value);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
 
-        if (NS_WARN_IF(!JS_SetElement(aCx, array, index, value))) {
+        if (NS_WARN_IF(!JS_DefineElement(aCx, array, index, value,
+                                         JSPROP_ENUMERATE))) {
           IDB_REPORT_INTERNAL_ERR();
           return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
         }
       }
     }
 
     aResult.setObject(*array);
     return NS_OK;
@@ -1089,17 +1091,17 @@ BackgroundFactoryRequestChild::Recv__del
       break;
 
     default:
       MOZ_CRASH("Unknown response type!");
   }
 
   IDBOpenDBRequest* request = GetOpenDBRequest();
   MOZ_ASSERT(request);
-  
+
   request->NoteComplete();
 
   if (NS_WARN_IF(!result)) {
     return false;
   }
 
   return true;
 }
--- a/dom/indexedDB/Key.cpp
+++ b/dom/indexedDB/Key.cpp
@@ -213,17 +213,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_DefineElement(aCx, array, index++, val, JSPROP_ENUMERATE)) {
         NS_WARNING("Failed to set array element!");
         IDB_REPORT_INTERNAL_ERR();
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
     }
 
     NS_ASSERTION(aPos >= aEnd || (*aPos % eMaxType) == eTerminator,
                  "Should have found end-of-array marker");
--- a/dom/indexedDB/KeyPath.cpp
+++ b/dom/indexedDB/KeyPath.cpp
@@ -354,17 +354,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_DefineElement(aCx, arrayObj, i, value, JSPROP_ENUMERATE)) {
       IDB_REPORT_INTERNAL_ERR();
       return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
     }
   }
 
   *aOutVal = OBJECT_TO_JSVAL(arrayObj);
   return NS_OK;
 }
@@ -466,17 +466,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)) {
         IDB_REPORT_INTERNAL_ERR();
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
 
-      if (!JS_SetElement(aCx, array, i, val)) {
+      if (!JS_DefineElement(aCx, array, i, val, JSPROP_ENUMERATE)) {
         IDB_REPORT_INTERNAL_ERR();
         return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       }
     }
 
     aValue.setObject(*array);
     return NS_OK;
   }
--- a/dom/mobilemessage/MmsMessage.cpp
+++ b/dom/mobilemessage/MmsMessage.cpp
@@ -582,17 +582,17 @@ MmsMessage::GetAttachments(JSContext* aC
     if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) {
       return NS_ERROR_FAILURE;
     }
 
     if (!JS_DefineProperty(aCx, attachmentObj, "content", val, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
 
-    if (!JS_SetElement(aCx, attachments, i, attachmentObj)) {
+    if (!JS_DefineElement(aCx, attachments, i, attachmentObj, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   aAttachments.setObject(*attachments);
   return NS_OK;
 }
 
--- a/dom/mobilemessage/MobileMessageCallback.cpp
+++ b/dom/mobilemessage/MobileMessageCallback.cpp
@@ -192,17 +192,17 @@ MobileMessageCallback::NotifyMessageDele
   AutoJSAPI jsapi;
   if (NS_WARN_IF(!jsapi.Init(mDOMRequest->GetOwner()))) {
     return NS_ERROR_FAILURE;
   }
   JSContext* cx = jsapi.cx();
 
   JS::Rooted<JSObject*> deleteArrayObj(cx, JS_NewArrayObject(cx, aSize));
   for (uint32_t i = 0; i < aSize; i++) {
-    JS_SetElement(cx, deleteArrayObj, i, aDeleted[i]);
+    JS_DefineElement(cx, deleteArrayObj, i, aDeleted[i], JSPROP_ENUMERATE);
   }
 
   JS::Rooted<JS::Value> deleteArrayVal(cx, JS::ObjectValue(*deleteArrayObj));
   return NotifySuccess(deleteArrayVal);
 }
 
 NS_IMETHODIMP
 MobileMessageCallback::NotifyDeleteMessageFailed(int32_t aError)
--- a/dom/mobilemessage/ipc/SmsParent.cpp
+++ b/dom/mobilemessage/ipc/SmsParent.cpp
@@ -115,17 +115,17 @@ GetParamsFromSendMmsMessageRequest(JSCon
 
   // attachments
   JS::Rooted<JSObject*> attachmentArray(aCx, JS_NewArrayObject(aCx,
                                                                aRequest.attachments().Length()));
   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);
-    if (!JS_SetElement(aCx, attachmentArray, i, obj)) {
+    if (!JS_DefineElement(aCx, attachmentArray, i, obj, JSPROP_ENUMERATE)) {
       return false;
     }
   }
 
   if (!JS_DefineProperty(aCx, paramsObj, "attachments", attachmentArray, 0)) {
     return false;
   }
 
--- a/js/xpconnect/public/nsTArrayHelpers.h
+++ b/js/xpconnect/public/nsTArrayHelpers.h
@@ -29,18 +29,18 @@ 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, obj, &wrappedVal);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    if (!JS_SetElement(aCx, arrayObj, index, wrappedVal)) {
-      NS_WARNING("JS_SetElement failed!");
+    if (!JS_DefineElement(aCx, arrayObj, index, wrappedVal, JSPROP_ENUMERATE)) {
+      NS_WARNING("JS_DefineElement failed!");
       return NS_ERROR_FAILURE;
     }
   }
 
   if (!JS_FreezeObject(aCx, arrayObj)) {
     NS_WARNING("JS_FreezeObject failed!");
     return NS_ERROR_FAILURE;
   }
@@ -69,18 +69,18 @@ nsTArrayToJSArray<nsString>(JSContext* a
     s = JS_NewUCStringCopyN(aCx, aSourceArray[index].BeginReading(),
                             aSourceArray[index].Length());
 
     if(!s) {
       NS_WARNING("Memory allocation error!");
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
-    if (!JS_SetElement(aCx, arrayObj, index, s)) {
-      NS_WARNING("JS_SetElement failed!");
+    if (!JS_DefineElement(aCx, arrayObj, index, s, JSPROP_ENUMERATE)) {
+      NS_WARNING("JS_DefineElement 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
@@ -1275,17 +1275,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_DefineElement(cx, array, i, current, JSPROP_ENUMERATE))             \
                 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
@@ -90,17 +90,17 @@ StatementRow::GetProperty(nsIXPConnectWr
       if (!obj) {
         *_retval = false;
         return NS_OK;
       }
       *_vp = OBJECT_TO_JSVAL(obj);
 
       // Copy the blob over to the JS array.
       for (uint32_t i = 0; i < length; i++) {
-        if (!::JS_SetElement(aCtx, scope, i, blob[i])) {
+        if (!::JS_DefineElement(aCtx, scope, i, blob[i], JSPROP_ENUMERATE)) {
           *_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
@@ -114,17 +114,17 @@ PlaceInfo::GetVisits(JSContext* aContext
     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);
 
-    bool rc = JS_SetElement(aContext, visits, idx, jsobj);
+    bool rc = JS_DefineElement(aContext, visits, idx, jsobj, JSPROP_ENUMERATE);
     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
@@ -1918,18 +1918,18 @@ TelemetryImpl::ReflectSQL(const SlowSQLE
     return true;
 
   const nsACString &sql = entry->GetKey();
 
   JS::Rooted<JSObject*> arrayObj(cx, JS_NewArrayObject(cx, 0));
   if (!arrayObj) {
     return false;
   }
-  return (JS_SetElement(cx, arrayObj, 0, stat->hitCount)
-          && JS_SetElement(cx, arrayObj, 1, stat->totalTime)
+  return (JS_DefineElement(cx, arrayObj, 0, stat->hitCount, JSPROP_ENUMERATE)
+          && JS_DefineElement(cx, arrayObj, 1, stat->totalTime, JSPROP_ENUMERATE)
           && JS_DefineProperty(cx, obj, sql.BeginReading(), arrayObj,
                                JSPROP_ENUMERATE));
 }
 
 bool
 TelemetryImpl::ReflectMainThreadSQL(SlowSQLEntryType *entry, JSContext *cx,
                                     JS::Handle<JSObject*> obj)
 {
@@ -2518,36 +2518,39 @@ TelemetryImpl::GetChromeHangs(JSContext 
                          JSPROP_ENUMERATE);
   if (!ok) {
     return NS_ERROR_FAILURE;
   }
 
 
   const size_t length = stacks.GetStackCount();
   for (size_t i = 0; i < length; ++i) {
-    if (!JS_SetElement(cx, durationArray, i, mHangReports.GetDuration(i))) {
+    if (!JS_DefineElement(cx, durationArray, i, mHangReports.GetDuration(i),
+                          JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
-    if (!JS_SetElement(cx, systemUptimeArray, i, mHangReports.GetSystemUptime(i))) {
+    if (!JS_DefineElement(cx, systemUptimeArray, i, mHangReports.GetSystemUptime(i),
+                          JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
-    if (!JS_SetElement(cx, firefoxUptimeArray, i, mHangReports.GetFirefoxUptime(i))) {
+    if (!JS_DefineElement(cx, firefoxUptimeArray, i, mHangReports.GetFirefoxUptime(i),
+                          JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
     const nsTArray<HangReports::AnnotationInfo>& annotationInfo =
                                                 mHangReports.GetAnnotationInfo();
     for (uint32_t iterIndex = 0, arrayLen = annotationInfo.Length();
          iterIndex < arrayLen; ++iterIndex) {
       JS::Rooted<JSObject*> keyValueArray(cx, JS_NewArrayObject(cx, 0));
       if (!keyValueArray) {
         return NS_ERROR_FAILURE;
       }
       JS::RootedValue indexValue(cx);
       indexValue.setNumber(annotationInfo[iterIndex].mHangIndex);
-      if (!JS_SetElement(cx, keyValueArray, 0, indexValue)) {
+      if (!JS_DefineElement(cx, keyValueArray, 0, indexValue, JSPROP_ENUMERATE)) {
         return NS_ERROR_FAILURE;
       }
       JS::Rooted<JSObject*> jsAnnotation(cx, JS_NewPlainObject(cx));
       if (!jsAnnotation) {
         return NS_ERROR_FAILURE;
       }
       nsAutoPtr<HangAnnotations::Enumerator> annotationsEnum;
       if (!annotationInfo[iterIndex].mAnnotations->GetEnumerator(
@@ -2559,21 +2562,21 @@ TelemetryImpl::GetChromeHangs(JSContext 
       while (annotationsEnum->Next(key, value)) {
         JS::RootedValue jsValue(cx);
         jsValue.setString(JS_NewUCStringCopyN(cx, value.get(), value.Length()));
         if (!JS_DefineUCProperty(cx, jsAnnotation, key.get(), key.Length(),
                                  jsValue, JSPROP_ENUMERATE)) {
           return NS_ERROR_FAILURE;
         }
       }
-      if (!JS_SetElement(cx, keyValueArray, 1, jsAnnotation)) {
+      if (!JS_DefineElement(cx, keyValueArray, 1, jsAnnotation, JSPROP_ENUMERATE)) {
         return NS_ERROR_FAILURE;
       }
-      if (!JS_SetElement(cx, annotationsArray, iterIndex,
-                         keyValueArray)) {
+      if (!JS_DefineElement(cx, annotationsArray, iterIndex,
+                         keyValueArray, JSPROP_ENUMERATE)) {
         return NS_ERROR_FAILURE;
       }
     }
   }
 
   return NS_OK;
 }
 
@@ -2599,37 +2602,38 @@ CreateJSStackObject(JSContext *cx, const
     // Current module
     const Telemetry::ProcessedStack::Module& module =
       stacks.GetModule(moduleIndex);
 
     JS::Rooted<JSObject*> moduleInfoArray(cx, JS_NewArrayObject(cx, 0));
     if (!moduleInfoArray) {
       return nullptr;
     }
-    if (!JS_SetElement(cx, moduleArray, moduleIndex, moduleInfoArray)) {
+    if (!JS_DefineElement(cx, moduleArray, moduleIndex, moduleInfoArray,
+                          JSPROP_ENUMERATE)) {
       return nullptr;
     }
 
     unsigned index = 0;
 
     // Module name
     JS::Rooted<JSString*> str(cx, JS_NewStringCopyZ(cx, module.mName.c_str()));
     if (!str) {
       return nullptr;
     }
-    if (!JS_SetElement(cx, moduleInfoArray, index++, str)) {
+    if (!JS_DefineElement(cx, moduleInfoArray, index++, str, JSPROP_ENUMERATE)) {
       return nullptr;
     }
 
     // Module breakpad identifier
     JS::Rooted<JSString*> id(cx, JS_NewStringCopyZ(cx, module.mBreakpadId.c_str()));
     if (!id) {
       return nullptr;
     }
-    if (!JS_SetElement(cx, moduleInfoArray, index++, id)) {
+    if (!JS_DefineElement(cx, moduleInfoArray, index++, id, JSPROP_ENUMERATE)) {
       return nullptr;
     }
   }
 
   JS::Rooted<JSObject*> reportArray(cx, JS_NewArrayObject(cx, 0));
   if (!reportArray) {
     return nullptr;
   }
@@ -2641,37 +2645,38 @@ 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));
     if (!pcArray) {
       return nullptr;
     }
 
-    if (!JS_SetElement(cx, reportArray, i, pcArray)) {
+    if (!JS_DefineElement(cx, reportArray, i, pcArray, JSPROP_ENUMERATE)) {
       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));
       if (!framePair) {
         return nullptr;
       }
       int modIndex = (std::numeric_limits<uint16_t>::max() == frame.mModIndex) ?
         -1 : frame.mModIndex;
-      if (!JS_SetElement(cx, framePair, 0, modIndex)) {
+      if (!JS_DefineElement(cx, framePair, 0, modIndex, JSPROP_ENUMERATE)) {
         return nullptr;
       }
-      if (!JS_SetElement(cx, framePair, 1, static_cast<double>(frame.mOffset))) {
+      if (!JS_DefineElement(cx, framePair, 1, static_cast<double>(frame.mOffset),
+                            JSPROP_ENUMERATE)) {
         return nullptr;
       }
-      if (!JS_SetElement(cx, pcArray, pcIndex, framePair)) {
+      if (!JS_DefineElement(cx, pcArray, pcIndex, framePair, JSPROP_ENUMERATE)) {
         return nullptr;
       }
     }
   }
 
   return ret;
 }
 
@@ -2794,23 +2799,24 @@ CreateJSTimeHistogram(JSContext* cx, con
     cx, JS_NewArrayObject(cx, ArrayLength(time) + 1));
   JS::RootedObject counts(
     cx, JS_NewArrayObject(cx, ArrayLength(time) + 1));
   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. */
-  if (!JS_SetElement(cx, ranges, 0, time.GetBucketMin(0)) ||
-      !JS_SetElement(cx, counts, 0, 0)) {
+  if (!JS_DefineElement(cx, ranges, 0, time.GetBucketMin(0), JSPROP_ENUMERATE) ||
+      !JS_DefineElement(cx, counts, 0, 0, JSPROP_ENUMERATE)) {
     return nullptr;
   }
   for (size_t i = 0; i < ArrayLength(time); i++) {
-    if (!JS_SetElement(cx, ranges, i + 1, time.GetBucketMax(i)) ||
-        !JS_SetElement(cx, counts, i + 1, time[i])) {
+    if (!JS_DefineElement(cx, ranges, i + 1, time.GetBucketMax(i),
+                          JSPROP_ENUMERATE) ||
+        !JS_DefineElement(cx, counts, i + 1, time[i], JSPROP_ENUMERATE)) {
       return nullptr;
     }
   }
   if (!JS_DefineProperty(cx, ret, "ranges", ranges, JSPROP_ENUMERATE) ||
       !JS_DefineProperty(cx, ret, "counts", counts, JSPROP_ENUMERATE)) {
     return nullptr;
   }
   return ret;
@@ -2820,17 +2826,17 @@ static JSObject*
 CreateJSHangStack(JSContext* cx, const Telemetry::HangStack& stack)
 {
   JS::RootedObject ret(cx, JS_NewArrayObject(cx, stack.length()));
   if (!ret) {
     return nullptr;
   }
   for (size_t i = 0; i < stack.length(); i++) {
     JS::RootedString string(cx, JS_NewStringCopyZ(cx, stack[i]));
-    if (!JS_SetElement(cx, ret, i, string)) {
+    if (!JS_DefineElement(cx, ret, i, string, JSPROP_ENUMERATE)) {
       return nullptr;
     }
   }
   return ret;
 }
 
 static JSObject*
 CreateJSHangHistogram(JSContext* cx, const Telemetry::HangHistogram& hang)
@@ -2880,17 +2886,17 @@ CreateJSThreadHangStats(JSContext* cx, c
   }
 
   JS::RootedObject hangs(cx, JS_NewArrayObject(cx, 0));
   if (!hangs) {
     return nullptr;
   }
   for (size_t i = 0; i < thread.mHangs.length(); i++) {
     JS::RootedObject obj(cx, CreateJSHangHistogram(cx, thread.mHangs[i]));
-    if (!JS_SetElement(cx, hangs, i, obj)) {
+    if (!JS_DefineElement(cx, hangs, i, obj, JSPROP_ENUMERATE)) {
       return nullptr;
     }
   }
   if (!JS_DefineProperty(cx, ret, "hangs", hangs, JSPROP_ENUMERATE)) {
     return nullptr;
   }
   return ret;
 }
@@ -2909,28 +2915,28 @@ 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));
-    if (!JS_SetElement(cx, retObj, threadIndex++, obj)) {
+    if (!JS_DefineElement(cx, retObj, threadIndex++, obj, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
   }
 #endif
 
   // Add saved threads next
   MutexAutoLock autoLock(mThreadHangStatsMutex);
   for (size_t i = 0; i < mThreadHangStats.length(); i++) {
     JS::RootedObject obj(cx,
       CreateJSThreadHangStats(cx, mThreadHangStats[i]));
-    if (!JS_SetElement(cx, retObj, threadIndex++, obj)) {
+    if (!JS_DefineElement(cx, retObj, threadIndex++, obj, JSPROP_ENUMERATE)) {
       return NS_ERROR_FAILURE;
     }
   }
   ret.setObject(*retObj);
   return NS_OK;
 }
 
 void