Bug 972331 - Use node.remove(), especially instead of node.parentNode.removeChild(node): /suite/browser/. r=Neil
authorSebastian Hengst <archaeopteryx@coole-files.de>
Wed, 19 Feb 2014 14:24:17 +0100
changeset 15572 56534fe2388d32b9b8e57f8ba515040770441b16
parent 15571 1b35ab70f951ed7ae6f0707419e9f5b7b840e2cd
child 15573 184a513a7379ec238c7b26edfc01efe7e401f468
push id1133
push usermbanner@mozilla.com
push dateMon, 28 Apr 2014 19:42:02 +0000
treeherdercomm-esr52@166a3e8cac27 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs972331
Bug 972331 - Use node.remove(), especially instead of node.parentNode.removeChild(node): /suite/browser/. r=Neil
suite/browser/linkToolbarItem.js
suite/browser/metadata.js
suite/browser/navigator.js
suite/browser/nsBrowserStatusHandler.js
suite/browser/pageinfo/pageInfo.js
suite/browser/pageinfo/security.js
suite/browser/sessionHistoryUI.js
suite/browser/tabbrowser.xml
suite/browser/test/browser/browser_bug427559.js
suite/browser/test/browser/browser_bug581947.js
suite/browser/test/browser/browser_popupNotification.js
suite/browser/urlbarBindings.xml
--- a/suite/browser/linkToolbarItem.js
+++ b/suite/browser/linkToolbarItem.js
@@ -93,17 +93,17 @@ function LinkToolbarMenu (linkType) {
   this.clear = function() {
     this.disableParentMenuButton();
     this.getXULElement().setAttribute("disabled", "true");
     clearPopup(this.getPopup());
   }
 
   function clearPopup(popup) {
     while (popup.hasChildNodes())
-      popup.removeChild(popup.lastChild);
+      popup.lastChild.remove();
   }
 
   this.getPopup = function() {
     return document.getElementById(this.xulPopupId);
   }
 
   this.displayLink = function(linkElement) {
     this.addMenuItem(linkElement);
@@ -195,18 +195,17 @@ function LinkToolbarTransientMenu (linkT
      *        to crash anymore.
      */
     this.getXULElement().setAttribute("collapsed", "true");
   }
 
   this.removeXULElement = function() {
     // XXX: stop using this method once it's safe to use hideXULElement
     if (this.__proto__.getXULElement.apply(this))
-      this.__proto__.getXULElement.apply(this).parentNode.removeChild(
-          this.__proto__.getXULElement.apply(this));
+      this.__proto__.getXULElement.apply(this).remove();
   }
 
   this.displayLink = function(linkElement) {
     if(!this.__proto__.displayLink.apply(this, [linkElement])) return false;
 
     this.getXULElement().removeAttribute("collapsed");
 
     // Show the 'miscellaneous' separator
--- a/suite/browser/metadata.js
+++ b/suite/browser/metadata.js
@@ -348,19 +348,17 @@ function setInfo(id, value)
 
     var node = document.getElementById(id+"-text");
 
     if (node.namespaceURI == XULNS && node.localName == "label" ||
        (node.namespaceURI == XULNS && node.localName == "textbox")) {
         node.setAttribute("value",value);
 
     } else if (node.namespaceURI == XULNS && node.localName == "description") {
-        while (node.hasChildNodes())
-            node.removeChild(node.firstChild);
-        node.appendChild(node.ownerDocument.createTextNode(value));
+        node.textContent = value;
     }
 }
 
 // Hide node with specified id
 function hideNode(id)
 {
     var style = document.getElementById(id).getAttribute("style");
     document.getElementById(id).setAttribute("style", "display:none;" + style);
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -270,18 +270,18 @@ function saveFrameDocument()
     saveDocument(focusedWindow.document, true);
 }
 
 function updateHomeButtonTooltip()
 {
   var homePage = getHomePage();
   var tooltip = document.getElementById("home-button-tooltip-inner");
 
-  while (tooltip.firstChild)
-    tooltip.removeChild(tooltip.firstChild);
+  while (tooltip.hasChildNodes())
+    tooltip.lastChild.remove();
 
   for (var i in homePage) {
     var label = document.createElementNS(XUL_NS, "label");
     label.setAttribute("value", homePage[i]);
     tooltip.appendChild(label);
   }
 }
 
@@ -973,18 +973,18 @@ function BrowserHandleShiftBackspace()
     case 1:
       goDoCommand("cmd_scrollPageDown");
       break;
   }
 }
 
 function SetGroupHistory(popupMenu, direction)
 {
-  while (popupMenu.firstChild)
-    popupMenu.removeChild(popupMenu.firstChild);
+  while (popupMenu.hasChildNodes())
+    popupMenu.lastChild.remove();
 
   var menuItem = document.createElementNS(XUL_NS, "menuitem");
   var label = gNavigatorBundle.getString("tabs.historyItem");
   menuItem.setAttribute("label", label);
   menuItem.setAttribute("index", direction);
   popupMenu.appendChild(menuItem);
 }
 
