Bug 1558571 - Move HTMLDocument.all to Document; r=farre
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 09 Jul 2019 18:09:40 +0000
changeset 481971 03fe4de2ed94664a7100ccfca5ab9a0f57981a7c
parent 481970 9a84014bc0e96d1b7ac2771427015dd31de78721
child 481972 af369a5fc700b13d98937040576ffa45c6209c60
push id113647
push useraciure@mozilla.com
push dateWed, 10 Jul 2019 09:46:39 +0000
treeherdermozilla-inbound@f3a387c13e2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfarre
bugs1558571
milestone70.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 1558571 - Move HTMLDocument.all to Document; r=farre Differential Revision: https://phabricator.services.mozilla.com/D34569
dom/base/Document.cpp
dom/base/Document.h
dom/html/HTMLAllCollection.cpp
dom/html/HTMLAllCollection.h
dom/html/nsHTMLDocument.cpp
dom/html/nsHTMLDocument.h
dom/webidl/Document.webidl
dom/webidl/HTMLDocument.webidl
testing/web-platform/meta/html/dom/interfaces.https.html.ini
testing/web-platform/tests/xhr/responsexml-document-properties.htm
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -86,16 +86,17 @@
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/CSPDictionariesBinding.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/FeaturePolicy.h"
 #include "mozilla/dom/FeaturePolicyUtils.h"
 #include "mozilla/dom/FramingChecker.h"
+#include "mozilla/dom/HTMLAllCollection.h"
 #include "mozilla/dom/HTMLSharedElement.h"
 #include "mozilla/dom/Navigator.h"
 #include "mozilla/dom/Performance.h"
 #include "mozilla/dom/TreeOrderedArrayInlines.h"
 #include "mozilla/dom/ResizeObserver.h"
 #include "mozilla/dom/ResizeObserverController.h"
 #include "mozilla/dom/ServiceWorkerContainer.h"
 #include "mozilla/dom/ScriptLoader.h"
@@ -1999,16 +2000,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mApplets);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnchors);
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAnonymousContents)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCommandDispatcher)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFeaturePolicy)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSuppressedEventListener)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrototypeDocument)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMidasCommandManager)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAll)
 
   // Traverse all our nsCOMArrays.
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPreloadingImages)
 
   for (uint32_t i = 0; i < tmp->mFrameRequestCallbacks.Length(); ++i) {
     NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mFrameRequestCallbacks[i]");
     cb.NoteXPCOMChild(tmp->mFrameRequestCallbacks[i].mCallback);
   }
@@ -5627,16 +5629,23 @@ void Document::SetFgColor(const nsAStrin
     body->SetText(aFgColor);
   }
 }
 
 void Document::CaptureEvents() { WarnOnceAbout(Document::eUseOfCaptureEvents); }
 
 void Document::ReleaseEvents() { WarnOnceAbout(Document::eUseOfReleaseEvents); }
 
+HTMLAllCollection* Document::All() {
+  if (!mAll) {
+    mAll = new HTMLAllCollection(this);
+  }
+  return mAll;
+}
+
 nsresult Document::GetSrcdocData(nsAString& aSrcdocData) {
   if (mIsSrcdocDocument) {
     nsCOMPtr<nsIInputStreamChannel> inStrmChan = do_QueryInterface(mChannel);
     if (inStrmChan) {
       return inStrmChan->GetSrcdocData(aSrcdocData);
     }
   }
   aSrcdocData = VoidString();
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -180,16 +180,17 @@ class DOMStringList;
 class Element;
 struct ElementCreationOptions;
 class Event;
 class EventTarget;
 class FeaturePolicy;
 class FontFaceSet;
 class FrameRequestCallback;
 class ImageTracker;
+class HTMLAllCollection;
 class HTMLBodyElement;
 class HTMLSharedElement;
 class HTMLImageElement;
 struct LifecycleCallbackArgs;
 class Link;
 class Location;
 class MediaQueryList;
 class GlobalObject;
@@ -3577,16 +3578,18 @@ class Document : public nsINode,
   void GetBgColor(nsAString& aBgColor);
   void SetBgColor(const nsAString& aBgColor);
   void Clear() const {
     // Deprecated
   }
   void CaptureEvents();
   void ReleaseEvents();
 
+  mozilla::dom::HTMLAllCollection* All();
+
   static bool IsUnprefixedFullscreenEnabled(JSContext* aCx, JSObject* aObject);
   static bool DocumentSupportsL10n(JSContext* aCx, JSObject* aObject);
   static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject);
   static bool IsWebAnimationsEnabled(CallerType aCallerType);
   static bool IsWebAnimationsGetAnimationsEnabled(JSContext* aCx,
                                                   JSObject* aObject);
   static bool AreWebAnimationsImplicitKeyframesEnabled(JSContext* aCx,
                                                        JSObject* aObject);
