Bug 1347804 - Use Intl.Collator instead of nsICollation. r=pmorris CLOSED TREE
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 12 May 2020 20:12:57 +0300
changeset 39128 3a5d1ddae8c55710125c55a8c11e835dd3e5a52b
parent 39127 9667d3a0a37959dd7902ea2a21ff5915bc28c0d3
child 39129 5e8adf8205d5f51df3541feee756deb36c1b8386
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewerspmorris
bugs1347804
Bug 1347804 - Use Intl.Collator instead of nsICollation. r=pmorris CLOSED TREE Differential Revision: https://phabricator.services.mozilla.com/D71532
calendar/base/content/calendar-task-view.js
calendar/base/modules/utils/calL10NUtils.jsm
calendar/base/modules/utils/calPrintUtils.jsm
calendar/lightning/content/lightning-item-iframe.js
calendar/test/unit/test_l10n_utils.js
--- a/calendar/base/content/calendar-task-view.js
+++ b/calendar/base/content/calendar-task-view.js
@@ -308,18 +308,18 @@ var taskDetailsView = {
     let modified = false;
     let newIndex = categories.indexOf(category);
     if (newIndex > -1) {
       if (categoryList[newIndex].getAttribute("checked") != "true") {
         categoryList[newIndex].setAttribute("checked", "true");
         modified = true;
       }
     } else {
-      let localeCollator = cal.l10n.createLocaleCollator();
-      let compare = localeCollator.compareString.bind(localeCollator, 0);
+      const localeCollator = new Intl.Collator();
+      let compare = localeCollator.compare;
       newIndex = cal.data.binaryInsert(categories, category, compare, true);
 
       let item = document.getElementById("calendar-task-tree").currentTask;
       let maxCount = item.calendar.getProperty("capabilities.categories.maxCount");
 
       let menuitem = document.createXULElement("menuitem");
       menuitem.setAttribute("class", "menuitem-iconic calendar-category");
       menuitem.setAttribute("label", category);
--- a/calendar/base/modules/utils/calL10NUtils.jsm
+++ b/calendar/base/modules/utils/calL10NUtils.jsm
@@ -137,35 +137,24 @@ var call10n = {
       // Fall back to the default name format
       monthForm = "name";
     }
 
     return call10n.getDateFmtString(`month.${aMonthNum}.${monthForm}`);
   },
 
   /**
-   * Create a new locale collator
-   *
-   * @return {nsICollation}       A new locale collator
-   */
-  createLocaleCollator() {
-    return Cc["@mozilla.org/intl/collation-factory;1"]
-      .getService(Ci.nsICollationFactory)
-      .CreateCollation();
-  },
-
-  /**
    * Sort an array of strings in place, according to the current locale.
    *
    * @param {String[]} aStringArray   The strings to sort
    * @return {String[]}               The sorted strings, more specifically aStringArray
    */
   sortArrayByLocaleCollator(aStringArray) {
-    let collator = call10n.createLocaleCollator();
-    aStringArray.sort((a, b) => collator.compareString(0, a, b));
+    const collator = new Intl.Collator();
+    aStringArray.sort(collator.compare);
     return aStringArray;
   },
 
   /**
    * Provides locale dependent parameters for displaying calendar views
    *
    * @param {String} aLocale     The locale to get the info for, e.g. "en-US",
    *                               "de-DE" or null for the current locale
--- a/calendar/base/modules/utils/calPrintUtils.jsm
+++ b/calendar/base/modules/utils/calPrintUtils.jsm
@@ -100,22 +100,22 @@ var calprint = {
 
     // Fill in details of the task
     if (item.isCompleted) {
       taskNode.querySelector(".task-checkbox").setAttribute("checked", "checked");
     }
 
     taskNode.querySelector(".task-title").textContent = item.title;
 
-    let collator = cal.l10n.createLocaleCollator();
+    const collator = new Intl.Collator();
     cal.data.binaryInsertNode(
       taskContainer,
       taskNode,
       item,
-      (a, b) => collator.compareString(0, a, b),
+      collator.compare,
       node => node.item.title
     );
   },
 
   /**
    * Get time interval string for the given item. Returns an empty string for all-day items.
    *
    * @param aItem     The item providing the interval
--- a/calendar/lightning/content/lightning-item-iframe.js
+++ b/calendar/lightning/content/lightning-item-iframe.js
@@ -1038,18 +1038,18 @@ function categoryTextboxKeypress(event) 
 
   let categoryList = categoryPopup.querySelectorAll("menuitem.calendar-category");
   let categories = Array.from(categoryList, cat => cat.getAttribute("value"));
 
   let newIndex = categories.indexOf(category);
   if (newIndex > -1) {
     categoryList[newIndex].setAttribute("checked", true);
   } else {
-    let localeCollator = cal.l10n.createLocaleCollator();
-    let compare = localeCollator.compareString.bind(localeCollator, 0);
+    const localeCollator = new Intl.Collator();
+    let compare = localeCollator.compare;
     newIndex = cal.data.binaryInsert(categories, category, compare, true);
 
     let calendar = getCurrentCalendar();
     let maxCount = calendar.getProperty("capabilities.categories.maxCount");
 
     let item = document.createXULElement("menuitem");
     item.setAttribute("class", "menuitem-iconic calendar-category");
     item.setAttribute("label", category);
--- a/calendar/test/unit/test_l10n_utils.js
+++ b/calendar/test/unit/test_l10n_utils.js
@@ -11,17 +11,16 @@ function run_test() {
 // tests for calL10NUtils.jsm
 /* Incomplete - still missing test coverage for:
  * getAnyString
  * getString
  * getCalString
  * getLtnString
  * getDateFmtString
  * formatMonth
- * createLocaleCollator
  */
 
 add_task(async function calendarInfo_test() {
   let data = [
     {
       input: { locale: "en-US" },
       expected: {
         properties: [