Bug 1326023 - Make Element::GetBindingURL return a strong reference. r?smaug draft
authorCameron McCormack <cam@mcc.id.au>
Wed, 28 Dec 2016 17:50:44 +0800
changeset 454454 73926f83448cd12541bf1648ce6f121c2744731f
parent 454453 db38dbe32679ad449fecadf6e5f8501d6a0d7234
child 540709 90189bc08b3c21110447fecbd92fba3b1c285f79
push id39930
push userbmo:cam@mcc.id.au
push dateThu, 29 Dec 2016 09:53:21 +0000
reviewerssmaug
bugs1326023
milestone53.0a1
Bug 1326023 - Make Element::GetBindingURL return a strong reference. r?smaug MozReview-Commit-ID: 5QI6UuvwDrE
dom/base/Element.cpp
dom/base/Element.h
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -443,27 +443,25 @@ Element::GetBindingURL(nsIDocument *aDoc
   // (i.e. object, embed, or applet).
   bool isXULorPluginElement = (IsXULElement() ||
                                IsHTMLElement(nsGkAtoms::object) ||
                                IsHTMLElement(nsGkAtoms::embed) ||
                                IsHTMLElement(nsGkAtoms::applet));
   nsCOMPtr<nsIPresShell> shell = aDocument->GetShell();
   if (!shell || GetPrimaryFrame() || !isXULorPluginElement) {
     *aResult = nullptr;
-
     return true;
   }
 
   // Get the computed -moz-binding directly from the style context
   RefPtr<nsStyleContext> sc =
     nsComputedDOMStyle::GetStyleContextForElementNoFlush(this, nullptr, shell);
   NS_ENSURE_TRUE(sc, false);
 
-  *aResult = sc->StyleDisplay()->mBinding;
-
+  NS_IF_ADDREF(*aResult = sc->StyleDisplay()->mBinding);
   return true;
 }
 
 JSObject*
 Element::WrapObject(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
 {
   JS::Rooted<JSObject*> givenProto(aCx, aGivenProto);
   JS::Rooted<JSObject*> customProto(aCx);
@@ -530,18 +528,18 @@ Element::WrapObject(JSContext *aCx, JS::
     // run script if we also removed the binding from the PAQ queue, but that
     // seems like a scary change that would mosly just add more
     // inconsistencies.
     return obj;
   }
 
   // Make sure the style context goes away _before_ we load the binding
   // since that can destroy the relevant presshell.
-  mozilla::css::URLValue *bindingURL;
-  bool ok = GetBindingURL(doc, &bindingURL);
+  RefPtr<css::URLValue> bindingURL;
+  bool ok = GetBindingURL(doc, getter_AddRefs(bindingURL));
   if (!ok) {
     dom::Throw(aCx, NS_ERROR_FAILURE);
     return nullptr;
   }
 
   if (!bindingURL) {
     // No binding, nothing left to do here.
     return obj;
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -382,17 +382,17 @@ public:
      * SetDirectionality for every element, and UpdateState is very very slow
      * for some elements.
      */
     if (aNotify) {
       UpdateState(true);
     }
   }
 
-  bool GetBindingURL(nsIDocument *aDocument, css::URLValue **aResult);
+  bool GetBindingURL(nsIDocument* aDocument, css::URLValue **aResult);
 
   // The bdi element defaults to dir=auto if it has no dir attribute set.
   // Other elements will only have dir=auto if they have an explicit dir=auto,
   // which will mean that HasValidDir() returns true but HasFixedDir() returns
   // false
   inline bool HasDirAuto() const {
     return (!HasFixedDir() &&
             (HasValidDir() || IsHTMLElement(nsGkAtoms::bdi)));