Bug 1415176. Move getElementsByName from HTMLDocument to Document. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 08 Nov 2017 11:13:33 -0500
changeset 390819 a27cb625d8eda6791da01debf2103a1b4ef07d9c
parent 390818 b69cb7c76bcd141264877059abef4848690d687f
child 390820 aefc9e16c5711bd2083ebb9b23ef74ef7db0dd5e
push id32845
push userarchaeopteryx@coole-files.de
push dateWed, 08 Nov 2017 22:08:47 +0000
treeherdermozilla-central@c10cf7082a9b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1415176
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1415176. Move getElementsByName from HTMLDocument to Document. r=mccr8 MozReview-Commit-ID: CRfrXC2x97S
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
dom/html/nsHTMLDocument.cpp
dom/html/nsHTMLDocument.h
dom/interfaces/html/nsIDOMHTMLDocument.idl
dom/webidl/Document.webidl
dom/webidl/HTMLDocument.webidl
layout/base/PresShell.cpp
testing/web-platform/meta/html/dom/interfaces.html.ini
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -7730,16 +7730,41 @@ nsIDocument::SetDir(const nsAString& aDi
 {
   Element* rootElement = GetHtmlElement();
   if (rootElement) {
     rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir,
                          aDirection, true);
   }
 }
 
+/* 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()) {
+    return false;
+  }
+
+  nsString* elementName = static_cast<nsString*>(aData);
+  return
+    aElement->GetNameSpaceID() == kNameSpaceID_XHTML &&
+    aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
+                          *elementName, eCaseMatters);
+}
+
+/* static */
+void*
+nsIDocument::UseExistingNameString(nsINode* aRootNode, const nsString* aName)
+{
+  return const_cast<nsString*>(aName);
+}
+
 NS_IMETHODIMP
 nsDocument::GetInputEncoding(nsAString& aInputEncoding)
 {
   nsIDocument::GetCharacterSet(aInputEncoding);
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -52,16 +52,17 @@ namespace dom {
 class ElementCreationOptionsOrString;
 } // namespace dom
 } // namespace mozilla
 #endif // MOZILLA_INTERNAL_API
 
 class gfxUserFontSet;
 class imgIRequest;
 class nsBindingManager;
+class nsCachableElementsByNameNodeList;
 class nsIDocShell;
 class nsDocShell;
 class nsDOMNavigationTiming;
 class nsFrameLoader;
 class nsHTMLCSSStyleSheet;
 class nsHTMLDocument;
 class nsHTMLStyleSheet;
 class nsAtom;
@@ -2936,16 +2937,24 @@ public:
   void GetReadyState(nsAString& aReadyState) const;
   // Not const because otherwise the compiler can't figure out whether to call
   // this GetTitle or the nsAString version from non-const methods, since
   // neither is an exact match.
   virtual void GetTitle(nsString& aTitle) = 0;
   virtual void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv) = 0;
   void GetDir(nsAString& aDirection) const;
   void SetDir(const nsAString& aDirection);
+  already_AddRefed<nsContentList> GetElementsByName(const nsAString& aName)
+  {
+    return GetFuncStringContentList<nsCachableElementsByNameNodeList>(this,
+                                                                      MatchNameAttribute,
+                                                                      nullptr,
+                                                                      UseExistingNameString,
+                                                                      aName);
+  }
   nsPIDOMWindowOuter* GetDefaultView() const
   {
     return GetWindow();
   }
   Element* GetActiveElement();
   bool HasFocus(mozilla::ErrorResult& rv) const;
   mozilla::TimeStamp LastFocusTime() const;
   void SetLastFocusTime(const mozilla::TimeStamp& aFocusTime);
