Bug 1271032 - Make getPref Unicode-aware. r=mkaply, a=ritu
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Tue, 10 May 2016 19:45:22 +0900
changeset 326253 168613131e6a01c065897186ba2e91c3a9de3798
parent 326252 2d928f3ea42b9835ba503e350213eef684af8980
child 326254 93a53170dedffdff45bf9eb8dac6e5ef7a13c4ba
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkaply, ritu
bugs1271032
milestone47.0
Bug 1271032 - Make getPref Unicode-aware. r=mkaply, a=ritu
extensions/pref/autoconfig/src/prefcalls.js
extensions/pref/autoconfig/test/unit/autoconfig-latin1.cfg
extensions/pref/autoconfig/test/unit/autoconfig-utf8.cfg
extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
--- a/extensions/pref/autoconfig/src/prefcalls.js
+++ b/extensions/pref/autoconfig/src/prefcalls.js
@@ -109,16 +109,22 @@ function unlockPref(prefName) {
 function getPref(prefName) {
     
     try {
         var prefBranch = getPrefBranch();
         
         switch (prefBranch.getPrefType(prefName)) {
             
         case prefBranch.PREF_STRING:
+            if (gIsUTF8) {
+                const nsISupportsString = Components.interfaces.nsISupportsString;
+                let string = Components.classes["@mozilla.org/supports-string;1"]
+                                       .createInstance(nsISupportsString);
+                return prefBranch.getComplexValue(prefName, nsISupportsString).data;
+            }
             return prefBranch.getCharPref(prefName);
             
         case prefBranch.PREF_INT:
             return prefBranch.getIntPref(prefName);
             
         case prefBranch.PREF_BOOL:
             return prefBranch.getBoolPref(prefName);
         default:
--- a/extensions/pref/autoconfig/test/unit/autoconfig-latin1.cfg
+++ b/extensions/pref/autoconfig/test/unit/autoconfig-latin1.cfg
@@ -1,5 +1,6 @@
 // # don't remove this comment! (the first line is ignored by Mozilla)
 // 
 lockPref("_test.string.ASCII", "ASCII");
 lockPref("_test.string.non-ASCII", "日本語");
+lockPref("_test.string.getPref", getPref("_test.string.non-ASCII"));
 lockPref("_test.string.gIsUTF8", String(this.gIsUTF8));
--- a/extensions/pref/autoconfig/test/unit/autoconfig-utf8.cfg
+++ b/extensions/pref/autoconfig/test/unit/autoconfig-utf8.cfg
@@ -1,5 +1,6 @@
 // # don't remove this comment! (the first line is ignored by Mozilla)
 
 lockPref("_test.string.ASCII", "UTF-8");
 lockPref("_test.string.non-ASCII", "日本語");
+lockPref("_test.string.getPref", getPref("_test.string.non-ASCII"));
 lockPref("_test.string.gIsUTF8", String(this.gIsUTF8));
--- a/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
+++ b/extensions/pref/autoconfig/test/unit/test_autoconfig_nonascii.js
@@ -26,23 +26,25 @@ function run_test() {
     Cc["@mozilla.org/readconfig;1"].getService(Ci.nsISupports);
     ps.resetPrefs();
 
     var tests = [{
       filename: "autoconfig-utf8.cfg",
       prefs: {
         "_test.string.ASCII": "UTF-8",
         "_test.string.non-ASCII": "日本語",
+        "_test.string.getPref": "日本語",
         "_test.string.gIsUTF8": "true"
       }
     }, {
       filename: "autoconfig-latin1.cfg",
       prefs: {
         "_test.string.ASCII": "ASCII",
         "_test.string.non-ASCII": "日本語",
+        "_test.string.getPref": "日本語",
         "_test.string.gIsUTF8": "false",
       }
     }];
 
     function testAutoConfig(test) {
       // Make sure pref values are unset.
       for (let prefName in test.prefs) {
         do_check_eq(Ci.nsIPrefBranch.PREF_INVALID, prefs.getPrefType(prefName));