diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 5d52dbd91c72..b761ab192ae0 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -91,6 +91,7 @@ #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" @@ -2004,6 +2005,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(Document) 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) @@ -5632,6 +5634,13 @@ 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 inStrmChan = do_QueryInterface(mChannel); diff --git a/dom/base/Document.h b/dom/base/Document.h index b657e80400b8..a5ad5781f158 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -185,6 +185,7 @@ class FeaturePolicy; class FontFaceSet; class FrameRequestCallback; class ImageTracker; +class HTMLAllCollection; class HTMLBodyElement; class HTMLSharedElement; class HTMLImageElement; @@ -3582,6 +3583,8 @@ class Document : public nsINode, 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); @@ -5215,6 +5218,8 @@ class Document : public nsINode, RefPtr mXULBroadcastManager; RefPtr mXULPersist; + RefPtr mAll; + // document lightweight theme for use with :-moz-lwtheme, // :-moz-lwtheme-brighttext and :-moz-lwtheme-darktext DocumentTheme mDocLWTheme; diff --git a/dom/html/HTMLAllCollection.cpp b/dom/html/HTMLAllCollection.cpp index 675898020d06..413d25a41998 100644 --- a/dom/html/HTMLAllCollection.cpp +++ b/dom/html/HTMLAllCollection.cpp @@ -8,13 +8,15 @@ #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); } diff --git a/dom/html/HTMLAllCollection.h b/dom/html/HTMLAllCollection.h index e999cfc30db4..b8b4269b5bd1 100644 --- a/dom/html/HTMLAllCollection.h +++ b/dom/html/HTMLAllCollection.h @@ -15,12 +15,12 @@ #include class nsContentList; -class nsHTMLDocument; class nsINode; namespace mozilla { namespace dom { +class Document; class Element; class OwningHTMLCollectionOrElement; template @@ -32,7 +32,7 @@ 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) @@ -80,7 +80,7 @@ class HTMLAllCollection final : public nsISupports, public nsWrapperCache { */ Element* Item(uint32_t aIndex); - RefPtr mDocument; + RefPtr mDocument; RefPtr mCollection; nsRefPtrHashtable mNamedMap; }; diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index ca39d3ceb131..bec9899817b6 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -9,7 +9,6 @@ #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" @@ -158,10 +157,6 @@ nsHTMLDocument::nsHTMLDocument() 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 aGivenProto) { return HTMLDocument_Binding::Wrap(aCx, this, aGivenProto); @@ -780,13 +775,6 @@ bool nsHTMLDocument::MatchFormControls(Element* aElement, int32_t aNamespaceID, 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, diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h index fc05cad6523c..831bd71a5d90 100644 --- a/dom/html/nsHTMLDocument.h +++ b/dom/html/nsHTMLDocument.h @@ -27,7 +27,6 @@ class nsILoadGroup; namespace mozilla { namespace dom { -class HTMLAllCollection; template struct Nullable; class WindowProxyHolder; @@ -49,9 +48,6 @@ class nsHTMLDocument : public mozilla::dom::Document { 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, @@ -73,8 +69,6 @@ class nsHTMLDocument : public mozilla::dom::Document { 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 aRetval, @@ -172,8 +166,6 @@ class nsHTMLDocument : public mozilla::dom::Document { friend class ContentListHolder; ContentListHolder* mContentListHolder; - RefPtr mAll; - /** # of forms in the document, synchronously set */ int32_t mNumForms; diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index 006a2990ce97..4a4c55810da5 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -276,7 +276,7 @@ partial interface Document { void captureEvents(); void releaseEvents(); - //(HTML only)[SameObject] readonly attribute HTMLAllCollection all; + [SameObject] readonly attribute HTMLAllCollection all; }; // https://fullscreen.spec.whatwg.org/#api diff --git a/dom/webidl/HTMLDocument.webidl b/dom/webidl/HTMLDocument.webidl index ddc2e2d3c627..5b26fe71fb52 100644 --- a/dom/webidl/HTMLDocument.webidl +++ b/dom/webidl/HTMLDocument.webidl @@ -9,8 +9,6 @@ interface HTMLDocument : Document { // DOM tree accessors [Throws] getter object (DOMString name); - - readonly attribute HTMLAllCollection all; }; partial interface HTMLDocument { diff --git a/testing/web-platform/meta/html/dom/interfaces.https.html.ini b/testing/web-platform/meta/html/dom/interfaces.https.html.ini index 84c68fe7331c..a4af994a7cc6 100644 --- a/testing/web-platform/meta/html/dom/interfaces.https.html.ini +++ b/testing/web-platform/meta/html/dom/interfaces.https.html.ini @@ -1,8 +1,5 @@ prefs: [dom.security.featurePolicy.enabled:true] [interfaces.https.html?include=(Document|Window)] - [Document interface: attribute all] - expected: FAIL - [Document interface: attribute oncancel] expected: FAIL @@ -30,9 +27,6 @@ prefs: [dom.security.featurePolicy.enabled:true] [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 diff --git a/testing/web-platform/tests/xhr/responsexml-document-properties.htm b/testing/web-platform/tests/xhr/responsexml-document-properties.htm index 9071fab121fc..c27a4482cd20 100644 --- a/testing/web-platform/tests/xhr/responsexml-document-properties.htm +++ b/testing/web-platform/tests/xhr/responsexml-document-properties.htm @@ -28,7 +28,7 @@ defaultView:null, body:null, doctype:null, - all:undefined, + all:HTMLAllCollection, cookie:'' } @@ -38,7 +38,11 @@ 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) }