@@ -3300,16 +3309,22 @@ protected:
   // mFrameRequestCallbacksScheduled.  aOldShell should only be passed when
   // mPresShell is becoming null; in that case it will be used to get hold of
   // the relevant refresh driver.
   void UpdateFrameRequestCallbackSchedulingState(nsIPresShell* aOldShell = nullptr);
 
   // Helper for GetScrollingElement/IsScrollingElement.
   bool IsPotentiallyScrollable(mozilla::dom::HTMLBodyElement* aBody);
 
+  // Helpers for GetElementsByName.
+  static bool MatchNameAttribute(mozilla::dom::Element* aElement,
+                                 int32_t aNamespaceID,
+                                 nsAtom* aAtom, void* aData);
+  static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName);
+
   nsCString mReferrer;
   nsString mLastModified;
 
   nsCOMPtr<nsIURI> mDocumentURI;
   nsCOMPtr<nsIURI> mOriginalURI;
   nsCOMPtr<nsIURI> mChromeXHRDocURI;
   nsCOMPtr<nsIURI> mDocumentBaseURI;
   nsCOMPtr<nsIURI> mChromeXHRDocBaseURI;
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -2045,48 +2045,16 @@ nsHTMLDocument::Writeln(const nsAString&
 
 void
 nsHTMLDocument::Writeln(JSContext* cx, const Sequence<nsString>& aText,
                         ErrorResult& rv)
 {
   WriteCommon(cx, aText, true, rv);
 }
 
-bool
-nsHTMLDocument::MatchNameAttribute(Element* aElement, int32_t aNamespaceID,
-                                   nsAtom* aAtom, void* aData)
-{
-  NS_PRECONDITION(aElement, "Must have element to work with!");
-
-  if (!aElement->HasName()) {
-    return false;
-  }
-
-  nsString* elementName = static_cast<nsString*>(aData);
-  return
-    aElement->GetNameSpaceID() == kNameSpaceID_XHTML &&
-    aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
-                          *elementName, eCaseMatters);
-}
-
-/* static */
-void*
-nsHTMLDocument::UseExistingNameString(nsINode* aRootNode, const nsString* aName)
-{
-  return const_cast<nsString*>(aName);
-}
-
-NS_IMETHODIMP
-nsHTMLDocument::GetElementsByName(const nsAString& aElementName,
-                                  nsIDOMNodeList** aReturn)
-{
-  *aReturn = GetElementsByName(aElementName).take();
-  return NS_OK;
-}
-
 void
 nsHTMLDocument::AddedForm()
 {
   ++mNumForms;
 }
 
 void
 nsHTMLDocument::RemovedForm()
--- a/dom/html/nsHTMLDocument.h
+++ b/dom/html/nsHTMLDocument.h
@@ -188,24 +188,16 @@ public:
   nsIHTMLCollection* Embeds();
   nsIHTMLCollection* Plugins();
   nsIHTMLCollection* Links();
   nsIHTMLCollection* Forms()
   {
     return nsHTMLDocument::GetForms();
   }
   nsIHTMLCollection* Scripts();
-  already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName)
-  {
-    return GetFuncStringContentList<nsCachableElementsByNameNodeList>(this,
-                                                                      MatchNameAttribute,
-                                                                      nullptr,
-                                                                      UseExistingNameString,
-                                                                      aName);
-  }
   already_AddRefed<nsIDocument> Open(JSContext* cx,
                                      const nsAString& aType,
                                      const nsAString& aReplace,
                                      mozilla::ErrorResult& aError);
   already_AddRefed<nsPIDOMWindowOuter>
   Open(JSContext* cx,
        const nsAString& aURL,
        const nsAString& aName,
@@ -275,20 +267,16 @@ protected:
                        int32_t* aHeight);
 
   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);
-  static bool MatchNameAttribute(mozilla::dom::Element* aElement,
-                                 int32_t aNamespaceID,
-                                 nsAtom* aAtom, void* aData);
-  static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName);
 
   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);
 
