Bug 1439223: Stop ShadowRoot::Host from being a useless function call. r?smaug draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 18 Feb 2018 14:33:14 +0100
changeset 756815 4681ad21c548874b64790d767c6a4d0f146ebaad
parent 756814 bca985cf71adf010ee63473f6e5e09ca30e7e49a
child 756816 e00f07d2b7b0ef3e042f0ae136504100adc81819
push id99555
push userbmo:emilio@crisal.io
push dateSun, 18 Feb 2018 13:35:44 +0000
reviewerssmaug
bugs1439223
milestone60.0a1
Bug 1439223: Stop ShadowRoot::Host from being a useless function call. r?smaug Also, change DocumentFragment to use RefPtr, since that's the usual style. MozReview-Commit-ID: 4PQ19nbmhUh
dom/base/DocumentFragment.h
dom/base/ShadowRoot.cpp
dom/base/ShadowRoot.h
--- a/dom/base/DocumentFragment.h
+++ b/dom/base/DocumentFragment.h
@@ -102,16 +102,16 @@ public:
 
 protected:
   virtual ~DocumentFragment()
   {
   }
 
   nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                  bool aPreallocateChildren) const override;
-  nsCOMPtr<Element> mHost;
+  RefPtr<Element> mHost;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 
 #endif // mozilla_dom_DocumentFragment_h__
--- a/dom/base/ShadowRoot.cpp
+++ b/dom/base/ShadowRoot.cpp
@@ -466,26 +466,16 @@ ShadowRoot::GetInnerHTML(nsAString& aInn
 }
 
 void
 ShadowRoot::SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError)
 {
   SetInnerHTMLInternal(aInnerHTML, aError);
 }
 
-Element*
-ShadowRoot::Host()
-{
-  nsIContent* host = GetHost();
-  MOZ_ASSERT(host && host->IsElement(),
-             "ShadowRoot host should always be an element, "
-             "how else did we create this ShadowRoot?");
-  return host->AsElement();
-}
-
 void
 ShadowRoot::AttributeChanged(nsIDocument* aDocument,
                              Element* aElement,
                              int32_t aNameSpaceID,
                              nsAtom* aAttribute,
                              int32_t aModType,
                              const nsAttrValue* aOldValue)
 {
--- a/dom/base/ShadowRoot.h
+++ b/dom/base/ShadowRoot.h
@@ -60,17 +60,23 @@ public:
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
 
   ShadowRoot(Element* aElement, bool aClosed,
              already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
              nsXBLPrototypeBinding* aProtoBinding);
 
   // Shadow DOM v1
-  Element* Host();
+  Element* Host() const
+  {
+    MOZ_ASSERT(GetHost(), "ShadowRoot always has a host, how did we create "
+                          "this ShadowRoot?");
+    return GetHost();
+  }
+
   ShadowRootMode Mode() const
   {
     return mMode;
   }
   bool IsClosed() const
   {
     return mMode == ShadowRootMode::Closed;
   }