From 58287333e8bc304f1b2055dcc9371f03036ebdc9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 9 Feb 2014 09:04:36 +0100 Subject: [PATCH] Bug 968766 - Part h: Replace GetDocumentAllResult by GetDocumentAllList on nsHTMLDocument; r=jst --- .../html/document/src/HTMLAllCollection.cpp | 19 +++++++++++++++- content/html/document/src/nsHTMLDocument.cpp | 22 +++---------------- content/html/document/src/nsHTMLDocument.h | 8 ++----- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/content/html/document/src/HTMLAllCollection.cpp b/content/html/document/src/HTMLAllCollection.cpp index 3d9b6fd4195..84c73885d15 100644 --- a/content/html/document/src/HTMLAllCollection.cpp +++ b/content/html/document/src/HTMLAllCollection.cpp @@ -135,7 +135,24 @@ HTMLAllCollection::GetNamedItem(const nsAString& aID, nsWrapperCache** aCache, nsresult* aResult) { - return mDocument->GetDocumentAllResult(aID, aCache, aResult); + nsContentList* docAllList = mDocument->GetDocumentAllList(aID, aResult); + if (!docAllList) { + return nullptr; + } + + // Check if there are more than 1 entries. Do this by getting the second one + // rather than the length since getting the length always requires walking + // the entire document. + + nsIContent* cont = docAllList->Item(1, true); + if (cont) { + *aCache = docAllList; + return static_cast(docAllList); + } + + // There's only 0 or 1 items. Return the first one or null. + *aCache = cont = docAllList->Item(0, true); + return cont; } } // namespace dom diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 971a52d5434..f91ed90fc00 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -2591,12 +2591,9 @@ DocAllResultMatch(nsIContent* aContent, int32_t aNamespaceID, nsIAtom* aAtom, } -nsISupports* -nsHTMLDocument::GetDocumentAllResult(const nsAString& aID, - nsWrapperCache** aCache, - nsresult *aResult) +nsContentList* +nsHTMLDocument::GetDocumentAllList(const nsAString& aID, nsresult *aResult) { - *aCache = nullptr; *aResult = NS_OK; nsIdentifierMapEntry *entry = mIdentifierMap.PutEntry(aID); @@ -2620,20 +2617,7 @@ nsHTMLDocument::GetDocumentAllResult(const nsAString& aID, entry->SetDocAllList(docAllList); } - // Check if there are more than 1 entries. Do this by getting the second one - // rather than the length since getting the length always requires walking - // the entire document. - - nsIContent* cont = docAllList->Item(1, true); - if (cont) { - *aCache = docAllList; - return static_cast(docAllList); - } - - // There's only 0 or 1 items. Return the first one or null. - *aCache = cont = docAllList->Item(0, true); - - return cont; + return docAllList; } HTMLAllCollection* diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 0e2994df9f5..5f96115393d 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -103,13 +103,9 @@ public: NS_DECL_NSIDOMHTMLDOCUMENT /** - * Returns the result of document.all[aID] which can either be a node - * or a nodelist depending on if there are multiple nodes with the same - * id. + * Returns the NodeList for document.all[aID], or null if there isn't one. */ - nsISupports *GetDocumentAllResult(const nsAString& aID, - nsWrapperCache **aCache, - nsresult *aResult); + nsContentList* GetDocumentAllList(const nsAString& aID, nsresult* aResult); mozilla::dom::HTMLAllCollection* All(); JSObject* GetAll(JSContext* aCx, mozilla::ErrorResult& aRv);