--- a/dom/interfaces/html/nsIDOMHTMLDocument.idl
+++ b/dom/interfaces/html/nsIDOMHTMLDocument.idl
@@ -24,17 +24,16 @@ interface nsIDOMHTMLDocument : nsIDOMDoc
 
   readonly attribute nsIDOMHTMLCollection images;
   readonly attribute nsIDOMHTMLCollection embeds;
   // mapped to attribute embeds for NS4 compat
   readonly attribute nsIDOMHTMLCollection plugins;
   readonly attribute nsIDOMHTMLCollection links;
   readonly attribute nsIDOMHTMLCollection forms;
   readonly attribute nsIDOMHTMLCollection scripts;
-  nsIDOMNodeList            getElementsByName(in DOMString elementName);
 
   // If aContentType is not something supported by nsHTMLDocument and
   // the HTML content sink, trying to write to the document will
   // probably throw.
   // Pass aReplace = true to trigger a replacement of the previous
   // document in session history; pass false for normal history handling.
   [implicit_jscontext, optional_argc]
   nsISupports               open([optional] in DOMString aContentTypeOrUrl,
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -118,17 +118,18 @@ partial interface Document {
   //(HTML only)         attribute HTMLElement? body;
   //(HTML only)readonly attribute HTMLHeadElement? head;
   //(HTML only)readonly attribute HTMLCollection images;
   //(HTML only)readonly attribute HTMLCollection embeds;
   //(HTML only)readonly attribute HTMLCollection plugins;
   //(HTML only)readonly attribute HTMLCollection links;
   //(HTML only)readonly attribute HTMLCollection forms;
   //(HTML only)readonly attribute HTMLCollection scripts;
-  //(HTML only)NodeList getElementsByName(DOMString elementName);
+  [Pure]
+  NodeList getElementsByName(DOMString elementName);
   //(Not implemented)readonly attribute DOMElementMap cssElementMap;
 
   // dynamic markup insertion
   //(HTML only)Document open(optional DOMString type, optional DOMString replace);
   //(HTML only)WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace);
   //(HTML only)void close();
   //(HTML only)void write(DOMString... text);
   //(HTML only)void writeln(DOMString... text);
--- a/dom/webidl/HTMLDocument.webidl
+++ b/dom/webidl/HTMLDocument.webidl
@@ -24,17 +24,16 @@ interface HTMLDocument : Document {
   [Pure]
   readonly attribute HTMLCollection plugins;
   [Pure]
   readonly attribute HTMLCollection links;
   [Pure]
   readonly attribute HTMLCollection forms;
   [Pure]
   readonly attribute HTMLCollection scripts;
-  NodeList getElementsByName(DOMString elementName);
 
   // dynamic markup insertion
   [CEReactions, Throws]
   Document open(optional DOMString type = "text/html", optional DOMString replace = "");
   [CEReactions, Throws]
   WindowProxy? open(DOMString url, DOMString name, DOMString features, optional boolean replace = false);
   [CEReactions, Throws]
   void close();
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -3070,20 +3070,19 @@ PresShell::GoToAnchor(const nsAString& a
 
   // Search for an element with a matching "id" attribute
   if (mDocument) {
     content = mDocument->GetElementById(aAnchorName);
   }
 
   // Search for an anchor element with a matching "name" attribute
   if (!content && htmlDoc) {
-    nsCOMPtr<nsIDOMNodeList> list;
     // Find a matching list of named nodes
-    rv = htmlDoc->GetElementsByName(aAnchorName, getter_AddRefs(list));
-    if (NS_SUCCEEDED(rv) && list) {
+    nsCOMPtr<nsIDOMNodeList> list = mDocument->GetElementsByName(aAnchorName);
+    if (list) {
       uint32_t i;
       // Loop through the named nodes looking for the first anchor
       for (i = 0; true; i++) {
         nsCOMPtr<nsIDOMNode> node;
         rv = list->Item(i, getter_AddRefs(node));
         if (!node) {  // End of list
           break;
         }
--- a/testing/web-platform/meta/html/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/html/dom/interfaces.html.ini
@@ -26,19 +26,16 @@
     expected: FAIL
 
   [Document interface: attribute forms]
     expected: FAIL
 
   [Document interface: attribute scripts]
     expected: FAIL
 
-  [Document interface: operation getElementsByName(DOMString)]
-    expected: FAIL
-
   [Document interface: operation getItems(DOMString)]
     expected: FAIL
 
   [Document interface: attribute cssElementMap]
     expected: FAIL
 
   [Document interface: operation open(DOMString,DOMString)]
     expected: FAIL
@@ -197,22 +194,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "forms" with the proper type (48)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "scripts" with the proper type (49)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "getElementsByName" with the proper type (50)]
-    expected: FAIL
-
-  [Document interface: calling getElementsByName(DOMString) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "getItems" with the proper type (51)]
     expected: FAIL
 
   [Document interface: calling getItems(DOMString) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "cssElementMap" with the proper type (52)]
     expected: FAIL
@@ -1853,19 +1844,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "forms" with the proper type (49)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "scripts" with the proper type (50)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "getElementsByName" with the proper type (51)]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "getItems" with the proper type (52)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "cssElementMap" with the proper type (53)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "open" with the proper type (56)]
     expected: FAIL
@@ -2051,22 +2039,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "forms" with the proper type (49)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "scripts" with the proper type (50)]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "getElementsByName" with the proper type (51)]
-    expected: FAIL
-
-  [Document interface: calling getElementsByName(DOMString) on new Document() with too few arguments must throw TypeError]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "cssElementMap" with the proper type (52)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "open" with the proper type (54)]
     expected: FAIL
 
   [Document interface: calling open(DOMString,DOMString) on new Document() with too few arguments must throw TypeError]
     expected: FAIL
@@ -2813,19 +2795,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "forms" with the proper type (50)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "scripts" with the proper type (51)]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "getElementsByName" with the proper type (52)]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "fgColor" with the proper type (70)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "linkColor" with the proper type (71)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "vlinkColor" with the proper type (72)]
     expected: FAIL
