Back out e9c07d92a4a4 (bug 719295) for orange
authorPhil Ringnalda <philringnalda@gmail.com>
Thu, 01 Mar 2012 20:36:59 -0800
changeset 89646 1c238e6cf7a18516ad68accbbae5abebb3ff6fe3
parent 89645 f7a0d7946225016300945e05d6c92ee7e226efec
child 89647 c30b6943dc98e8b2d24f76fba20764eefbfb109a
push id975
push userffxbld
push dateTue, 13 Mar 2012 21:39:16 +0000
treeherdermozilla-aurora@99faebf9dc36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs719295
milestone13.0a1
backs oute9c07d92a4a4717ac78b36a61cef3bfa44d73f7e
Back out e9c07d92a4a4 (bug 719295) for orange
toolkit/components/telemetry/Telemetry.cpp
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -313,51 +313,36 @@ enum reflectStatus
 ReflectHistogramAndSamples(JSContext *cx, JSObject *obj, Histogram *h,
                            const Histogram::SampleSet &ss)
 {
   // We don't want to reflect corrupt histograms.
   if (h->FindCorruption(ss) != Histogram::NO_INCONSISTENCIES) {
     return REFLECT_CORRUPT;
   }
 
-  if (!JS_DefineProperty(cx, obj, "min", INT_TO_JSVAL(h->declared_min()), NULL, NULL, JSPROP_ENUMERATE)
-      && JS_DefineProperty(cx, obj, "max", INT_TO_JSVAL(h->declared_max()), NULL, NULL, JSPROP_ENUMERATE)
-      && JS_DefineProperty(cx, obj, "histogram_type", INT_TO_JSVAL(h->histogram_type()), NULL, NULL, JSPROP_ENUMERATE)
-      && JS_DefineProperty(cx, obj, "sum", DOUBLE_TO_JSVAL(ss.sum()), NULL, NULL, JSPROP_ENUMERATE)) {
-    return REFLECT_FAILURE;
-  }
-
+  JSObject *counts_array;
+  JSObject *rarray;
   const size_t count = h->bucket_count();
-  JSObject *rarray = JS_NewArrayObject(cx, count, nsnull);
-  if (!rarray) {
-    return REFLECT_FAILURE;
-  }
-  JS::AutoObjectRooter aroot(cx, rarray);
-  if (!(FillRanges(cx, rarray, h)
-        && JS_DefineProperty(cx, obj, "ranges", OBJECT_TO_JSVAL(rarray),
-                             NULL, NULL, JSPROP_ENUMERATE))) {
-    return REFLECT_FAILURE;
-  }
-
-  JSObject *counts_array = JS_NewArrayObject(cx, count, NULL);
-  if (!counts_array) {
-    return REFLECT_FAILURE;
-  }
-  JS::AutoObjectRooter croot(cx, counts_array);
-  if (!JS_DefineProperty(cx, obj, "counts", OBJECT_TO_JSVAL(counts_array),
-                         NULL, NULL, JSPROP_ENUMERATE)) {
+  if (!(JS_DefineProperty(cx, obj, "min", INT_TO_JSVAL(h->declared_min()), NULL, NULL, JSPROP_ENUMERATE)
+        && JS_DefineProperty(cx, obj, "max", INT_TO_JSVAL(h->declared_max()), NULL, NULL, JSPROP_ENUMERATE)
+        && JS_DefineProperty(cx, obj, "histogram_type", INT_TO_JSVAL(h->histogram_type()), NULL, NULL, JSPROP_ENUMERATE)
+        && JS_DefineProperty(cx, obj, "sum", DOUBLE_TO_JSVAL(ss.sum()), NULL, NULL, JSPROP_ENUMERATE)
+        && (rarray = JS_NewArrayObject(cx, count, NULL))
+        && JS_DefineProperty(cx, obj, "ranges", OBJECT_TO_JSVAL(rarray), NULL, NULL, JSPROP_ENUMERATE)
+        && FillRanges(cx, rarray, h)
+        && (counts_array = JS_NewArrayObject(cx, count, NULL))
+        && JS_DefineProperty(cx, obj, "counts", OBJECT_TO_JSVAL(counts_array), NULL, NULL, JSPROP_ENUMERATE)
+        )) {
     return REFLECT_FAILURE;
   }
   for (size_t i = 0; i < count; i++) {
-    if (!JS_DefineElement(cx, counts_array, i, INT_TO_JSVAL(ss.counts(i)),
-                          NULL, NULL, JSPROP_ENUMERATE)) {
+    if (!JS_DefineElement(cx, counts_array, i, INT_TO_JSVAL(ss.counts(i)), NULL, NULL, JSPROP_ENUMERATE)) {
       return REFLECT_FAILURE;
     }
   }
- 
   return REFLECT_OK;
 }
 
 enum reflectStatus
 ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
 {
   Histogram::SampleSet ss;
   h->SnapshotSample(&ss);
@@ -403,20 +388,19 @@ JSBool
 JSHistogram_Snapshot(JSContext *cx, unsigned argc, jsval *vp)
 {
   JSObject *obj = JS_THIS_OBJECT(cx, vp);
   if (!obj) {
     return JS_FALSE;
   }
 
   Histogram *h = static_cast<Histogram*>(JS_GetPrivate(obj));
-  JSObject *snapshot = JS_NewObject(cx, nsnull, nsnull, nsnull);
+  JSObject *snapshot = JS_NewObject(cx, NULL, NULL, NULL);
   if (!snapshot)
     return JS_FALSE;
-  JS::AutoObjectRooter sroot(cx, snapshot);
 
   switch (ReflectHistogramSnapshot(cx, snapshot, h)) {
   case REFLECT_FAILURE:
     return JS_FALSE;
   case REFLECT_CORRUPT:
     JS_ReportError(cx, "Histogram is corrupt");
     return JS_FALSE;
   case REFLECT_OK:
@@ -437,24 +421,20 @@ WrapAndReturnHistogram(Histogram *h, JSC
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
     JSCLASS_NO_OPTIONAL_MEMBERS
   };
 
   JSObject *obj = JS_NewObject(cx, &JSHistogram_class, NULL, NULL);
   if (!obj)
     return NS_ERROR_FAILURE;
-  JS::AutoObjectRooter root(cx, obj);
-  if (!(JS_DefineFunction (cx, obj, "add", JSHistogram_Add, 1, 0)
-        && JS_DefineFunction (cx, obj, "snapshot", JSHistogram_Snapshot, 1, 0))) {
-    return NS_ERROR_FAILURE;
-  }
   *ret = OBJECT_TO_JSVAL(obj);
   JS_SetPrivate(obj, h);
-  return NS_OK;
+  return (JS_DefineFunction (cx, obj, "add", JSHistogram_Add, 1, 0)
+          && JS_DefineFunction (cx, obj, "snapshot", JSHistogram_Snapshot, 1, 0)) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 TelemetryImpl::TelemetryImpl():
 mHistogramMap(Telemetry::HistogramCount),
 mCanRecord(XRE_GetProcessType() == GeckoProcessType_Default),
 mHashMutex("Telemetry::mHashMutex")
 {
   // A whitelist to prevent Telemetry reporting on Addon & Thunderbird DBs
@@ -494,47 +474,43 @@ bool
 TelemetryImpl::StatementReflector(SlowSQLEntryType *entry, JSContext *cx,
                                   JSObject *obj)
 {
   const nsACString &sql = entry->GetKey();
   jsval hitCount = UINT_TO_JSVAL(entry->mData.hitCount);
   jsval totalTime = UINT_TO_JSVAL(entry->mData.totalTime);
 
   JSObject *arrayObj = JS_NewArrayObject(cx, 2, nsnull);
-  if (!arrayObj) {
-    return false;
-  }
-  JS::AutoObjectRooter root(cx, arrayObj);
-  return (JS_SetElement(cx, arrayObj, 0, &hitCount)
+  return (arrayObj
+          && JS_SetElement(cx, arrayObj, 0, &hitCount)
           && JS_SetElement(cx, arrayObj, 1, &totalTime)
           && JS_DefineProperty(cx, obj,
                                sql.BeginReading(),
                                OBJECT_TO_JSVAL(arrayObj),
                                NULL, NULL, JSPROP_ENUMERATE));
 }
 
 bool
 TelemetryImpl::AddSQLInfo(JSContext *cx, JSObject *rootObj, bool mainThread)
 {
   JSObject *statsObj = JS_NewObject(cx, NULL, NULL, NULL);
   if (!statsObj)
     return false;
-  JS::AutoObjectRooter root(cx, statsObj);
+
+  JSBool ok = JS_DefineProperty(cx, rootObj,
+                                mainThread ? "mainThread" : "otherThreads",
+                                OBJECT_TO_JSVAL(statsObj),
+                                NULL, NULL, JSPROP_ENUMERATE);
+  if (!ok)
+    return false;
 
   AutoHashtable<SlowSQLEntryType> &sqlMap = (mainThread
                                              ? mSlowSQLOnMainThread
                                              : mSlowSQLOnOtherThread);
-  if (!sqlMap.ReflectHashtable(StatementReflector, cx, statsObj)) {
-    return false;
-  }
-
-  return JS_DefineProperty(cx, rootObj,
-                           mainThread ? "mainThread" : "otherThreads",
-                           OBJECT_TO_JSVAL(statsObj),
-                           NULL, NULL, JSPROP_ENUMERATE);
+  return sqlMap.ReflectHashtable(StatementReflector, cx, statsObj);
 }
 
 nsresult
 TelemetryImpl::GetHistogramEnumId(const char *name, Telemetry::ID *id)
 {
   if (!sTelemetry) {
     return NS_ERROR_FAILURE;
   }
@@ -797,17 +773,16 @@ TelemetryImpl::GetHistogramSnapshots(JSC
     if (!ShouldReflectHistogram(h)) {
       continue;
     }
 
     JSObject *hobj = JS_NewObject(cx, NULL, NULL, NULL);
     if (!hobj) {
       return NS_ERROR_FAILURE;
     }
-    JS::AutoObjectRooter root(cx, hobj);
     switch (ReflectHistogramSnapshot(cx, hobj, h)) {
     case REFLECT_CORRUPT:
       // We can still hit this case even if ShouldReflectHistograms
       // returns true.  The histogram lies outside of our control
       // somehow; just skip it.
       continue;
     case REFLECT_FAILURE:
       return NS_ERROR_FAILURE;
@@ -826,21 +801,17 @@ TelemetryImpl::AddonHistogramReflector(A
                                        JSContext *cx, JSObject *obj)
 {
   // Never even accessed the histogram.
   if (!entry->mData.h) {
     return true;
   }
 
   JSObject *snapshot = JS_NewObject(cx, NULL, NULL, NULL);
-  if (!snapshot) {
-    // Just consider this to be skippable.
-    return true;
-  }
-  JS::AutoObjectRooter r(cx, snapshot);
+  js::AutoObjectRooter r(cx, snapshot);
   switch (ReflectHistogramSnapshot(cx, snapshot, entry->mData.h)) {
   case REFLECT_FAILURE:
   case REFLECT_CORRUPT:
     return false;
   case REFLECT_OK:
     const nsACString &histogramName = entry->GetKey();
     if (!JS_DefineProperty(cx, obj,
                            PromiseFlatCString(histogramName).get(),
@@ -857,17 +828,17 @@ bool
 TelemetryImpl::AddonReflector(AddonEntryType *entry,
                               JSContext *cx, JSObject *obj)
 {
   const nsACString &addonId = entry->GetKey();
   JSObject *subobj = JS_NewObject(cx, NULL, NULL, NULL);
   if (!subobj) {
     return false;
   }
-  JS::AutoObjectRooter r(cx, subobj);
+  js::AutoObjectRooter r(cx, subobj);
 
   AddonHistogramMapType *map = entry->mData;
   if (!(map->ReflectHashtable(AddonHistogramReflector, cx, subobj)
         && JS_DefineProperty(cx, obj,
                              PromiseFlatCString(addonId).get(),
                              OBJECT_TO_JSVAL(subobj), NULL, NULL,
                              JSPROP_ENUMERATE))) {
     return false;
@@ -878,17 +849,17 @@ TelemetryImpl::AddonReflector(AddonEntry
 NS_IMETHODIMP
 TelemetryImpl::GetAddonHistogramSnapshots(JSContext *cx, jsval *ret)
 {
   *ret = JSVAL_VOID;
   JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
   if (!obj) {
     return NS_ERROR_FAILURE;
   }
-  JS::AutoObjectRooter r(cx, obj);
+  js::AutoObjectRooter r(cx, obj);
 
   if (!mAddonMap.ReflectHashtable(AddonReflector, cx, obj)) {
     return NS_ERROR_FAILURE;
   }
   *ret = OBJECT_TO_JSVAL(obj);
   return NS_OK;
 }
 
@@ -913,17 +884,16 @@ TelemetryImpl::GetSlowSQL(JSContext *cx,
 
 NS_IMETHODIMP
 TelemetryImpl::GetRegisteredHistograms(JSContext *cx, jsval *ret)
 {
   size_t count = ArrayLength(gHistograms);
   JSObject *info = JS_NewObject(cx, NULL, NULL, NULL);
   if (!info)
     return NS_ERROR_FAILURE;
-  JS::AutoObjectRooter root(cx, info);
 
   for (size_t i = 0; i < count; ++i) {
     JSString *comment = JS_InternString(cx, gHistograms[i].comment);
     
     if (!(comment
           && JS_DefineProperty(cx, info, gHistograms[i].id,
                                STRING_TO_JSVAL(comment), NULL, NULL,
                                JSPROP_ENUMERATE))) {
@@ -1008,32 +978,32 @@ TelemetrySessionData::SampleReflector(En
   if (NS_FAILED(rv)) {
     return true;
   }
 
   JSObject *snapshot = JS_NewObject(cx, NULL, NULL, NULL);
   if (!snapshot) {
     return false;
   }
-  JS::AutoObjectRooter root(cx, snapshot);
+  js::AutoObjectRooter root(cx, snapshot);
   return (ReflectHistogramAndSamples(cx, snapshot, h, entry->mData)
           && JS_DefineProperty(cx, snapshots,
                                h->histogram_name().c_str(),
                                OBJECT_TO_JSVAL(snapshot), NULL, NULL,
                                JSPROP_ENUMERATE));
 }
 
 NS_IMETHODIMP
 TelemetrySessionData::GetSnapshots(JSContext *cx, jsval *ret)
 {
   JSObject *snapshots = JS_NewObject(cx, NULL, NULL, NULL);
   if (!snapshots) {
     return NS_ERROR_FAILURE;
   }
-  JS::AutoObjectRooter root(cx, snapshots);
+  js::AutoObjectRooter root(cx, snapshots);
 
   if (!mSampleSetMap.ReflectHashtable(SampleReflector, cx, snapshots)) {
     return NS_ERROR_FAILURE;
   }
 
   *ret = OBJECT_TO_JSVAL(snapshots);
   return NS_OK;
 }