Bug 1415588 part 3. Move the .links getter from HTMLDocument to Document. r=mystor

The null-checks in MatchLinks were working around code in nsDocument::Destroy
that was removed a while back in bug 341730.

MozReview-Commit-ID: 2SMmGr83GCB
This commit is contained in:
Boris Zbarsky 2018-03-12 21:44:56 -04:00
Родитель d5f5a95c81
Коммит f6f85bb529
8 изменённых файлов: 24 добавлений и 81 удалений

Просмотреть файл

@ -1976,6 +1976,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildrenCollection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mImages);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEmbeds);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLinks);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mForms);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScripts);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mApplets);
@ -2071,6 +2072,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChildrenCollection)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mImages);
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEmbeds);
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLinks);
NS_IMPL_CYCLE_COLLECTION_UNLINK(mForms);
NS_IMPL_CYCLE_COLLECTION_UNLINK(mScripts);
NS_IMPL_CYCLE_COLLECTION_UNLINK(mApplets);
@ -6835,6 +6837,23 @@ nsIDocument::Embeds()
return mEmbeds;
}
static bool
MatchLinks(Element* aElement, int32_t aNamespaceID,
nsAtom* aAtom, void* aData)
{
return aElement->IsAnyOfHTMLElements(nsGkAtoms::a, nsGkAtoms::area) &&
aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::href);
}
nsIHTMLCollection*
nsIDocument::Links()
{
if (!mLinks) {
mLinks = new nsContentList(this, MatchLinks, nullptr, nullptr);
}
return mLinks;
}
nsIHTMLCollection*
nsIDocument::Forms()
{

Просмотреть файл

@ -3289,6 +3289,7 @@ public:
{
return Embeds();
}
nsIHTMLCollection* Links();
nsIHTMLCollection* Forms();
nsIHTMLCollection* Scripts();
already_AddRefed<nsContentList> GetElementsByName(const nsAString& aName)
@ -3886,6 +3887,7 @@ protected:
// Various DOM lists
RefPtr<nsContentList> mImages;
RefPtr<nsContentList> mEmbeds;
RefPtr<nsContentList> mLinks;
RefPtr<nsContentList> mForms;
RefPtr<nsContentList> mScripts;
nsCOMPtr<nsIHTMLCollection> mApplets;

Просмотреть файл

@ -196,7 +196,6 @@ nsHTMLDocument::~nsHTMLDocument()
NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, nsDocument,
mAll,
mLinks,
mAnchors,
mWyciwygChannel,
mMidasCommandManager)
@ -1048,47 +1047,6 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain, ErrorResult& rv)
rv = NodePrincipal()->SetDomain(newURI);
}
bool
nsHTMLDocument::MatchLinks(Element* aElement, int32_t aNamespaceID,
nsAtom* aAtom, void* aData)
{
nsIDocument* doc = aElement->GetUncomposedDoc();
if (doc) {
NS_ASSERTION(aElement->IsInUncomposedDoc(),
"This method should never be called on content nodes that "
"are not in a document!");
#ifdef DEBUG
{
nsCOMPtr<nsIHTMLDocument> htmldoc =
do_QueryInterface(aElement->GetUncomposedDoc());
NS_ASSERTION(htmldoc,
"Huh, how did this happen? This should only be used with "
"HTML documents!");
}
#endif
mozilla::dom::NodeInfo *ni = aElement->NodeInfo();
nsAtom *localName = ni->NameAtom();
if (ni->NamespaceID() == kNameSpaceID_XHTML &&
(localName == nsGkAtoms::a || localName == nsGkAtoms::area)) {
return aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::href);
}
}
return false;
}
nsIHTMLCollection*
nsHTMLDocument::Links()
{
if (!mLinks) {
mLinks = new nsContentList(this, MatchLinks, nullptr, nullptr);
}
return mLinks;
}
bool
nsHTMLDocument::MatchAnchors(Element* aElement, int32_t aNamespaceID,
nsAtom* aAtom, void* aData)

Просмотреть файл

