From c37cf6640dd7505bdfb83e1a23d576d2472903a2 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 13 Nov 2017 10:39:06 -0500 Subject: [PATCH] Bug 1415677 part 3. Remove nsIDOMHTMLCollection::GetLength. r=qdot MozReview-Commit-ID: H9rdYf47WV --- dom/base/nsContentList.h | 20 ++++++++++++++------ dom/base/nsDocument.cpp | 12 ++++-------- dom/html/HTMLFormControlsCollection.cpp | 7 +++---- dom/html/HTMLFormControlsCollection.h | 1 + dom/html/HTMLFormElement.cpp | 4 +--- dom/html/HTMLOptionsCollection.cpp | 8 +++----- dom/html/HTMLOptionsCollection.h | 1 + dom/html/HTMLTableElement.cpp | 8 ++++---- dom/html/nsIHTMLCollection.h | 7 +------ dom/interfaces/html/nsIDOMHTMLCollection.idl | 1 - 10 files changed, 32 insertions(+), 37 deletions(-) diff --git a/dom/base/nsContentList.h b/dom/base/nsContentList.h index 9aa3b59902c2..b4c707279f8a 100644 --- a/dom/base/nsContentList.h +++ b/dom/base/nsContentList.h @@ -141,8 +141,8 @@ private: // Used for returning lists that will always be empty, such as the applets list // in HTML Documents -class nsEmptyContentList: public nsBaseContentList, - public nsIHTMLCollection +class nsEmptyContentList final : public nsBaseContentList, + public nsIHTMLCollection { public: explicit nsEmptyContentList(nsINode* aRoot) : nsBaseContentList(), @@ -155,8 +155,8 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsEmptyContentList, nsBaseContentList) NS_DECL_NSIDOMHTMLCOLLECTION - // Need Item because we also implement nsIDOMNodeList. - NS_IMETHOD Item(uint32_t aIndex, nsIDOMNode** aReturn); + // nsIDOMNodeList, which we also implement. + NS_DECL_NSIDOMNODELIST virtual nsINode* GetParentObject() override { @@ -174,6 +174,10 @@ public: nsWrapperCache::PreserveWrapper(aScriptObjectHolder); } + virtual uint32_t Length() override final + { + return 0; + } virtual nsIContent* Item(uint32_t aIndex) override; virtual mozilla::dom::Element* GetElementAt(uint32_t index) override; virtual mozilla::dom::Element* @@ -335,8 +339,8 @@ public: // nsIDOMHTMLCollection NS_DECL_NSIDOMHTMLCOLLECTION - // Need Item because we also implement nsIDOMNodeList. - NS_IMETHOD Item(uint32_t aIndex, nsIDOMNode** aReturn); + // nsIDOMNodeList, which we also implement. + NS_DECL_NSIDOMNODELIST // nsBaseContentList overrides virtual int32_t IndexOf(nsIContent *aContent, bool aDoFlush) override; @@ -346,6 +350,10 @@ public: return mRootNode; } + virtual uint32_t Length() override final + { + return Length(true); + } virtual nsIContent* Item(uint32_t aIndex) override; virtual mozilla::dom::Element* GetElementAt(uint32_t index) override; virtual mozilla::dom::Element* diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 69f8f3df0483..7ce560ee880f 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -592,6 +592,10 @@ public: { return nsSimpleContentList::GetParentObject(); } + virtual uint32_t Length() override + { + return nsSimpleContentList::Length(); + } virtual Element* GetElementAt(uint32_t aIndex) override { return mElements.SafeElementAt(aIndex)->AsElement(); @@ -657,7 +661,6 @@ public: return HTMLCollectionBinding::Wrap(aCx, this, aGivenProto); } - using nsBaseContentList::Length; using nsBaseContentList::Item; private: @@ -667,13 +670,6 @@ private: NS_IMPL_ISUPPORTS_INHERITED(SimpleHTMLCollection, nsSimpleContentList, nsIHTMLCollection, nsIDOMHTMLCollection) -NS_IMETHODIMP -SimpleHTMLCollection::GetLength(uint32_t* aLength) -{ - *aLength = Length(); - return NS_OK; -} - } // namespace dom } // namespace mozilla diff --git a/dom/html/HTMLFormControlsCollection.cpp b/dom/html/HTMLFormControlsCollection.cpp index f9e68595cc55..f282e712b3b8 100644 --- a/dom/html/HTMLFormControlsCollection.cpp +++ b/dom/html/HTMLFormControlsCollection.cpp @@ -155,12 +155,11 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(HTMLFormControlsCollection) // nsIDOMHTMLCollection interface -NS_IMETHODIMP -HTMLFormControlsCollection::GetLength(uint32_t* aLength) +uint32_t +HTMLFormControlsCollection::Length() { FlushPendingNotifications(); - *aLength = mElements.Length(); - return NS_OK; + return mElements.Length(); } nsISupports* diff --git a/dom/html/HTMLFormControlsCollection.h b/dom/html/HTMLFormControlsCollection.h index da1d8975399a..6cccf8998650 100644 --- a/dom/html/HTMLFormControlsCollection.h +++ b/dom/html/HTMLFormControlsCollection.h @@ -38,6 +38,7 @@ public: // nsIDOMHTMLCollection interface NS_DECL_NSIDOMHTMLCOLLECTION + virtual uint32_t Length() override; virtual Element* GetElementAt(uint32_t index) override; virtual nsINode* GetParentObject() override; diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index a7198b073b19..31205ed9bce8 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -1041,9 +1041,7 @@ HTMLFormElement::WalkFormElements(HTMLFormSubmission* aFormSubmission) NS_IMETHODIMP_(uint32_t) HTMLFormElement::GetElementCount() const { - uint32_t count = 0; - mControls->GetLength(&count); - return count; + return mControls->Length(); } Element* diff --git a/dom/html/HTMLOptionsCollection.cpp b/dom/html/HTMLOptionsCollection.cpp index f7e0416d7b62..e51e506cdd14 100644 --- a/dom/html/HTMLOptionsCollection.cpp +++ b/dom/html/HTMLOptionsCollection.cpp @@ -110,12 +110,10 @@ HTMLOptionsCollection::WrapObject(JSContext* aCx, JS::Handle aGivenPr return HTMLOptionsCollectionBinding::Wrap(aCx, this, aGivenProto); } -NS_IMETHODIMP -HTMLOptionsCollection::GetLength(uint32_t* aLength) +uint32_t +HTMLOptionsCollection::Length() { - *aLength = mElements.Length(); - - return NS_OK; + return mElements.Length(); } void diff --git a/dom/html/HTMLOptionsCollection.h b/dom/html/HTMLOptionsCollection.h index b0bceff7c16d..11f2bb609a02 100644 --- a/dom/html/HTMLOptionsCollection.h +++ b/dom/html/HTMLOptionsCollection.h @@ -56,6 +56,7 @@ protected: } public: + virtual uint32_t Length() override; virtual Element* GetElementAt(uint32_t aIndex) override; virtual nsINode* GetParentObject() override; diff --git a/dom/html/HTMLTableElement.cpp b/dom/html/HTMLTableElement.cpp index fed084859e6c..25d0932eea1d 100644 --- a/dom/html/HTMLTableElement.cpp +++ b/dom/html/HTMLTableElement.cpp @@ -39,6 +39,7 @@ public: NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED + virtual uint32_t Length() override; virtual Element* GetElementAt(uint32_t aIndex) override; virtual nsINode* GetParentObject() override { @@ -222,12 +223,11 @@ NS_INTERFACE_TABLE_HEAD(TableRowsCollection) NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(TableRowsCollection) NS_INTERFACE_MAP_END -NS_IMETHODIMP -TableRowsCollection::GetLength(uint32_t* aLength) +uint32_t +TableRowsCollection::Length() { EnsureInitialized(); - *aLength = mRows.Length(); - return NS_OK; + return mRows.Length(); } Element* diff --git a/dom/html/nsIHTMLCollection.h b/dom/html/nsIHTMLCollection.h index 7583560fb2ee..bd6bdc9561cc 100644 --- a/dom/html/nsIHTMLCollection.h +++ b/dom/html/nsIHTMLCollection.h @@ -40,12 +40,7 @@ public: */ virtual nsINode* GetParentObject() = 0; - uint32_t Length() - { - uint32_t length; - GetLength(&length); - return length; - } + virtual uint32_t Length() = 0; virtual mozilla::dom::Element* GetElementAt(uint32_t index) = 0; mozilla::dom::Element* Item(uint32_t index) { diff --git a/dom/interfaces/html/nsIDOMHTMLCollection.idl b/dom/interfaces/html/nsIDOMHTMLCollection.idl index c5c998687578..57dc16d0c718 100644 --- a/dom/interfaces/html/nsIDOMHTMLCollection.idl +++ b/dom/interfaces/html/nsIDOMHTMLCollection.idl @@ -19,5 +19,4 @@ [uuid(bb07f567-5b37-4172-92aa-7d00ceed4809)] interface nsIDOMHTMLCollection : nsISupports { - readonly attribute unsigned long length; };