Bug 1094035 - Keyed Histograms do not reflect key strings to JS correctly. r=froydnj, a=lmandel
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 05 Nov 2014 18:58:36 +0100
changeset 225933 b94f02c9dc7d
parent 225932 4e78f69ca4a9
child 225934 04a5da64e518
push id4075
push usergeorg.fritzsche@googlemail.com
push date2014-11-05 21:23 +0000
treeherdermozilla-beta@b94f02c9dc7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, lmandel
bugs1094035
milestone34.0
Bug 1094035 - Keyed Histograms do not reflect key strings to JS correctly. r=froydnj, a=lmandel
toolkit/components/telemetry/Telemetry.cpp
toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -671,21 +671,20 @@ KeyedHistogram::Clear()
   mHistogramMap.Clear();
 }
 
 /* static */
 PLDHashOperator
 KeyedHistogram::ReflectKeys(KeyedHistogramEntry* entry, void* arg)
 {
   ReflectKeysArgs* args = static_cast<ReflectKeysArgs*>(arg);
-  const nsACString& key = entry->GetKey();
 
   JS::RootedValue jsKey(args->jsContext);
-  const nsCString& flat = nsPromiseFlatCString(key);
-  jsKey.setString(JS_NewStringCopyN(args->jsContext, flat.get(), flat.Length()));
+  const NS_ConvertUTF8toUTF16 key(entry->GetKey());
+  jsKey.setString(JS_NewUCStringCopyN(args->jsContext, key.Data(), key.Length()));
   args->vector->append(jsKey);
 
   return PL_DHASH_NEXT;
 }
 
 nsresult
 KeyedHistogram::GetJSKeys(JSContext* cx, JS::CallArgs& args)
 {
@@ -718,20 +717,19 @@ KeyedHistogram::ReflectKeyedHistogram(Ke
   if (!histogramSnapshot) {
     return false;
   }
 
   if (ReflectHistogramSnapshot(cx, histogramSnapshot, entry->mData) != REFLECT_OK) {
     return false;
   }
 
-  const nsACString& key = entry->GetKey();
-  const nsCString& flat = nsPromiseFlatCString(key);
-
-  if (!JS_DefineProperty(cx, obj, flat.get(), histogramSnapshot, JSPROP_ENUMERATE)) {
+  const NS_ConvertUTF8toUTF16 key(entry->GetKey());
+  if (!JS_DefineUCProperty(cx, obj, key.Data(), key.Length(),
+                           histogramSnapshot, JSPROP_ENUMERATE)) {
     return false;
   }
 
   return true;
 }
 
 nsresult
 KeyedHistogram::GetJSSnapshot(JSContext* cx, JS::Handle<JSObject*> obj)
--- a/toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
+++ b/toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
@@ -385,17 +385,18 @@ function numberRange(lower, upper)
     a.push(i);
   }
   return a;
 }
 
 function test_keyed_boolean_histogram()
 {
   const KEYED_ID = "test::keyed::boolean";
-  const KEYS = ["key"+(i+1) for (i of numberRange(0, 3))];
+  KEYS = ["key"+(i+1) for (i of numberRange(0, 2))];
+  KEYS.push("漢語");
   let histogramBase = {
     "min": 1,
     "max": 2,
     "histogram_type": 2,
     "sum": 1,
     "sum_squares_lo": 1,
     "sum_squares_hi": 0,
     "ranges": [0, 1, 2],