Bug 1323600 - Some fields have been converted to properties and won't reset anymore when the binding is recreated. r=Mossop draft
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 15 Dec 2016 00:58:21 +0100
changeset 449753 da4ac7a9dc6563236a4e64d9be64754ddcb2d142
parent 448260 8404d26166a35406f46ff237ed132735c98882b2
child 539564 167a18c8f908a404915824866f566e0add00eb01
push id38646
push usermak77@bonardo.net
push dateThu, 15 Dec 2016 00:02:46 +0000
reviewersMossop
bugs1323600
milestone53.0a1
Bug 1323600 - Some fields have been converted to properties and won't reset anymore when the binding is recreated. r=Mossop MozReview-Commit-ID: CHxBFpbW6aS
toolkit/content/widgets/autocomplete.xml
toolkit/content/widgets/tabbox.xml
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -64,41 +64,41 @@
       ]]></constructor>
 
       <destructor><![CDATA[
         this.inputField.controllers.removeController(this._pasteController);
       ]]></destructor>
 
       <!-- =================== nsIAutoCompleteInput =================== -->
 
+      <field name="_popup">null</field>
       <property name="popup" readonly="true">
         <getter><![CDATA[
+          // Memoize the result in a field rather than replacing this property,
+          // so that it can be reset along with the binding.
+          if (this._popup) {
+            return this._popup;
+          }
+
           let popup = null;
           let popupId = this.getAttribute("autocompletepopup");
           if (popupId) {
             popup = document.getElementById(popupId);
           }
           if (!popup) {
             popup = document.createElement("panel");
             popup.setAttribute("type", "autocomplete");
             popup.setAttribute("noautofocus", "true");
 
             let popupset = document.getAnonymousElementByAttribute(this, "anonid", "popupset");
             popupset.appendChild(popup);
           }
           popup.mInput = this;
 
-          // Avoid having to recalculate the popup property each time
-          Object.defineProperty(this, "popup", {
-            configurable: true,
-            enumerable: true,
-            writable: true,
-            value: popup
-          });
-          return popup;
+          return this._popup = popup;
         ]]></getter>
       </property>
 
       <property name="controller" onget="return this.mController;" readonly="true"/>
 
       <property name="popupOpen"
                 onget="return this.popup.popupOpen;"
                 onset="if (val) this.openPopup(); else this.closePopup();"/>
--- a/toolkit/content/widgets/tabbox.xml
+++ b/toolkit/content/widgets/tabbox.xml
@@ -344,34 +344,34 @@
                 break;
               }
             }
             return val;
           ]]>
         </setter>
       </property>
 
+      <field name="_tabbox">null</field>
       <property name="tabbox" readonly="true">
         <getter><![CDATA[
+          // Memoize the result in a field rather than replacing this property,
+          // so that it can be reset along with the binding.
+          if (this._tabbox) {
+            return this._tabbox;
+          }
+
           let parent = this.parentNode;
           while (parent) {
             if (parent.localName == "tabbox") {
               break;
             }
             parent = parent.parentNode;
           }
 
-          // Avoid having to recalculate the tabbox property each time
-          Object.defineProperty(this, "tabbox", {
-            configurable: true,
-            enumerable: true,
-            writable: true,
-            value: parent
-          });
-          return parent;
+          return this._tabbox = parent;
         ]]></getter>
       </property>
 
       <!-- _tabbox is deprecated, it exists only for backwards compatibility. -->
       <field name="_tabbox" readonly="true"><![CDATA[
         this.tabbox;
       ]]></field>
 
@@ -639,34 +639,34 @@
           }
 
           return tabElmFromIndex;
         ]]>
         </body>
       </method>
 
       <!-- public -->
+      <field name="_tabbox">null</field>
       <property name="tabbox" readonly="true">
         <getter><![CDATA[
+          // Memoize the result in a field rather than replacing this property,
+          // so that it can be reset along with the binding.
+          if (this._tabbox) {
+            return this._tabbox;
+          }
+
           let parent = this.parentNode;
           while (parent) {
             if (parent.localName == "tabbox") {
               break;
             }
             parent = parent.parentNode;
           }
 
-          // Avoid having to recalculate the tabbox property each time
-          Object.defineProperty(this, "tabbox", {
-            configurable: true,
-            enumerable: true,
-            writable: true,
-            value: parent
-          });
-          return parent;
+          return this._tabbox = parent;
         ]]></getter>
       </property>
 
       <field name="_selectedPanel">this.childNodes.item(this.selectedIndex)</field>
 
       <property name="selectedIndex">
         <getter>
         <![CDATA[