Bug 1497814 - Clean up UrlbarInput getters and setters. r=Standard8
authorDão Gottwald <dao@mozilla.com>
Wed, 10 Oct 2018 10:18:59 +0000
changeset 496169 003208b2dd175a1ecd16a9a781011c115a3d7d06
parent 496168 61ad878d2f66d0b129b326a526e6dff46d839e94
child 496170 08d597127e937fbcb9f2929c6cd772ed93bfd7d9
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1497814
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 1497814 - Clean up UrlbarInput getters and setters. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D8188
browser/components/urlbar/UrlbarInput.jsm
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -45,57 +45,46 @@ class UrlbarInput {
     this.panel = options.panel;
     this.window = this.textbox.ownerGlobal;
     this.controller = options.controller || new UrlbarController();
     this.view = new UrlbarView(this);
     this.valueIsTyped = false;
     this.userInitiatedFocus = false;
     this.isPrivate = PrivateBrowsingUtils.isWindowPrivate(this.window);
 
+    // Forward textbox methods and properties.
     const METHODS = ["addEventListener", "removeEventListener",
       "setAttribute", "hasAttribute", "removeAttribute", "getAttribute",
       "focus", "blur", "select"];
-    const READ_ONLY_PROPERTIES = ["focused", "inputField", "editor"];
-    const READ_WRITE_PROPERTIES = ["value", "placeholder", "readOnly",
+    const READ_ONLY_PROPERTIES = ["inputField", "editor"];
+    const READ_WRITE_PROPERTIES = ["placeholder", "readOnly",
       "selectionStart", "selectionEnd"];
 
     for (let method of METHODS) {
       this[method] = (...args) => {
         this.textbox[method](...args);
       };
     }
 
     for (let property of READ_ONLY_PROPERTIES) {
       Object.defineProperty(this, property, {
         enumerable: true,
         get() {
-          let getter = "_get_" + property;
-          if (getter in this) {
-            return this[getter]();
-          }
           return this.textbox[property];
         },
       });
     }
 
     for (let property of READ_WRITE_PROPERTIES) {
       Object.defineProperty(this, property, {
         enumerable: true,
         get() {
-          let getter = "_get_" + property;
-          if (getter in this) {
-            return this[getter]();
-          }
           return this.textbox[property];
         },
         set(val) {
-          let setter = "_set_" + property;
-          if (setter in this) {
-            return this[setter](val);
-          }
           return this.textbox[property] = val;
         },
       });
     }
 
     XPCOMUtils.defineLazyGetter(this, "valueFormatter", () => {
       return new UrlbarValueFormatter(this);
     });
@@ -108,22 +97,25 @@ class UrlbarInput {
     this.inputField.addEventListener("overflow", this);
     this.inputField.addEventListener("underflow", this);
     this.inputField.addEventListener("scrollend", this);
     this.inputField.addEventListener("select", this);
 
     this.inputField.controllers.insertControllerAt(0, new CopyCutController(this));
   }
 
-  /* Shortens the given value, usually by removing http:// and trailing slashes,
+  /**
+   * Shortens the given value, usually by removing http:// and trailing slashes,
    * such that calling nsIURIFixup::createFixupURI with the result will produce
    * the same URI.
    *
    * @param {string} val
    *   The string to be trimmed if it appears to be URI
+   * @returns {string}
+   *   The trimmed string
    */
   trimValue(val) {
     return UrlbarPrefs.get("trimURLs") ? this.window.trimURL(val) : val;
   }
 
   /**
    * Applies styling to the text in the urlbar input, depending on the text.
    */
@@ -174,21 +166,25 @@ class UrlbarInput {
       this[methodName](event);
     } else {
       throw "Unrecognized urlbar event: " + event.type;
     }
   }
 
   // Getters and Setters below.
 
-  _get_focused() {
-    return this.inputField.getAttribute("focused") == "true";
+  get focused() {
+    return this.textbox.getAttribute("focused") == "true";
   }
 
-  _set_value(val) {
+  get value() {
+    return this.inputField.value;
+  }
+
+  set value(val) {
     val = this.trimValue(val);
 
     this.valueIsTyped = false;
     this.inputField.value = val;
     this.formatValue();
 
     return val;
   }