@@ -1428,17 +1428,17 @@ function updateRecentMenuItems()
   recentWindowsItem.setAttribute("disabled", ss.getClosedWindowCount() == 0);
 }
 
 function updateRecentTabs(menupopup)
 {
   var browser = getBrowser();
 
   while (menupopup.hasChildNodes())
-    menupopup.removeChild(menupopup.lastChild);
+    menupopup.lastChild.remove();
 
   var list = browser.getUndoList();
   for (var i = 0; i < list.length; i++) {
     var menuitem = document.createElement("menuitem");
     var label = list[i];
     if (i < 9) {
       label = gNavigatorBundle.getFormattedString("tabs.recentlyClosed.format", [i + 1, label]);
       menuitem.setAttribute("accesskey", i + 1);
@@ -1454,17 +1454,17 @@ function updateRecentTabs(menupopup)
 }
 
 function updateRecentWindows(menupopup)
 {
   var ss = Components.classes["@mozilla.org/suite/sessionstore;1"]
                      .getService(Components.interfaces.nsISessionStore);
 
   while (menupopup.hasChildNodes())
-    menupopup.removeChild(menupopup.lastChild);
+    menupopup.lastChild.remove();
 
   var undoItems = JSON.parse(ss.getClosedWindowData());
   for (var i = 0; i < undoItems.length; i++) {
     var menuitem = document.createElement("menuitem");
     var label = undoItems[i].title;
     if (i < 9) {
       label = gNavigatorBundle.getFormattedString("windows.recentlyClosed.format", [i + 1, label]);
       menuitem.setAttribute("accesskey", i + 1);
@@ -2054,17 +2054,17 @@ function stylesheetFillAll(menuPopup, fr
  * Populates the View > Use Style submenu with all available stylesheet sets
  * @param menuPopup The submenu's popup child
  */
 function stylesheetFillPopup(menuPopup)
 {
   /* Clear menu */
   var itemPersistentOnly = menuPopup.firstChild.nextSibling;
   while (itemPersistentOnly.nextSibling)
-    menuPopup.removeChild(itemPersistentOnly.nextSibling);
+    itemPersistentOnly.nextSibling.remove();
 
   /* Reset permanent items */
   var styleDisabled = getMarkupDocumentViewer().authorStyleDisabled;
   menuPopup.firstChild.setAttribute("checked", styleDisabled);
   itemPersistentOnly.setAttribute("checked", !styleDisabled);
   itemPersistentOnly.hidden = true;
 
   stylesheetFillAll(menuPopup, window.content, styleDisabled, itemPersistentOnly);
--- a/suite/browser/nsBrowserStatusHandler.js
+++ b/suite/browser/nsBrowserStatusHandler.js
@@ -133,18 +133,18 @@ nsBrowserStatusHandler.prototype =
            contentType == "application/javascript" ||
            contentType == "application/xml" ||
            contentType == "mozilla.application/cached-xul";
   },
 
   populateFeeds : function(popup)
   {
     // First clear out any old items
-    while (popup.firstChild)
-      popup.removeChild(popup.lastChild);
+    while (popup.hasChildNodes())
+      popup.lastChild.remove();
 
     for (var i = 0; i < this.feeds.length; i++) {
       var link = this.feeds[i];
       var menuitem = document.createElement("menuitem");
       menuitem.className = "menuitem-iconic bookmark-item";
       menuitem.statusText = link.href;
       menuitem.setAttribute("label", link.title || link.href);
       popup.appendChild(menuitem);
--- a/suite/browser/pageinfo/pageInfo.js
+++ b/suite/browser/pageinfo/pageInfo.js
@@ -384,17 +384,17 @@ function resetPageInfo(args)
   gFieldView.clear();
   gLinkView.clear();
   gImageView.clear();
   gImageHash = {};
 
   /* Reset Feeds Tab */
   var feedListbox = document.getElementById("feedListbox");
   while (feedListbox.hasChildNodes())
-    feedListbox.removeChild(feedListbox.lastChild);
+    feedListbox.lastChild.remove();
 
   /* Call registered overlay reset functions */
   onResetRegistry.forEach(function(func) { func(); });
 
   if (args && args.doc) {
     gDocument = args.doc;
     gWindow = gDocument.defaultView;
   }
@@ -1176,17 +1176,17 @@ function makePreview(row)
   if (width != physWidth || height != physHeight)
     physSize = gBundle.getFormattedString("mediaSize",
                                           [formatNumber(physWidth),
                                            formatNumber(physHeight)]);
   setItemValue("physSize", physSize);
 
   makeBlockImage(url);
 
-  imageContainer.removeChild(oldImage);
+  oldImage.remove();
   imageContainer.appendChild(newImage);
 }
 
 function makeBlockImage(url)
 {
   var checkbox = document.getElementById("blockImage");
   var imagePref = Services.prefs.getIntPref("permissions.default.image");
   if (!(/^https?:/.test(url)) || imagePref == 2)
--- a/suite/browser/pageinfo/security.js
+++ b/suite/browser/pageinfo/security.js
@@ -221,22 +221,18 @@ function securityOnLoad() {
 
 function setText(id, value)
 {
   var element = document.getElementById(id);
   if (!element)
     return;
   if (element.localName == "textbox" || element.localName == "label")
     element.value = value;
-  else {
-    if (element.hasChildNodes())
-      element.removeChild(element.firstChild);
-    var textNode = document.createTextNode(value);
-    element.appendChild(textNode);
-  }
+  else
+    element.textContent = value;
 }
 
 function viewCertHelper(parent, cert)
 {
   if (!cert)
     return;
 
   var cd = Components.classes[CERTIFICATEDIALOGS_CONTRACTID].getService(nsICertificateDialogs);
--- a/suite/browser/sessionHistoryUI.js
+++ b/suite/browser/sessionHistoryUI.js
@@ -94,17 +94,17 @@ function executeUrlBarHistoryCommand( aT
         UpdatePageProxyState();
         handleURLBarCommand();
       }
   }
 
 function createUBHistoryMenu( aParent )
   {
     while (aParent.hasChildNodes())
-      aParent.removeChild(aParent.lastChild);
+      aParent.lastChild.remove();
 
     var file = GetUrlbarHistoryFile();
     if (file.exists()) {
       var connection = Services.storage.openDatabase(file);
       try {
         if (connection.tableExists("urlbarhistory")) {
           var statement = connection.createStatement(
               "SELECT url FROM urlbarhistory ORDER BY ROWID DESC");
@@ -153,17 +153,17 @@ function createHistoryMenuItem(aParent, 
 }
 
 function deleteHistoryItems(aParent)
 {
   var children = aParent.childNodes;
   for (let i = children.length - 1; i >= 0; --i)
   {
     if (children[i].hasAttribute("index"))
-      aParent.removeChild(children[i]);
+      children[i].remove();
   }
 }
 
 function updateGoMenu(event)
   {
     FillHistoryMenu(event.target, "go");
     updateRecentMenuItems();
   }
--- a/suite/browser/tabbrowser.xml
+++ b/suite/browser/tabbrowser.xml
@@ -1703,17 +1703,17 @@
               this.mCurrentBrowser = null;
 
             // Invalidate browsers cache, as the tab is removed from the
             // tab container.
             this._browsers = null;
 
             // Clean up before/afterselected attributes before removing the tab
             aTab._selected = false;
-            this.tabContainer.removeChild(aTab);
+            aTab.remove();
 
             // When the current tab is removed select a new tab
             // and fire select events on tabpanels and tabs
             if (this.mPreviousTab && (aTab == this.mCurrentTab))
               this.selectedTab = this.mPreviousTab;
             else {
               this.tabContainer.selectedIndex = newIndex;
 
@@ -1735,17 +1735,17 @@
               // Because of the way XBL works (fields just set JS
               // properties on the element) and the code we have in place
               // to preserve the JS objects for any elements that have
               // JS properties set on them, the browser element won't be
               // destroyed until the document goes away.  So we force a
               // cleanup ourselves.
               oldBrowser.parentNode.destroy();
               oldBrowser.destroy();
-              this.mPanelContainer.removeChild(oldBrowser.parentNode);
+              oldBrowser.parentNode.remove();
 
               // Fix up the selected panel in the case the removed
               // browser was to the left of the current browser
               this.mTabBox.selectedPanel = this.selectedTab.linkedBrowser.parentNode;
               return;
             } 
 
             // preserve a pointer to the browser for undoing the close
@@ -1783,17 +1783,17 @@
               tabData = this.savedBrowsers.pop();
               var deadBrowser = tabData.browserData.browser;
               delete tabData.browserData;
               deadBrowser.parentNode.destroy();
               deadBrowser.destroy();
 
               // The pagehide event that this removal triggers is safe
               // because the browser is no longer current at this point
-              this.mPanelContainer.removeChild(deadBrowser.parentNode);
+              deadBrowser.parentNode.remove();
               this.mTabBox.selectedPanel = this.selectedTab.linkedBrowser.parentNode;
             }
           ]]>
         </body>
       </method>
 
       <method name="forgetSavedBrowser">
         <parameter name="aIndex"/>
@@ -1805,17 +1805,17 @@
             var tabData = this.savedBrowsers.splice(aIndex, 1)[0];
             var deadBrowser = tabData.browserData.browser;
             delete tabData.browserData;
             deadBrowser.parentNode.destroy();
             deadBrowser.destroy();
 
             // The pagehide event that this removal triggers is safe
             // because the browser is no longer current at this point
-            this.mPanelContainer.removeChild(deadBrowser.parentNode);
+            deadBrowser.parentNode.remove();
             this.mTabBox.selectedPanel = this.selectedTab.linkedBrowser.parentNode;
             return true;
           ]]>
         </body>
       </method>
 
       <method name="reloadAllTabs">
         <body>
@@ -2660,17 +2660,17 @@
               var tabData = this.savedBrowsers.pop();
               var deadBrowser = tabData.browserData.browser;
               delete tabData.browserData;
               deadBrowser.parentNode.destroy();
               deadBrowser.destroy();
 
               // The pagehide event that this removal triggers is safe
               // because the browser is no longer current at this point
-              this.mPanelContainer.removeChild(deadBrowser.parentNode);
+              deadBrowser.parentNode.remove();
               this.mTabBox.selectedPanel = this.selectedTab.linkedBrowser.parentNode;
             }
           ]]>
         </body>
       </method>
 
       <field name="_fastFind">null</field>
       <property name="fastFind" readonly="true">
@@ -3092,17 +3092,17 @@
            extends="chrome://global/content/bindings/popup.xml#popup">
     <implementation implements="nsIDOMEventListener">
       <method name="_tabOnTabClose">
         <parameter name="aEvent"/>
         <body>
           <![CDATA[
             let menuItem = aEvent.target.mCorrespondingMenuitem;
             if (menuItem)
-              this.removeChild(menuItem);
+              menuItem.remove();
           ]]>
         </body>
       </method>
 
       <method name="handleEvent">
         <parameter name="aEvent"/>
         <body>
           <![CDATA[
@@ -3206,17 +3206,17 @@
             document.removeBroadcastListenerFor(menuItem.tab, menuItem, "label");
             document.removeBroadcastListenerFor(menuItem.tab, menuItem, "crop");
             document.removeBroadcastListenerFor(menuItem.tab, menuItem, "image");
             document.removeBroadcastListenerFor(menuItem.tab, menuItem, "busy");
             document.removeBroadcastListenerFor(menuItem.tab, menuItem, "selected");
             menuItem.tab.removeEventListener("TabClose", this, false);
             menuItem.tab.mCorrespondingMenuitem = null;
             menuItem.tab = null;
-            this.removeChild(menuItem);
+            menuItem.remove();
           }
           let tabcontainer = document.getBindingParent(this);
           tabcontainer.mTabstrip.removeEventListener("scroll", this, false);
           document.getBindingParent(tabcontainer).removeEventListener("TabOpen", this, false);
         ]]>
       </handler>
 
       <handler event="command">
--- a/suite/browser/test/browser/browser_bug427559.js
+++ b/suite/browser/test/browser/browser_bug427559.js
@@ -4,17 +4,17 @@
 
 /*
  * Test bug 427559 to make sure focused elements that are no longer on the page
  * will have focus transferred to the window when changing tabs back to that
  * tab with the now-gone element.
  */
 
 // Default focus on a button and have it kill itself on blur
-let testPage = 'data:text/html,<body><button onblur="this.parentNode.removeChild(this);"><script>document.body.firstChild.focus();</script></body>';
+let testPage = 'data:text/html,<body><button onblur="this.remove();"><script>document.body.firstChild.focus();</script></body>';
 
 function test() {
   waitForExplicitFinish();
 
   gBrowser.selectedTab = gBrowser.addTab();
 
   gBrowser.selectedBrowser.addEventListener("load", function loadListener() {
     gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
--- a/suite/browser/test/browser/browser_bug581947.js
+++ b/suite/browser/test/browser/browser_bug581947.js
@@ -23,17 +23,17 @@ function check(aElementName, aBarred) {
       "No tooltip should be shown if the title attribute is set");
 
   e.removeAttribute('title');
   content.setAttribute('novalidate', '');
   ok (!FillInHTMLTooltip(e),
       "No tooltip should be shown if the novalidate attribute is set on the form owner");
   content.removeAttribute('novalidate');
 
-  content.removeChild(e);
+  e.remove();
 }
 
 function todo_check(aElementName, aBarred) {
   let doc = gBrowser.contentDocument;
   let tooltip = document.getElementById("aHTMLTooltip");
   let content = doc.getElementById('content');
 
   let e = doc.createElement(aElementName);
@@ -43,17 +43,17 @@ function todo_check(aElementName, aBarre
   try {
     e.setCustomValidity('foo');
   } catch (e) {
     caught = true;
   }
 
   todo(!caught, "setCustomValidity should exist for " + aElementName);
 
-  content.removeChild(e);
+  e.remove();
 }
 
 function test() {
   waitForExplicitFinish();
   gBrowser.selectedTab = gBrowser.addTab();
   gBrowser.selectedBrowser.addEventListener("load", function loadListener() {
     gBrowser.selectedBrowser.removeEventListener("load", loadListener, true);
 
--- a/suite/browser/test/browser/browser_popupNotification.js
+++ b/suite/browser/test/browser/browser_popupNotification.js
@@ -513,17 +513,17 @@ var tests = [
       EventUtils.synthesizeMouse(button, 1, 1, {});
     },
     onShown: function(popup) {
       checkPopup(popup, this.notifyObj);
       dismissNotification(popup);
     },
     onHidden: function(popup) {
       this.notification.remove();
-      this.box.parentNode.removeChild(this.box);
+      this.box.remove();
     }
   },
   // Test that popupnotifications without popups have anchor icons shown
   { // Test #16
     run: function() {
       let notifyObj = new basicNotification();
       notifyObj.anchorID = "geo-notification-icon";
       notifyObj.addOptions({neverShow: true});
--- a/suite/browser/urlbarBindings.xml
+++ b/suite/browser/urlbarBindings.xml
@@ -413,17 +413,17 @@
           box.setAttribute("engineIndex", this.childNodes.length);
           this.mSearchBox.appendChild(box);
         ]]></body>
       </method>
 
       <method name="clearEngines">
         <body><![CDATA[
           while (this.mSearchBox.hasChildNodes())
-            this.mSearchBox.removeChild(this.mSearchBox.lastChild);
+            this.mSearchBox.lastChild.remove();
         ]]></body>
       </method>
 
       <method name="updateEngines">
         <body><![CDATA[
           var defaultEngine = Services.search.defaultEngine;
           if (defaultEngine) {
             this.clearEngines();