From 1c7a6361be740dd402aa07be11a1b9bb797719de Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 15 Apr 2004 22:14:39 +0000 Subject: [PATCH] Make nsXULElement::GetChildNodes use the same (live) node list that nsGenericElement uses. Bug 240633, r+sr=jst on the C++ changes, r=neil, sr=jst on the JS changes. git-svn-id: svn://10.0.0.236/trunk@154950 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/browser/base/content/browser.js | 2 +- mozilla/content/xul/content/src/Makefile.in | 1 - .../xul/content/src/nsRDFDOMNodeList.cpp | 133 ------------------ .../xul/content/src/nsRDFDOMNodeList.h | 68 --------- .../content/xul/content/src/nsXULElement.cpp | 36 ++--- .../content/xul/content/src/nsXULElement.h | 3 +- .../xul/document/src/nsXULDocument.cpp | 1 - .../editor/libeditor/base/DeleteRangeTxn.cpp | 2 + mozilla/editor/ui/composer/content/editor.js | 5 +- .../editor/ui/dialogs/content/EdInsertTOC.js | 5 +- .../content/jsutil/xul/inTreeBuilder.js | 4 +- .../content/viewers/jsObject/jsObject.js | 5 +- .../viewers/xblBindings/xblBindings.js | 5 +- .../p3p/resources/content/p3pSummary.js | 6 + .../mail/base/content/msgHdrViewOverlay.js | 4 +- .../addrbook/content/abCardViewOverlay.js | 6 +- .../compose/content/MsgComposeCommands.js | 8 +- .../prefs/resources/content/pref-directory.js | 4 +- .../resources/content/abCardViewOverlay.js | 6 +- .../resources/content/MsgComposeCommands.js | 8 +- .../import/resources/content/importDialog.js | 8 +- .../toolkit/components/help/content/help.js | 2 +- .../resources/content/sessionHistoryUI.js | 2 +- .../resources/content/urlbarBindings.xml | 5 +- .../components/search/resources/shared.js | 24 ++-- 25 files changed, 71 insertions(+), 282 deletions(-) delete mode 100644 mozilla/content/xul/content/src/nsRDFDOMNodeList.cpp delete mode 100644 mozilla/content/xul/content/src/nsRDFDOMNodeList.h diff --git a/mozilla/browser/base/content/browser.js b/mozilla/browser/base/content/browser.js index d10b0e148f9..6399d1ea462 100644 --- a/mozilla/browser/base/content/browser.js +++ b/mozilla/browser/base/content/browser.js @@ -1962,7 +1962,7 @@ function createRadioMenuItem( aParent, aIndex, aLabel, aChecked) function deleteHistoryItems(aParent) { var children = aParent.childNodes; - for (var i = 0; i < children.length; i++) + for (var i = children.length - 1; i >= 0; --i) { var index = children[i].getAttribute("index"); if (index) diff --git a/mozilla/content/xul/content/src/Makefile.in b/mozilla/content/xul/content/src/Makefile.in index 00d97add8f9..e874bab907b 100644 --- a/mozilla/content/xul/content/src/Makefile.in +++ b/mozilla/content/xul/content/src/Makefile.in @@ -51,7 +51,6 @@ REQUIRES = xpcom \ $(NULL) CPPSRCS = \ - nsRDFDOMNodeList.cpp \ nsXULElement.cpp \ nsXULPopupListener.cpp \ $(NULL) diff --git a/mozilla/content/xul/content/src/nsRDFDOMNodeList.cpp b/mozilla/content/xul/content/src/nsRDFDOMNodeList.cpp deleted file mode 100644 index 1dfce979282..00000000000 --- a/mozilla/content/xul/content/src/nsRDFDOMNodeList.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - - Helper class to implement the nsIDOMNodeList interface. - - XXX It's probably wrong in some sense, as it uses the "naked" - content interface to look for kids. (I assume in general this is - bad because there may be pseudo-elements created for presentation - that aren't visible to the DOM.) - -*/ - -#include "nsIDOMNode.h" -#include "nsRDFDOMNodeList.h" -#include "nsContentUtils.h" - -//////////////////////////////////////////////////////////////////////// -// ctors & dtors - - -nsRDFDOMNodeList::nsRDFDOMNodeList(void) -{ -} - -nsRDFDOMNodeList::~nsRDFDOMNodeList(void) -{ -} - -//////////////////////////////////////////////////////////////////////// -// nsISupports interface - - -// QueryInterface implementation for nsRDFDOMNodeList -NS_INTERFACE_MAP_BEGIN(nsRDFDOMNodeList) - NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList) - NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULNodeList) -NS_INTERFACE_MAP_END - - -NS_IMPL_ADDREF(nsRDFDOMNodeList) -NS_IMPL_RELEASE(nsRDFDOMNodeList) - - -//////////////////////////////////////////////////////////////////////// -// nsIDOMNodeList interface - -NS_IMETHODIMP -nsRDFDOMNodeList::GetLength(PRUint32* aLength) -{ - NS_ASSERTION(aLength != nsnull, "null ptr"); - if (! aLength) - return NS_ERROR_NULL_POINTER; - - *aLength = mElements.Count(); - return NS_OK; -} - - -NS_IMETHODIMP -nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) -{ - if (aIndex >= (PRUint32) mElements.Count()) { - // We simply return nsnull, as per the DOM spec. - *aReturn = nsnull; - return NS_OK; - } - - NS_ADDREF(*aReturn = mElements[aIndex]); - return NS_OK; -} - - -//////////////////////////////////////////////////////////////////////// -// Implementation methods - -nsresult -nsRDFDOMNodeList::AppendNode(nsIDOMNode* aNode) -{ - NS_PRECONDITION(aNode != nsnull, "null ptr"); - if (! aNode) - return NS_ERROR_NULL_POINTER; - - return mElements.AppendObject(aNode); -} - -nsresult -nsRDFDOMNodeList::RemoveNode(nsIDOMNode* aNode) -{ - NS_PRECONDITION(aNode != nsnull, "null ptr"); - if (! aNode) - return NS_ERROR_NULL_POINTER; - - return mElements.RemoveObject(aNode); -} diff --git a/mozilla/content/xul/content/src/nsRDFDOMNodeList.h b/mozilla/content/xul/content/src/nsRDFDOMNodeList.h deleted file mode 100644 index f18c8075c46..00000000000 --- a/mozilla/content/xul/content/src/nsRDFDOMNodeList.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsRDFDOMNodeList_h__ -#define nsRDFDOMNodeList_h__ - -#include "nsIDOMNodeList.h" -#include "nsCOMArray.h" -class nsIDOMNode; - -class nsRDFDOMNodeList : public nsIDOMNodeList -{ -private: - nsCOMArray mElements; - - -public: - nsRDFDOMNodeList(void); - virtual ~nsRDFDOMNodeList(void); - - // nsISupports interface - NS_DECL_ISUPPORTS - - // nsIDOMNodeList interface - NS_DECL_NSIDOMNODELIST - - // Implementation methods - nsresult AppendNode(nsIDOMNode* aNode); - nsresult RemoveNode(nsIDOMNode* aNode); -}; - -#endif // nsRDFDOMNodeList_h__ - diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index af346234b2e..5506dbe2a70 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -112,7 +112,6 @@ #include "nsLayoutCID.h" #include "nsContentCID.h" #include "nsRDFCID.h" -#include "nsRDFDOMNodeList.h" #include "nsStyleConsts.h" #include "nsXPIDLString.h" #include "nsXULControllers.h" @@ -125,7 +124,6 @@ #include "nsCSSDeclaration.h" #include "nsIListBoxObject.h" #include "nsContentUtils.h" -#include "nsGenericElement.h" #include "nsContentList.h" #include "nsMutationEvent.h" #include "nsIDOMMutationEvent.h" @@ -642,31 +640,17 @@ nsXULElement::GetParentNode(nsIDOMNode** aParentNode) NS_IMETHODIMP nsXULElement::GetChildNodes(nsIDOMNodeList** aChildNodes) { - nsresult rv; + nsresult rv = EnsureSlots(); + NS_ENSURE_SUCCESS(rv, rv); - nsRDFDOMNodeList* children = new nsRDFDOMNodeList(); - NS_ENSURE_TRUE(children, NS_ERROR_OUT_OF_MEMORY); - NS_ADDREF(children); - - PRUint32 count = GetChildCount(); - - for (PRUint32 i = 0; i < count; ++i) { - nsIContent *child = GetChildAt(i); - - nsCOMPtr domNode = do_QueryInterface(child); - if (!domNode) { - NS_WARNING("child content doesn't support nsIDOMNode"); - continue; + if (!mSlots->mChildNodes) { + mSlots->mChildNodes = new nsChildContentList(this); + if (!mSlots->mChildNodes) { + return NS_ERROR_OUT_OF_MEMORY; } - - rv = children->AppendNode(domNode); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to append node to list"); - if (NS_FAILED(rv)) - break; } - - // Create() addref'd for us - *aChildNodes = children; + + NS_ADDREF(*aChildNodes = mSlots->mChildNodes); return NS_OK; } @@ -4029,6 +4013,10 @@ nsXULElement::Slots::Slots() nsXULElement::Slots::~Slots() { MOZ_COUNT_DTOR(nsXULElement::Slots); + + if (mChildNodes) { + mChildNodes->DropReference(); + } } diff --git a/mozilla/content/xul/content/src/nsXULElement.h b/mozilla/content/xul/content/src/nsXULElement.h index a7c2c4cb6da..9b3bec131f6 100644 --- a/mozilla/content/xul/content/src/nsXULElement.h +++ b/mozilla/content/xul/content/src/nsXULElement.h @@ -82,13 +82,13 @@ #include "nsAttrAndChildArray.h" #include "nsXULAtoms.h" #include "nsAutoPtr.h" +#include "nsGenericElement.h" class nsIDocument; class nsIRDFService; class nsISupportsArray; class nsIXULContentUtils; class nsIXULPrototypeDocument; -class nsRDFDOMNodeList; class nsString; class nsVoidArray; class nsIDocShell; @@ -595,6 +595,7 @@ protected: nsCOMPtr mControllers; // [OWNER] nsRefPtr mDOMStyle; // [OWNER] nsRefPtr mAttributeMap; // [OWNER] + nsRefPtr mChildNodes; // [OWNER] PRUint32 mLazyState; }; diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 19af5a994cc..0b69ec1d5de 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -94,7 +94,6 @@ #include "nsPIBoxObject.h" #include "nsRDFCID.h" #include "nsILocalStore.h" -#include "nsRDFDOMNodeList.h" #include "nsXPIDLString.h" #include "nsPIDOMWindow.h" #include "nsXULCommandDispatcher.h" diff --git a/mozilla/editor/libeditor/base/DeleteRangeTxn.cpp b/mozilla/editor/libeditor/base/DeleteRangeTxn.cpp index 46c7d24ef0f..73831d44698 100644 --- a/mozilla/editor/libeditor/base/DeleteRangeTxn.cpp +++ b/mozilla/editor/libeditor/base/DeleteRangeTxn.cpp @@ -259,9 +259,11 @@ DeleteRangeTxn::CreateTxnsToDeleteBetween(nsIDOMNode *aStartParent, if (NS_FAILED(result)) return result; if (!children) return NS_ERROR_NULL_POINTER; +#ifdef DEBUG PRUint32 childCount; children->GetLength(&childCount); NS_ASSERTION(aEndOffset<=childCount, "bad aEndOffset"); +#endif PRUint32 i; for (i=aStartOffset; i to flex the buttons to the left // so, don't remove the last child at position length - 1 - for (var i = childNodesLength - 2; i >= 0; i--) { - toolbar.removeChild(childNodes.item(i)); + while (childNodes.length > 1) { + // Remove back to front so there's less moving about. + toolbar.removeChild(childNodes.item(childNodes.length - 2)); } toolbar.removeAttribute("label"); diff --git a/mozilla/editor/ui/dialogs/content/EdInsertTOC.js b/mozilla/editor/ui/dialogs/content/EdInsertTOC.js index 9f151eff158..437f8913da2 100644 --- a/mozilla/editor/ui/dialogs/content/EdInsertTOC.js +++ b/mozilla/editor/ui/dialogs/content/EdInsertTOC.js @@ -295,9 +295,8 @@ function BuildTOC(update) } else { // we can keep the list itself but let's get rid of the TOC entries - var nodeList = toc.childNodes, l = nodeList.length; - for (j = l - 1; j >= 0; --j) - toc.removeChild(nodeList.item(j)); + while (toc.hasChildNodes()) { + toc.removeChild(toc.lastChild); } } var commentText = "mozToc "; diff --git a/mozilla/extensions/inspector/resources/content/jsutil/xul/inTreeBuilder.js b/mozilla/extensions/inspector/resources/content/jsutil/xul/inTreeBuilder.js index 9233cbc21f1..5e065deed8a 100644 --- a/mozilla/extensions/inspector/resources/content/jsutil/xul/inTreeBuilder.js +++ b/mozilla/extensions/inspector/resources/content/jsutil/xul/inTreeBuilder.js @@ -257,7 +257,7 @@ inTreeBuilder.prototype = resetTree: function() { var kids = this.mTree.childNodes; - for (var i = 0 ; i < kids.length; ++i) + for (var i = kids.length - 1; i >= 0; --i) if (kids[i].localName != "treechildren") this.mTree.removeChild(kids[i]); @@ -268,7 +268,7 @@ inTreeBuilder.prototype = clearChildren: function(aEl) { - while (aEl.childNodes.length) + while (aEl.hasChildNodes()) aEl.removeChild(aEl.lastChild); }, diff --git a/mozilla/extensions/inspector/resources/content/viewers/jsObject/jsObject.js b/mozilla/extensions/inspector/resources/content/viewers/jsObject/jsObject.js index 97f8190447e..8b9f5c0c788 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/jsObject/jsObject.js +++ b/mozilla/extensions/inspector/resources/content/viewers/jsObject/jsObject.js @@ -184,9 +184,8 @@ JSObjectViewer.prototype = emptyTree: function(aTreeKids) { - var kids = aTreeKids.childNodes; - for (var i = 0; i < kids.length; ++i) { - aTreeKids.removeChild(kids[i]); + while (aTreeKids.hasChildNodes()) { + aTreeKids.removeChild(aTreeKids.lastChild); } }, diff --git a/mozilla/extensions/inspector/resources/content/viewers/xblBindings/xblBindings.js b/mozilla/extensions/inspector/resources/content/viewers/xblBindings/xblBindings.js index 23f0ccdf7e7..97b5d38784e 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/xblBindings/xblBindings.js +++ b/mozilla/extensions/inspector/resources/content/viewers/xblBindings/xblBindings.js @@ -386,9 +386,8 @@ XBLBindings.prototype = clearChildren: function(aEl) { - var kids = aEl.childNodes; - for (var i = kids.length-1; i >=0; --i) - aEl.removeChild(kids[i]); + while (aEl.hasChildNodes()) + aEl.removeChild(aEl.lastChild); }, readDOMText: function(aEl) diff --git a/mozilla/extensions/p3p/resources/content/p3pSummary.js b/mozilla/extensions/p3p/resources/content/p3pSummary.js index c853cdefe18..29cbf7f992a 100644 --- a/mozilla/extensions/p3p/resources/content/p3pSummary.js +++ b/mozilla/extensions/p3p/resources/content/p3pSummary.js @@ -116,6 +116,12 @@ function transferToDocument(aResult, aResultDocument) else { aResultDocument.insertBefore(childNode, aResultDocument.documentElement); } + // We removed the node from the list, which will cause it + // to shrink by one element. "i" is now pointing to the + // node that used to be _after_ the node we just removed. + // Decrement i, so when it increments (at the start of the + // next iteration) we'll point at the right place. + --i; } } } diff --git a/mozilla/mail/base/content/msgHdrViewOverlay.js b/mozilla/mail/base/content/msgHdrViewOverlay.js index 012e9e3a6ef..cdd37b34c9d 100644 --- a/mozilla/mail/base/content/msgHdrViewOverlay.js +++ b/mozilla/mail/base/content/msgHdrViewOverlay.js @@ -1250,8 +1250,8 @@ function ClearAttachmentList() // clear selection var list = document.getElementById('attachmentList'); - while (list.childNodes.length) - list.removeChild(list.firstChild); + while (list.hasChildNodes()) + list.removeChild(list.lastChild); } function ShowEditMessageButton() diff --git a/mozilla/mail/components/addrbook/content/abCardViewOverlay.js b/mozilla/mail/components/addrbook/content/abCardViewOverlay.js index 5a5b291f073..e138ef4dc0c 100644 --- a/mozilla/mail/components/addrbook/content/abCardViewOverlay.js +++ b/mozilla/mail/components/addrbook/content/abCardViewOverlay.js @@ -402,7 +402,7 @@ function cvSetNode(node, text) { if ( node ) { - if ( node.childNodes.length == 0 ) + if ( !node.hasChildNodes() ) { var textNode = document.createTextNode(text); node.appendChild(textNode); @@ -437,8 +437,8 @@ function cvAddAddressNodes(node, uri) if (addressList) { var total = addressList.Count(); if (total > 0) { - for (var i = node.childNodes.length - 1; i >= 0; i--) { - node.removeChild(node.childNodes[i]); + while (node.hasChildNodes()) { + node.removeChild(node.lastChild); } for (i = 0; i < total; i++ ) { var descNode = document.createElement("description"); diff --git a/mozilla/mail/components/compose/content/MsgComposeCommands.js b/mozilla/mail/components/compose/content/MsgComposeCommands.js index fa9a0df7110..d759e27d8f2 100644 --- a/mozilla/mail/components/compose/content/MsgComposeCommands.js +++ b/mozilla/mail/components/compose/content/MsgComposeCommands.js @@ -1996,8 +1996,8 @@ function queryISupportsArray(supportsArray, iid) { function ClearIdentityListPopup(popup) { if (popup) - for (var i = popup.childNodes.length - 1; i >= 0; i--) - popup.removeChild(popup.childNodes[i]); + while (popup.hasChildNodes()) + popup.removeChild(popup.lastChild); } function compareAccountSortOrder(account1, account2) @@ -2432,9 +2432,9 @@ function RemoveAllAttachments() { var child; var bucket = document.getElementById("attachmentBucket"); - for (var i = bucket.childNodes.length - 1; i >= 0; i--) + while (bucket.hasChildNodes()) { - child = bucket.removeChild(bucket.childNodes[i]); + child = bucket.removeChild(bucket.lastChild); // Let's release the attachment object hold by the node else it won't go away until the window is destroyed child.attachment = null; } diff --git a/mozilla/mailnews/addrbook/prefs/resources/content/pref-directory.js b/mozilla/mailnews/addrbook/prefs/resources/content/pref-directory.js index c99eb359eb3..a682dcef6c9 100644 --- a/mozilla/mailnews/addrbook/prefs/resources/content/pref-directory.js +++ b/mozilla/mailnews/addrbook/prefs/resources/content/pref-directory.js @@ -30,8 +30,8 @@ function onEditDirectories() var popup = document.getElementById("directoriesListPopup"); if (popup) { - while (popup.childNodes.length) - popup.removeChild(popup.childNodes[0]); + while (popup.hasChildNodes()) + popup.removeChild(popup.lastChild); } gAvailDirectories = null; LoadDirectories(popup); diff --git a/mozilla/mailnews/addrbook/resources/content/abCardViewOverlay.js b/mozilla/mailnews/addrbook/resources/content/abCardViewOverlay.js index 8ea6f6123b3..fb6fb15eb07 100644 --- a/mozilla/mailnews/addrbook/resources/content/abCardViewOverlay.js +++ b/mozilla/mailnews/addrbook/resources/content/abCardViewOverlay.js @@ -403,7 +403,7 @@ function cvSetNode(node, text) { if ( node ) { - if ( node.childNodes.length == 0 ) + if ( !node.hasChildNodes() ) { var textNode = document.createTextNode(text); node.appendChild(textNode); @@ -438,8 +438,8 @@ function cvAddAddressNodes(node, uri) if (addressList) { var total = addressList.Count(); if (total > 0) { - for (var i = node.childNodes.length - 1; i >= 0; i--) { - node.removeChild(node.childNodes[i]); + while (node.hasChildNodes()) { + node.removeChild(node.lastChild); } for (i = 0; i < total; i++ ) { var descNode = document.createElement("description"); diff --git a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js index 9d35936e362..7a2824aa964 100644 --- a/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mozilla/mailnews/compose/resources/content/MsgComposeCommands.js @@ -1894,8 +1894,8 @@ function queryISupportsArray(supportsArray, iid) { function ClearIdentityListPopup(popup) { if (popup) - for (var i = popup.childNodes.length - 1; i >= 0; i--) - popup.removeChild(popup.childNodes[i]); + while (popup.hasChildNodes()) + popup.removeChild(popup.lastChild); } function compareAccountSortOrder(account1, account2) @@ -2300,9 +2300,9 @@ function RemoveAllAttachments() { var child; var bucket = document.getElementById("attachmentBucket"); - for (var i = bucket.childNodes.length - 1; i >= 0; i--) + while (bucket.hasChildNodes()) { - child = bucket.removeChild(bucket.childNodes[i]); + child = bucket.removeChild(bucket.lastChild); // Let's release the attachment object hold by the node else it won't go away until the window is destroyed child.attachment = null; } diff --git a/mozilla/mailnews/import/resources/content/importDialog.js b/mozilla/mailnews/import/resources/content/importDialog.js index 454289bcb9f..a5a88db7001 100644 --- a/mozilla/mailnews/import/resources/content/importDialog.js +++ b/mozilla/mailnews/import/resources/content/importDialog.js @@ -98,7 +98,7 @@ function SetDivText(id, text) var div = document.getElementById(id); if (div) { - if (!div.childNodes.length) { + if (!div.hasChildNodes()) { var textNode = document.createTextNode(text); div.appendChild(textNode); } @@ -321,10 +321,8 @@ function ListModules() { return; var body = document.getElementById( "moduleList"); - var max = body.childNodes.length - 1; - while (max >= 0) { - body.removeChild( body.childNodes[max]); - max--; + while (body.hasChildNodes()) { + body.removeChild(body.lastChild); } var count = top.importService.GetModuleCount(top.importType); diff --git a/mozilla/toolkit/components/help/content/help.js b/mozilla/toolkit/components/help/content/help.js index 6fe6190582b..a627183ad7a 100644 --- a/mozilla/toolkit/components/help/content/help.js +++ b/mozilla/toolkit/components/help/content/help.js @@ -413,7 +413,7 @@ function createMenuItem( aParent, aIndex, aLabel) function deleteHistoryItems(aParent) { var children = aParent.childNodes; - for (var i = 0; i < children.length; i++) + for (var i = children.length - 1; i >= 0; --i) { var index = children[i].getAttribute("index"); if (index) diff --git a/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js b/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js index 8b386c4781a..8e0077be75b 100644 --- a/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js +++ b/mozilla/xpfe/browser/resources/content/sessionHistoryUI.js @@ -304,7 +304,7 @@ function createRadioMenuItem( aParent, aIndex, aLabel, aChecked) function deleteHistoryItems(aParent) { var children = aParent.childNodes; - for (var i = 0; i < children.length; i++ ) + for (var i = children.length - 1; i >= 0; --i ) { var index = children[i].getAttribute( "index" ); if (index) diff --git a/mozilla/xpfe/browser/resources/content/urlbarBindings.xml b/mozilla/xpfe/browser/resources/content/urlbarBindings.xml index f0a8d47d41e..61c20922a4d 100644 --- a/mozilla/xpfe/browser/resources/content/urlbarBindings.xml +++ b/mozilla/xpfe/browser/resources/content/urlbarBindings.xml @@ -191,9 +191,8 @@ = 0; --i) - this.mSearchBox.removeChild(kids[i]); + while (this.mSearchBox.hasChildNodes()) + this.mSearchBox.removeChild(this.mSearchBox.lastChild); ]]> diff --git a/mozilla/xpfe/components/search/resources/shared.js b/mozilla/xpfe/components/search/resources/shared.js index 74457b4eb63..46a9cfeff1c 100644 --- a/mozilla/xpfe/components/search/resources/shared.js +++ b/mozilla/xpfe/components/search/resources/shared.js @@ -42,10 +42,10 @@ function fillContextMenu(name, treeName) if (!popupNode) return(false); // remove the menu node (which tosses all of its kids); // do this in case any old command nodes are hanging around - while (popupNode.childNodes.length) - { - popupNode.removeChild(popupNode.childNodes[0]); - } + while (popupNode.hasChildNodes()) + { + popupNode.removeChild(popupNode.lastChild); + } var treeNode = document.getElementById(treeName); if (!treeNode) return(false); @@ -185,17 +185,17 @@ function fillContextMenu(name, treeName) } // strip off leading/trailing menuseparators - while (popupNode.childNodes.length > 0) + while (popupNode.hasChildNodes()) { - if (popupNode.childNodes[0].tagName != "menuseparator") + if (popupNode.firstChild.tagName != "menuseparator") break; - popupNode.removeChild(popupNode.childNodes[0]); + popupNode.removeChild(popupNode.firstChild); } - while (popupNode.childNodes.length > 0) + while (popupNode.hasChildNodes()) { - if (popupNode.childNodes[popupNode.childNodes.length - 1].tagName != "menuseparator") + if (popupNode.lastChild.tagName != "menuseparator") break; - popupNode.removeChild(popupNode.childNodes[popupNode.childNodes.length - 1]); + popupNode.removeChild(popupNode.lastChild); } var searchMode = 0; @@ -203,9 +203,9 @@ function fillContextMenu(name, treeName) if (pref && bundle) { // then add a menu separator (if necessary) - if (popupNode.childNodes.length > 0) + if (popupNode.hasChildNodes()) { - if (popupNode.childNodes[popupNode.childNodes.length - 1].tagName != "menuseparator") + if (popupNode.lastChild.tagName != "menuseparator") { var menuSep = document.createElement("menuseparator"); popupNode.appendChild(menuSep);