@ -166,7 +166,6 @@ public:
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& rv);
void GetSupportedNames(nsTArray<nsString>& aNames);
nsIHTMLCollection* Links();
already_AddRefed<nsIDocument> Open(JSContext* cx,
const nsAString& aType,
const nsAString& aReplace,
@ -242,8 +241,6 @@ protected:
nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
static bool MatchLinks(mozilla::dom::Element* aElement, int32_t aNamespaceID,
nsAtom* aAtom, void* aData);
static bool MatchAnchors(mozilla::dom::Element* aElement, int32_t aNamespaceID,
nsAtom* aAtom, void* aData);
@ -307,7 +304,6 @@ protected:
friend class ContentListHolder;
ContentListHolder* mContentListHolder;
RefPtr<nsContentList> mLinks;
RefPtr<nsContentList> mAnchors;
RefPtr<mozilla::dom::HTMLAllCollection> mAll;

Просмотреть файл

@ -135,7 +135,7 @@ partial interface Document {
[SameObject] readonly attribute HTMLCollection images;
[SameObject] readonly attribute HTMLCollection embeds;
[SameObject] readonly attribute HTMLCollection plugins;
//(HTML only)readonly attribute HTMLCollection links;
[SameObject] readonly attribute HTMLCollection links;
[SameObject] readonly attribute HTMLCollection forms;
[SameObject] readonly attribute HTMLCollection scripts;
[Pure]

Просмотреть файл

@ -13,8 +13,6 @@ interface HTMLDocument : Document {
// DOM tree accessors
[Throws]
getter object (DOMString name);
[Pure]
readonly attribute HTMLCollection links;
// dynamic markup insertion
[CEReactions, Throws]

Просмотреть файл

@ -8,9 +8,6 @@
[Document interface: attribute cookie]
expected: FAIL
[Document interface: attribute links]
expected: FAIL
[Document interface: operation getItems(DOMString)]
expected: FAIL
@ -152,9 +149,6 @@
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "cookie" with the proper type (36)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "links" with the proper type (47)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "getItems" with the proper type (51)]
expected: FAIL
@ -1790,9 +1784,6 @@
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "cookie" with the proper type (37)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "links" with the proper type (48)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "getItems" with the proper type (52)]
expected: FAIL
@ -1961,9 +1952,6 @@
[Document interface: new Document() must inherit property "cookie" with the proper type (37)]
expected: FAIL
[Document interface: new Document() must inherit property "links" with the proper type (48)]
expected: FAIL
[Document interface: new Document() must inherit property "cssElementMap" with the proper type (52)]
expected: FAIL
@ -2672,9 +2660,6 @@
[Document interface: new Document() must inherit property "cookie" with the proper type (38)]
expected: FAIL
[Document interface: new Document() must inherit property "links" with the proper type (49)]
expected: FAIL
[Document interface: new Document() must inherit property "fgColor" with the proper type (70)]
expected: FAIL
@ -2723,9 +2708,6 @@
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "cookie" with the proper type (38)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "links" with the proper type (49)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "fgColor" with the proper type (70)]
expected: FAIL
@ -2840,9 +2822,6 @@
[Document interface: new Document() must inherit property "cookie" with the proper type (33)]
expected: FAIL
[Document interface: new Document() must inherit property "links" with the proper type (44)]
expected: FAIL
[Document interface: new Document() must inherit property "open" with the proper type (49)]
expected: FAIL
@ -2924,9 +2903,6 @@
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "cookie" with the proper type (33)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "links" with the proper type (44)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "open" with the proper type (49)]
expected: FAIL
@ -3206,9 +3182,6 @@
[Document interface: new Document() must inherit property "cookie" with the proper type]
expected: FAIL
[Document interface: new Document() must inherit property "links" with the proper type]
expected: FAIL
[Document interface: new Document() must inherit property "open(DOMString, DOMString)" with the proper type]
expected: FAIL
@ -3299,9 +3272,6 @@
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "cookie" with the proper type]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "links" with the proper type]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "open(DOMString, DOMString)" with the proper type]
expected: FAIL

Просмотреть файл

@ -27,7 +27,6 @@
body:null,
doctype:null,
all:undefined,
links: undefined,
cookie:''
}
@ -96,7 +95,8 @@
"styleSheets",
"implementation",
"images",
"forms"
"forms",
"links",
];
for (let prop of objectProps) {