Bug 1497948: Ensure that enterprise policies are converted into a correct UTF-16 string that can be parsed by JS_ParseJSON on macOS. r=mstange
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Sat, 13 Oct 2018 18:52:35 -0400
changeset 499581 1f542a1a1b9892b3b963724e3252c74585107b92
parent 499580 410f1ce46d58faaa90983efe0805b798df57c43e
child 499582 c86bcd5caf4d56057444464298454ee861f14eaf
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1497948
milestone64.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 1497948: Ensure that enterprise policies are converted into a correct UTF-16 string that can be parsed by JS_ParseJSON on macOS. r=mstange
xpcom/base/nsMacPreferencesReader.mm
--- a/xpcom/base/nsMacPreferencesReader.mm
+++ b/xpcom/base/nsMacPreferencesReader.mm
@@ -9,21 +9,24 @@
 #include "nsISupportsPrimitives.h"
 
 NS_IMPL_ISUPPORTS(nsMacPreferencesReader, nsIMacPreferencesReader)
 
 using namespace mozilla;
 
 struct StringWriteFunc : public JSONWriteFunc
 {
-  nsCString& mCString;
-  explicit StringWriteFunc(nsCString& aCString) : mCString(aCString)
+  nsAString& mString;
+  explicit StringWriteFunc(nsAString& aStr) : mString(aStr)
   {
   }
-  void Write(const char* aStr) override { mCString.Append(aStr); }
+  void Write(const char* aStr) override
+  {
+    mString.Append(NS_ConvertUTF8toUTF16(aStr));
+  }
 };
 
 static void
 EvaluateDict(JSONWriter* aWriter, NSDictionary<NSString*, id>* aDict);
 
 static void
 EvaluateArray(JSONWriter* aWriter, NSArray* aArray)
 {
@@ -74,24 +77,23 @@ nsMacPreferencesReader::PoliciesEnabled(
                          boolForKey:policiesEnabledStr] == YES;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMacPreferencesReader::ReadPreferences(JSContext* aCx,
                                         JS::MutableHandle<JS::Value> aResult)
 {
-  nsAutoCString jsonStr;
+  nsAutoString jsonStr;
   JSONWriter w(MakeUnique<StringWriteFunc>(jsonStr));
   w.Start();
   EvaluateDict(&w, [[NSUserDefaults standardUserDefaults]
                      dictionaryRepresentation]);
   w.End();
 
-  NS_ConvertUTF8toUTF16 jsString(nsDependentCString(jsonStr.get()));
-  auto json = static_cast<const char16_t*>(jsString.get());
+  auto json = static_cast<const char16_t*>(jsonStr.get());
 
   JS::RootedValue val(aCx);
   MOZ_ALWAYS_TRUE(JS_ParseJSON(aCx, json, jsonStr.Length(), &val));
 
   aResult.set(val);
   return NS_OK;
 }