Bug 1415588 part 4. Move the .anchors getter from HTMLDocument to Document. r=mystor
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 12 Mar 2018 21:44:57 -0400
changeset 766583 5246350dc39422ae2fc9290673a6bc69c40756d3
parent 766582 6dfa6b890a139b2eb14c0367faa87cb9d799d1f3
child 766584 bd612e2c67a90c41fb08c9294a419c5a650da032
push id102360
push usernnethercote@mozilla.com
push dateTue, 13 Mar 2018 01:59:25 +0000
reviewersmystor
bugs1415588
milestone61.0a1
Bug 1415588 part 4. Move the .anchors getter from HTMLDocument to Document. r=mystor MozReview-Commit-ID: 2uqt9cdz6y7
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
dom/html/nsHTMLDocument.cpp
dom/html/nsHTMLDocument.h
dom/webidl/Document.webidl
dom/webidl/HTMLDocument.webidl
testing/web-platform/meta/html/dom/interfaces.html.ini
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1975,16 +1975,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTemplateContentsOwner)
   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);
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnchors);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnonymousContents)
 
   // Traverse all our nsCOMArrays.
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleSheets)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOnDemandBuiltInUASheets)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPreloadingImages)
 
   for (uint32_t i = 0; i < tmp->mFrameRequestCallbacks.Length(); ++i) {
@@ -2071,16 +2072,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mTemplateContentsOwner)
   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);
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnchors);
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mOrientationPendingPromise)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mFontFaceSet)
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mReadyForIdle);
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mAboutCapabilities)
 
   tmp->mParentDocument = nullptr;
 
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mPreloadingImages)
@@ -6878,16 +6880,33 @@ nsIHTMLCollection*
 nsIDocument::Applets()
 {
   if (!mApplets) {
     mApplets = new nsEmptyContentList(this);
   }
   return mApplets;
 }
 
+static bool
+MatchAnchors(Element* aElement, int32_t aNamespaceID,
+             nsAtom* aAtom, void* aData)
+{
+  return aElement->IsHTMLElement(nsGkAtoms::a) &&
+         aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::name);
+}
+
+nsIHTMLCollection*
+nsIDocument::Anchors()
+{
+  if (!mAnchors) {
+    mAnchors = new nsContentList(this, MatchAnchors, nullptr, nullptr);
+  }
+  return mAnchors;
+}
+
 /* static */
 bool
 nsIDocument::MatchNameAttribute(Element* aElement, int32_t aNamespaceID,
                                 nsAtom* aAtom, void* aData)
 {
   NS_PRECONDITION(aElement, "Must have element to work with!");
 
   if (!aElement->HasName()) {
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -3302,16 +3302,17 @@ public:
   }
   nsPIDOMWindowOuter* GetDefaultView() const
   {
     return GetWindow();
   }
   Element* GetActiveElement();
   bool HasFocus(mozilla::ErrorResult& rv) const;
   nsIHTMLCollection* Applets();
+  nsIHTMLCollection* Anchors();
   mozilla::TimeStamp LastFocusTime() const;
   void SetLastFocusTime(const mozilla::TimeStamp& aFocusTime);
   // Event handlers are all on nsINode already
   bool MozSyntheticDocument() const
   {
     return IsSyntheticDocument();
   }
   Element* GetCurrentScript();
@@ -3886,16 +3887,17 @@ protected:
 
   // Various DOM lists
   RefPtr<nsContentList> mImages;
   RefPtr<nsContentList> mEmbeds;
   RefPtr<nsContentList> mLinks;
   RefPtr<nsContentList> mForms;
   RefPtr<nsContentList> mScripts;
   nsCOMPtr<nsIHTMLCollection> mApplets;
+  RefPtr<nsContentList> mAnchors;
 
   // container for per-context fonts (downloadable, SVG, etc.)
   RefPtr<mozilla::dom::FontFaceSet> mFontFaceSet;
 
   // Last time this document or a one of its sub-documents was focused.  If
   // focus has never occurred then mLastFocusTime.IsNull() will be true.
   mozilla::TimeStamp mLastFocusTime;
 
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -191,17 +191,16 @@ nsHTMLDocument::nsHTMLDocument()
 }
 
 nsHTMLDocument::~nsHTMLDocument()
 {
 }
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, nsDocument,
                                    mAll,
-                                   mAnchors,
                                    mWyciwygChannel,
                                    mMidasCommandManager)
 
 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(nsHTMLDocument,
                                              nsDocument,
                                              nsIHTMLDocument)
 
 JSObject*
@@ -1042,49 +1041,16 @@ nsHTMLDocument::SetDomain(const nsAStrin
     rv.Throw(NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN);
     return;
   }
 
   NS_TryToSetImmutable(newURI);
   rv = NodePrincipal()->SetDomain(newURI);
 }
 
