Bug 1521097 - Bug 1480057 follow-up: Don't use .label when the XBL binding isn't attached yet. r=florian a=jorgk
authorJorg K <jorgk@jorgk.com>
Mon, 21 Jan 2019 10:52:10 +0100
changeset 33959 f3dbd71d275b
parent 33958 c2bb7687c4ba
child 33960 48b416ee9271
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersflorian, jorgk
bugs1521097, 1480057
Bug 1521097 - Bug 1480057 follow-up: Don't use .label when the XBL binding isn't attached yet. r=florian a=jorgk
mail/components/im/content/imconversation.xml
--- a/mail/components/im/content/imconversation.xml
+++ b/mail/components/im/content/imconversation.xml
@@ -1096,16 +1096,17 @@
          this.trackNick(name);
 
          let image = document.createElement("image");
          let label = document.createElement("label");
          label.setAttribute("value", name);
          label.setAttribute("flex", "1");
          label.setAttribute("crop", "end");
 
+         // Fix addNick below if you change the DOM makeup!
          var item = document.createElement("richlistitem");
          item.chatBuddy = aBuddy;
          item.appendChild(image);
          item.appendChild(label);
          this.setBuddyAttributes(item);
 
          var color = this._computeColor(name);
          var style = "color: hsl(" + color + ", 100%, 40%);";
@@ -1130,17 +1131,21 @@
          var nicklist = document.getElementById("nicklist");
          var nick = aListItem.querySelector("label").value.toLowerCase();
 
          // Look for the place of the nick in the list
          var start = 0;
          var end = nicklist.itemCount;
          while (start < end) {
            var middle = start + Math.floor((end - start) / 2);
-           if (nick < nicklist.getItemAtIndex(middle).label.toLowerCase())
+           // .firstChild.nextSibling gets us to the label. We can't use
+           // .label since the XBL binding might not be attached yet.
+           if (nick < nicklist.getItemAtIndex(middle)
+                              .firstChild.nextSibling
+                              .getAttribute("value").toLowerCase())
              end = middle;
            else
              start = middle + 1;
          }
 
          // Now insert the element
          if (end == nicklist.itemCount)
            nicklist.appendChild(aListItem);