@@ -5210,16 +5213,18 @@ class Document : public nsINode,
   uint32_t mIgnoreOpensDuringUnloadCounter;
 
   nsCOMPtr<nsIDOMXULCommandDispatcher>
       mCommandDispatcher;  // [OWNER] of the focus tracker
 
   RefPtr<XULBroadcastManager> mXULBroadcastManager;
   RefPtr<XULPersist> mXULPersist;
 
+  RefPtr<mozilla::dom::HTMLAllCollection> mAll;
+
   // document lightweight theme for use with :-moz-lwtheme,
   // :-moz-lwtheme-brighttext and :-moz-lwtheme-darktext
   DocumentTheme mDocLWTheme;
 
   // Pres shell resolution saved before entering fullscreen mode.
   float mSavedResolution;
 
   bool mPendingInitialTranslation;
--- a/dom/html/HTMLAllCollection.cpp
+++ b/dom/html/HTMLAllCollection.cpp
@@ -3,23 +3,25 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/HTMLAllCollection.h"
 
 #include "mozilla/dom/HTMLAllCollectionBinding.h"
 #include "mozilla/dom/Nullable.h"
+#include "mozilla/dom/Document.h"
 #include "mozilla/dom/Element.h"
-#include "nsHTMLDocument.h"
+#include "nsContentList.h"
+#include "nsGenericHTMLElement.h"
 
 namespace mozilla {
 namespace dom {
 
-HTMLAllCollection::HTMLAllCollection(nsHTMLDocument* aDocument)
+HTMLAllCollection::HTMLAllCollection(mozilla::dom::Document* aDocument)
     : mDocument(aDocument) {
   MOZ_ASSERT(mDocument);
 }
 
 HTMLAllCollection::~HTMLAllCollection() {}
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(HTMLAllCollection, mDocument, mCollection,
                                       mNamedMap)
--- a/dom/html/HTMLAllCollection.h
+++ b/dom/html/HTMLAllCollection.h
@@ -10,34 +10,34 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsISupportsImpl.h"
 #include "nsRefPtrHashtable.h"
 #include "nsWrapperCache.h"
 
 #include <stdint.h>
 
 class nsContentList;
-class nsHTMLDocument;
 class nsINode;
 
 namespace mozilla {
 namespace dom {
 
+class Document;
 class Element;
 class OwningHTMLCollectionOrElement;
 template <typename>
 struct Nullable;
 template <typename>
 class Optional;
 
 class HTMLAllCollection final : public nsISupports, public nsWrapperCache {
   ~HTMLAllCollection();
 
  public:
-  explicit HTMLAllCollection(nsHTMLDocument* aDocument);
+  explicit HTMLAllCollection(mozilla::dom::Document* aDocument);
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(HTMLAllCollection)
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
   nsINode* GetParentObject() const;
 
@@ -75,17 +75,17 @@ class HTMLAllCollection final : public n
    */
   nsContentList* GetDocumentAllList(const nsAString& aID);
 
   /**
    * Helper for indexed getter and spec Item() method.
    */
   Element* Item(uint32_t aIndex);
 
-  RefPtr<nsHTMLDocument> mDocument;
+  RefPtr<mozilla::dom::Document> mDocument;
   RefPtr<nsContentList> mCollection;
   nsRefPtrHashtable<nsStringHashKey, nsContentList> mNamedMap;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // mozilla_dom_HTMLAllCollection_h
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsHTMLDocument.h"
 
 #include "nsIContentPolicy.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/PresShell.h"
-#include "mozilla/dom/HTMLAllCollection.h"
 #include "nsCommandManager.h"
 #include "nsCOMPtr.h"
 #include "nsGlobalWindow.h"
 #include "nsString.h"
 #include "nsPrintfCString.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIContentSecurityPolicy.h"
@@ -153,20 +152,16 @@ nsHTMLDocument::nsHTMLDocument()
       mIsPlainText(false) {
   mType = eHTML;
   mDefaultElementType = kNameSpaceID_XHTML;
   mCompatMode = eCompatibility_NavQuirks;
 }
 
 nsHTMLDocument::~nsHTMLDocument() {}
 
-NS_IMPL_CYCLE_COLLECTION_INHERITED(nsHTMLDocument, Document, mAll)
-
-NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(nsHTMLDocument, Document)
-
 JSObject* nsHTMLDocument::WrapNode(JSContext* aCx,
                                    JS::Handle<JSObject*> aGivenProto) {
   return HTMLDocument_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 nsresult nsHTMLDocument::Init() {
   nsresult rv = Document::Init();
   NS_ENSURE_SUCCESS(rv, rv);
@@ -775,23 +770,16 @@ void nsHTMLDocument::GetSupportedNames(n
 
 // forms related stuff
 
 bool nsHTMLDocument::MatchFormControls(Element* aElement, int32_t aNamespaceID,
                                        nsAtom* aAtom, void* aData) {
   return aElement->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL);
 }
 
-HTMLAllCollection* nsHTMLDocument::All() {
-  if (!mAll) {
-    mAll = new HTMLAllCollection(this);
-  }
-  return mAll;
-}
-
 nsresult nsHTMLDocument::Clone(dom::NodeInfo* aNodeInfo,
                                nsINode** aResult) const {
   NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
                "Can't import this document into another document!");
 
   RefPtr<nsHTMLDocument> clone = new nsHTMLDocument();
   nsresult rv = CloneDocHelper(clone.get());
   NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/html/nsHTMLDocument.h
+++ b/dom/html/nsHTMLDocument.h
@@ -22,17 +22,16 @@
 class nsCommandManager;
 class nsIURI;
 class nsIDocShell;
 class nsICachingChannel;
 class nsILoadGroup;
 
 namespace mozilla {
 namespace dom {
-class HTMLAllCollection;
 template <typename T>
 struct Nullable;
 class WindowProxyHolder;
 }  // namespace dom
 }  // namespace mozilla
 
 class nsHTMLDocument : public mozilla::dom::Document {
  protected:
@@ -44,19 +43,16 @@ class nsHTMLDocument : public mozilla::d
 
  public:
   using Document::GetPlugins;
   using Document::SetDocumentURI;
 
   nsHTMLDocument();
   virtual nsresult Init() override;
 
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLDocument, Document)
-
   // Document
   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) override;
   virtual void ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
                           nsIPrincipal* aPrincipal,
                           nsIPrincipal* aStoragePrincipal) override;
 
   virtual nsresult StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
                                      nsILoadGroup* aLoadGroup,
@@ -68,18 +64,16 @@ class nsHTMLDocument : public mozilla::d
  protected:
   virtual bool UseWidthDeviceWidthFallbackViewport() const override;
 
  public:
   virtual Element* GetUnfocusedKeyEventTarget() override;
 
   nsContentList* GetExistingForms() const { return mForms; }
 
-  mozilla::dom::HTMLAllCollection* All();
-
   // Returns whether an object was found for aName.
   bool ResolveName(JSContext* aCx, const nsAString& aName,
                    JS::MutableHandle<JS::Value> aRetval,
                    mozilla::ErrorResult& aError);
 
   /**
    * Called when form->BindToTree() is called so that document knows
    * immediately when a form is added
@@ -167,18 +161,16 @@ class nsHTMLDocument : public mozilla::d
     RefPtr<nsHTMLDocument> mDocument;
     RefPtr<nsContentList> mFormList;
     RefPtr<nsContentList> mFormControlList;
   };
 
   friend class ContentListHolder;
   ContentListHolder* mContentListHolder;
 
-  RefPtr<mozilla::dom::HTMLAllCollection> mAll;
-
   /** # of forms in the document, synchronously set */
   int32_t mNumForms;
 
   static void TryHintCharset(nsIContentViewer* aContentViewer,
                              int32_t& aCharsetSource,
                              NotNull<const Encoding*>& aEncoding);
   void TryUserForcedCharset(nsIContentViewer* aCv, nsIDocShell* aDocShell,
                             int32_t& aCharsetSource,
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -271,17 +271,17 @@ partial interface Document {
 
   void clear();
   // @deprecated These are old Netscape 4 methods. Do not use,
   //             the implementation is no-op.
   // XXXbz do we actually need these anymore?
   void captureEvents();
   void releaseEvents();
 
-  //(HTML only)[SameObject] readonly attribute HTMLAllCollection all;
+  [SameObject] readonly attribute HTMLAllCollection all;
 };
 
 // https://fullscreen.spec.whatwg.org/#api
 partial interface Document {
   // Note: Per spec the 'S' in these two is lowercase, but the "Moz"
   // versions have it uppercase.
   [LenientSetter, Unscopable, Func="Document::IsUnprefixedFullscreenEnabled"]
   readonly attribute boolean fullscreen;
--- a/dom/webidl/HTMLDocument.webidl
+++ b/dom/webidl/HTMLDocument.webidl
@@ -4,18 +4,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 [OverrideBuiltins]
 interface HTMLDocument : Document {
   // DOM tree accessors
   [Throws]
   getter object (DOMString name);
-
-  readonly attribute HTMLAllCollection all;
 };
 
 partial interface HTMLDocument {
   /*
    * Number of nodes that have been blocked by the Safebrowsing API to prevent
    * tracking, cryptomining and so on. This method is for testing only.
    */
   [ChromeOnly, Pure]
--- a/testing/web-platform/meta/html/dom/interfaces.https.html.ini
+++ b/testing/web-platform/meta/html/dom/interfaces.https.html.ini
@@ -1,13 +1,10 @@
 prefs: [dom.security.featurePolicy.enabled:true]
 [interfaces.https.html?include=(Document|Window)]
-  [Document interface: attribute all]
-    expected: FAIL
-
   [Document interface: attribute oncancel]
     expected: FAIL
 
   [Document interface: attribute onsecuritypolicyviolation]
     expected: FAIL
 
   [Document interface: iframe.contentDocument must inherit property "defaultView" with the proper type]
     expected: FAIL
@@ -25,19 +22,16 @@ prefs: [dom.security.featurePolicy.enabl
     expected: FAIL
 
   [Document interface: new Document() must inherit property "oncancel" with the proper type]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "onsecuritypolicyviolation" with the proper type]
     expected: FAIL
 
-  [Document interface: document.implementation.createDocument(null, "", null) must inherit property "all" with the proper type]
-    expected: FAIL
-
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "oncancel" with the proper type]
     expected: FAIL
 
   [Document interface: document.implementation.createDocument(null, "", null) must inherit property "onsecuritypolicyviolation" with the proper type]
     expected: FAIL
 
   [Window interface: attribute oncancel]
     expected: FAIL
--- a/testing/web-platform/tests/xhr/responsexml-document-properties.htm
+++ b/testing/web-platform/tests/xhr/responsexml-document-properties.htm
@@ -23,27 +23,31 @@
         referrer:'',
         title:'',
         contentType:'application/xml',
         readyState:'complete',
         location:null,
         defaultView:null,
         body:null,
         doctype:null,
-        all:undefined,
+        all:HTMLAllCollection,
         cookie:''
       }
 
       for (var name in expected) {
         runTest(name, expected[name])
       }
 
       function runTest(name, value){
         test(function(){
-          assert_equals(client.responseXML[name], value)
+          if (name == "all") {
+            assert_equals(client.responseXML[name].__proto__, value.prototype)
+          } else {
+            assert_equals(client.responseXML[name], value)
+          }
         }, name)
       }
 
       async_test(t => {
         const client = new XMLHttpRequest();
         client.open("GET", "resources/redirect.py?location=well-formed.xml");
         client.send();
         client.onload = t.step_func_done(() => {