-bool
-nsHTMLDocument::MatchAnchors(Element* aElement, int32_t aNamespaceID,
-                             nsAtom* aAtom, void* aData)
-{
-  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
-
-  if (aElement->IsHTMLElement(nsGkAtoms::a)) {
-    return aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::name);
-  }
-
-  return false;
-}
-
-nsIHTMLCollection*
-nsHTMLDocument::Anchors()
-{
-  if (!mAnchors) {
-    mAnchors = new nsContentList(this, MatchAnchors, nullptr, nullptr);
-  }
-  return mAnchors;
-}
-
 already_AddRefed<nsIChannel>
 nsHTMLDocument::CreateDummyChannelForCookies(nsIURI* aCodebaseURI)
 {
   // The cookie service reads the privacy status of the channel we pass to it in
   // order to determine which cookie database to query.  In some cases we don't
   // have a proper channel to hand it to the cookie service though.  This
   // function creates a dummy channel that is not used to load anything, for the
   // sole purpose of handing it to the cookie service.  DO NOT USE THIS CHANNEL
--- a/dom/html/nsHTMLDocument.h
+++ b/dom/html/nsHTMLDocument.h
@@ -208,17 +208,16 @@ public:
   void GetLinkColor(nsAString& aLinkColor);
   void SetLinkColor(const nsAString& aLinkColor);
   void GetVlinkColor(nsAString& aAvlinkColor);
   void SetVlinkColor(const nsAString& aVlinkColor);
   void GetAlinkColor(nsAString& aAlinkColor);
   void SetAlinkColor(const nsAString& aAlinkColor);
   void GetBgColor(nsAString& aBgColor);
   void SetBgColor(const nsAString& aBgColor);
-  nsIHTMLCollection* Anchors();
   void Clear() const
   {
     // Deprecated
   }
   void CaptureEvents();
   void ReleaseEvents();
   // We're picking up GetLocation from Document
   already_AddRefed<mozilla::dom::Location> GetLocation() const
@@ -236,19 +235,16 @@ public:
 protected:
   ~nsHTMLDocument();
 
   nsresult GetBodySize(int32_t* aWidth,
                        int32_t* aHeight);
 
   nsIContent *MatchId(nsIContent *aContent, const nsAString& aId);
 
-  static bool MatchAnchors(mozilla::dom::Element* aElement, int32_t aNamespaceID,
-                           nsAtom* aAtom, void* aData);
-
   static void DocumentWriteTerminationFunc(nsISupports *aRef);
 
   already_AddRefed<nsIURI> GetDomainURI();
   already_AddRefed<nsIURI> CreateInheritingURIForHost(const nsACString& aHostString);
   already_AddRefed<nsIURI> RegistrableDomainSuffixOfInternal(const nsAString& aHostSuffixString,
                                                              nsIURI* aOrigHost);
 
 
@@ -299,18 +295,16 @@ protected:
     RefPtr<nsHTMLDocument> mDocument;
     RefPtr<nsContentList> mFormList;
     RefPtr<nsContentList> mFormControlList;
   };
 
   friend class ContentListHolder;
   ContentListHolder* mContentListHolder;
 