@@ -2891,19 +2870,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "forms" with the proper type (50)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "scripts" with the proper type (51)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "getElementsByName" with the proper type (52)]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "fgColor" with the proper type (70)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "linkColor" with the proper type (71)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "vlinkColor" with the proper type (72)]
     expected: FAIL
@@ -3035,19 +3011,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "forms" with the proper type (45)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "scripts" with the proper type (46)]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "getElementsByName" with the proper type (47)]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "open" with the proper type (49)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "open" with the proper type (50)]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "close" with the proper type (51)]
     expected: FAIL
@@ -3146,19 +3119,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "forms" with the proper type (45)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "scripts" with the proper type (46)]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "getElementsByName" with the proper type (47)]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "open" with the proper type (49)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "open" with the proper type (50)]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "close" with the proper type (51)]
     expected: FAIL
@@ -3461,19 +3431,16 @@
     expected: FAIL
 
   [Document interface: new Document() must inherit property "forms" with the proper type]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "scripts" with the proper type]
     expected: FAIL
 
-  [Document interface: new Document() must inherit property "getElementsByName(DOMString)" with the proper type]
-    expected: FAIL
-
   [Document interface: new Document() must inherit property "open(DOMString, DOMString)" with the proper type]
     expected: FAIL
 
   [Document interface: calling open(DOMString, DOMString) on new Document() with too few arguments must throw TypeError]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "open(USVString, DOMString, DOMString)" with the proper type]
     expected: FAIL
@@ -3581,19 +3548,16 @@
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "forms" with the proper type]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "scripts" with the proper type]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "getElementsByName(DOMString)" 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
 
   [Document interface: calling open(DOMString, DOMString) on document.implementation.createDocument(null, "", null) with too few arguments must throw TypeError]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "open(USVString, DOMString, DOMString)" with the proper type]
     expected: FAIL