Bug 1361951 - Add null check for nsIDocument in ComputeAnimationDistance. draft
authorBoris Chiou <boris.chiou@gmail.com>
Fri, 05 May 2017 11:25:03 +0800
changeset 572983 38b0a4802a1370ebefee297b8b72ab03b790b907
parent 572425 4a6a71f4aa22e4dc3961884ce505ce34bdd799a2
child 627185 84f0776b4d7fad0a88c20f20d62dff50ca3c2853
push id57253
push userbmo:boris.chiou@gmail.com
push dateFri, 05 May 2017 03:30:56 +0000
bugs1361951
milestone55.0a1
Bug 1361951 - Add null check for nsIDocument in ComputeAnimationDistance. MozReview-Commit-ID: GFMmT8bMKzP
dom/base/nsDOMWindowUtils.cpp
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -2685,20 +2685,22 @@ nsDOMWindowUtils::ComputeAnimationDistan
 
   Element* element = content->AsElement();
   AnimationValue v1 = AnimationValue::FromString(property, aValue1, element);
   AnimationValue v2 = AnimationValue::FromString(property, aValue2, element);
   if (v1.IsNull() || v2.IsNull()) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
-  nsIPresShell* shell = element->GetComposedDoc()->GetShell();
-  RefPtr<nsStyleContext> styleContext = shell
-    ? nsComputedDOMStyle::GetStyleContext(element, nullptr, shell)
-    : nullptr;
+  RefPtr<nsStyleContext> styleContext;
+  nsIDocument* doc = element->GetComposedDoc();
+  if (doc && doc->GetShell()) {
+    styleContext =
+      nsComputedDOMStyle::GetStyleContext(element, nullptr, doc->GetShell());
+  }
   *aResult = v1.ComputeDistance(property, v2, styleContext);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetAnimationTypeForLonghand(const nsAString& aProperty,
                                               nsAString& aResult)
 {