Bug 1400665 - Add a explicit check for fieldDetail to avoid calling a method of "undefined". r=lchang
authorRay Lin <ralin@mozilla.com>
Tue, 19 Sep 2017 11:34:07 +0800
changeset 433812 9d2af29630cf63da091d907fc02d77ca9c9e5cfe
parent 433811 a182935e2bd40f64677c0add246ae2191391b780
child 433813 7bd14c0f640672f735af6aff9474e7185611ecfa
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslchang
bugs1400665
milestone57.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 1400665 - Add a explicit check for fieldDetail to avoid calling a method of "undefined". r=lchang MozReview-Commit-ID: EeYhje0b4c1
browser/extensions/formautofill/FormAutofillHandler.jsm
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -170,20 +170,27 @@ FormAutofillHandler.prototype = {
 
     return validDetails;
   },
 
   getFieldDetailByName(fieldName) {
     return this.fieldDetails.find(detail => detail.fieldName == fieldName);
   },
 
-  getFieldDetailsByElement(element) {
-    let fieldDetail = this.fieldDetails.find(
+  getFieldDetailByElement(element) {
+    return this.fieldDetails.find(
       detail => detail.elementWeakRef.get() == element
     );
+  },
+
+  getFieldDetailsByElement(element) {
+    let fieldDetail = this.getFieldDetailByElement(element);
+    if (!fieldDetail) {
+      return [];
+    }
     if (FormAutofillUtils.isAddressField(fieldDetail.fieldName)) {
       return this.address.fieldDetails;
     }
     if (FormAutofillUtils.isCreditCardField(fieldDetail.fieldName)) {
       return this.creditCard.fieldDetails;
     }
     return [];
   },