Bug 1461974: Account for ongoing shell destruction on both code paths. r?hiro draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 16 May 2018 16:51:28 +0200
changeset 795760 004b630a80bdfbced1e900801c0e460ea38bdf8c
parent 795759 ccbd56763120fdb75b30dc0174f9187dac3ee725
push id110064
push userbmo:emilio@crisal.io
push dateWed, 16 May 2018 14:54:04 +0000
reviewershiro
bugs1461974
milestone62.0a1
Bug 1461974: Account for ongoing shell destruction on both code paths. r?hiro If the shell is being destroyed and the canvas is not in the doc then we may try to call ResolveForDeclarations on a being-destroyed shell. MozReview-Commit-ID: 51sB49Tgepw
dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2695,33 +2695,33 @@ GetFontStyleForServo(Element* aElement, 
 
   ServoStyleSet* styleSet = aPresShell->StyleSet();
 
   RefPtr<ComputedStyle> parentStyle;
   // have to get a parent ComputedStyle for inherit-like relative
   // values (2em, bolder, etc.)
   if (aElement && aElement->IsInComposedDoc()) {
     parentStyle = nsComputedDOMStyle::GetComputedStyle(aElement, nullptr);
-    if (!parentStyle) {
-      // The flush killed the shell, so we couldn't get any meaningful style
-      // back.
-      aError.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
   } else {
     RefPtr<RawServoDeclarationBlock> declarations =
       CreateFontDeclarationForServo(NS_LITERAL_STRING("10px sans-serif"),
                                     aPresShell->GetDocument());
     MOZ_ASSERT(declarations);
-
-    parentStyle = aPresShell->StyleSet()->
-      ResolveForDeclarations(nullptr, declarations);
-  }
-
-  MOZ_RELEASE_ASSERT(parentStyle, "Should have a valid parent style");
+    if (!aPresShell->IsDestroying()) {
+      parentStyle =
+        aPresShell->StyleSet()->ResolveForDeclarations(nullptr, declarations);
+    }
+  }
+
+  if (!parentStyle) {
+    // Either the flush killed the shell, so we couldn't get any meaningful
+    // style back, or the shell was already destroying.
+    aError.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
 
   MOZ_ASSERT(!aPresShell->IsDestroying(),
              "We should have returned an error above if the presshell is "
              "being destroyed.");
 
   RefPtr<ComputedStyle> sc =
     styleSet->ResolveForDeclarations(parentStyle, declarations);