Bug 1365068 - Cleanup getListSuggestions. r=MattN
authorJonathan Guillotte-Blouin <jguillotteblouin@mozilla.com>
Mon, 15 May 2017 14:15:36 -0700
changeset 359770 c53adee3f113
parent 359769 52caa4cf1618
child 359771 7fcc4acd547f
push id31857
push userphilringnalda@gmail.com
push dateSun, 21 May 2017 20:00:29 +0000
treeherdermozilla-central@cf9f9525e4d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1365068
milestone55.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 1365068 - Cleanup getListSuggestions. r=MattN MozReview-Commit-ID: 2FVelDjB4pV
toolkit/components/satchel/nsInputListAutoComplete.js
--- a/toolkit/components/satchel/nsInputListAutoComplete.js
+++ b/toolkit/components/satchel/nsInputListAutoComplete.js
@@ -14,51 +14,50 @@ InputListAutoComplete.prototype = {
   classID: Components.ID("{bf1e01d0-953e-11df-981c-0800200c9a66}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIInputListAutoComplete]),
 
   autoCompleteSearch(aUntrimmedSearchString, aField) {
     let [values, labels] = this.getListSuggestions(aField);
     let searchResult = values.length > 0 ? Ci.nsIAutoCompleteResult.RESULT_SUCCESS
                                          : Ci.nsIAutoCompleteResult.RESULT_NOMATCH;
     let defaultIndex = values.length > 0 ? 0 : -1;
+
     return new FormAutoCompleteResult(aUntrimmedSearchString,
                                       searchResult, defaultIndex, "",
                                       values, labels, [], null);
   },
 
   getListSuggestions(aField) {
     let values = [];
     let labels = [];
+    if (!aField || !aField.list) {
+      return [values, labels];
+    }
 
-    if (aField) {
-      let filter = !aField.hasAttribute("mozNoFilter");
-      let lowerFieldValue = aField.value.toLowerCase();
+    let filter = !aField.hasAttribute("mozNoFilter");
+    let lowerFieldValue = aField.value.toLowerCase();
+    let options = aField.list.options;
 
-      if (aField.list) {
-        let options = aField.list.options;
-        let length = options.length;
-        for (let i = 0; i < length; i++) {
-          let item = options.item(i);
-          let label = "";
-          if (item.label) {
-            label = item.label;
-          } else if (item.text) {
-            label = item.text;
-          } else {
-            label = item.value;
-          }
+    for (let item of options) {
+      let label = "";
+      if (item.label) {
+        label = item.label;
+      } else if (item.text) {
+        label = item.text;
+      } else {
+        label = item.value;
+      }
 
-          if (filter && label.toLowerCase().indexOf(lowerFieldValue) == -1) {
-            continue;
-          }
+      if (filter && !label.toLowerCase().includes(lowerFieldValue)) {
+        continue;
+      }
 
-          labels.push(label);
-          values.push(item.value);
-        }
-      }
+      labels.push(label);
+      values.push(item.value);
     }
 
     return [values, labels];
+
   }
 };
 
 var component = [InputListAutoComplete];
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(component);