-  RefPtr<nsContentList> mAnchors;
-
   RefPtr<mozilla::dom::HTMLAllCollection> mAll;
 
   /** # of forms in the document, synchronously set */
   int32_t mNumForms;
 
   static uint32_t gWyciwygSessionCnt;
 
   static void TryHintCharset(nsIContentViewer* aContentViewer,
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -241,17 +241,17 @@ partial interface Document {
 // https://html.spec.whatwg.org/multipage/obsolete.html#other-elements%2C-attributes-and-apis
 partial interface Document {
   //(HTML only)[CEReactions] attribute [TreatNullAs=EmptyString] DOMString fgColor;
   //(HTML only)[CEReactions] attribute [TreatNullAs=EmptyString] DOMString linkColor;
   //(HTML only)[CEReactions] attribute [TreatNullAs=EmptyString] DOMString vlinkColor;
   //(HTML only)[CEReactions] attribute [TreatNullAs=EmptyString] DOMString alinkColor;
   //(HTML only)[CEReactions] attribute [TreatNullAs=EmptyString] DOMString bgColor;
 
-  //(HTML only)[SameObject] readonly attribute HTMLCollection anchors;
+  [SameObject] readonly attribute HTMLCollection anchors;
   [SameObject] readonly attribute HTMLCollection applets;
 
   //(HTML only)void clear();
   //(HTML only)void captureEvents();
   //(HTML only)void releaseEvents();
 
   //(HTML only)[SameObject] readonly attribute HTMLAllCollection all;
 };
--- a/dom/webidl/HTMLDocument.webidl
+++ b/dom/webidl/HTMLDocument.webidl
@@ -43,19 +43,16 @@ interface HTMLDocument : Document {
   DOMString queryCommandValue(DOMString commandId);
 
   [CEReactions, TreatNullAs=EmptyString] attribute DOMString fgColor;
   [CEReactions, TreatNullAs=EmptyString] attribute DOMString linkColor;
   [CEReactions, TreatNullAs=EmptyString] attribute DOMString vlinkColor;
   [CEReactions, TreatNullAs=EmptyString] attribute DOMString alinkColor;
   [CEReactions, TreatNullAs=EmptyString] attribute DOMString bgColor;
 
-  [Pure]
-  readonly attribute HTMLCollection anchors;
-
   void clear();
 
   readonly attribute HTMLAllCollection all;
 
   // @deprecated These are old Netscape 4 methods. Do not use,
   //             the implementation is no-op.
   // XXXbz do we actually need these anymore?
   void                      captureEvents();
--- a/testing/web-platform/meta/html/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/html/dom/interfaces.html.ini
@@ -63,19 +63,16 @@
     expected: FAIL
 
   [Document interface: attribute alinkColor]
     expected: FAIL
 
   [Document interface: attribute bgColor]
     expected: FAIL
 
-  [Document interface: attribute anchors]
-    expected: FAIL
-
   [Document interface: operation clear()]
     expected: FAIL
 
   [Document interface: operation captureEvents()]
     expected: FAIL
 
   [Document interface: operation releaseEvents()]
     expected: FAIL
@@ -237,19 +234,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "alinkColor" with the proper type (74)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "bgColor" with the proper type (75)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "anchors" with the proper type (76)]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "clear" with the proper type (78)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "captureEvents" with the proper type (79)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "releaseEvents" with the proper type (80)]
     expected: FAIL
@@ -1836,19 +1830,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "alinkColor" with the proper type (75)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "bgColor" with the proper type (76)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "anchors" with the proper type (77)]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "clear" with the proper type (79)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "captureEvents" with the proper type (80)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "releaseEvents" with the proper type (81)]
     expected: FAIL
@@ -2034,19 +2025,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "alinkColor" with the proper type (74)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "bgColor" with the proper type (75)]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "anchors" with the proper type (76)]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "clear" with the proper type (78)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "captureEvents" with the proper type (79)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "releaseEvents" with the proper type (80)]
     expected: FAIL
@@ -2406,19 +2394,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "alinkColor" with the proper type (72)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "bgColor" with the proper type (73)]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "anchors" with the proper type (74)]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "clear" with the proper type (76)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "captureEvents" with the proper type (77)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "releaseEvents" with the proper type (78)]
     expected: FAIL
@@ -2481,19 +2466,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "alinkColor" with the proper type (72)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "bgColor" with the proper type (73)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "anchors" with the proper type (74)]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "clear" with the proper type (76)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "captureEvents" with the proper type (77)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "releaseEvents" with the proper type (78)]
     expected: FAIL
@@ -2670,19 +2652,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "alinkColor" with the proper type (73)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "bgColor" with the proper type (74)]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "anchors" with the proper type (75)]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "clear" with the proper type (77)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "captureEvents" with the proper type (78)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "releaseEvents" with the proper type (79)]
     expected: FAIL
@@ -2718,19 +2697,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "alinkColor" with the proper type (73)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "bgColor" with the proper type (74)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "anchors" with the proper type (75)]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "clear" with the proper type (77)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "captureEvents" with the proper type (78)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "releaseEvents" with the proper type (79)]
     expected: FAIL
@@ -2868,19 +2844,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "alinkColor" with the proper type (68)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "bgColor" with the proper type (69)]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "anchors" with the proper type (70)]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "clear" with the proper type (72)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "captureEvents" with the proper type (73)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "releaseEvents" with the proper type (74)]
     expected: FAIL
@@ -2949,19 +2922,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "alinkColor" with the proper type (68)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "bgColor" with the proper type (69)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "anchors" with the proper type (70)]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "clear" with the proper type (72)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "captureEvents" with the proper type (73)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "releaseEvents" with the proper type (74)]
     expected: FAIL
@@ -3237,19 +3207,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "alinkColor" with the proper type]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "bgColor" with the proper type]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "anchors" with the proper type]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "clear()" with the proper type]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "captureEvents()" with the proper type]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "releaseEvents()" with the proper type]
     expected: FAIL
@@ -3327,19 +3294,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "alinkColor" with the proper type]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "bgColor" with the proper type]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "anchors" with the proper type]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "clear()" with the proper type]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "captureEvents()" with the proper type]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "releaseEvents()" with the proper type]
     expected: FAIL