Bug 1441613: Properly check for shell destruction instead of just nonsensically assert. r?hiro draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 28 Feb 2018 11:51:27 +0100
changeset 760924 4e097d17fbccd7f387fffc1fb58ff9fa87e344a4
parent 760923 013a10e7b9ecd135de97259f1af7c6c7aae85c71
push id100772
push userbmo:emilio@crisal.io
push dateWed, 28 Feb 2018 10:54:46 +0000
Bug 1441613: Properly check for shell destruction instead of just nonsensically assert. r?hiro GetStyleContext can flush. As such, that flush can kill the pres shell, and the return value could be null. I have no idea why that code was asserting it didn't happen, but that assert is completely bogus. Throw instead, just like GetFontParentStyleContext used to do for Gecko. MozReview-Commit-ID: 5RxDratKumZ
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2916,30 +2916,37 @@ GetFontStyleForServo(Element* aElement, 
   ServoStyleSet* styleSet = aPresShell->StyleSet()->AsServo();
   RefPtr<nsStyleContext> parentStyle;
   // have to get a parent style context for inherit-like relative
   // values (2em, bolder, etc.)
   if (aElement && aElement->IsInComposedDoc()) {
     parentStyle = nsComputedDOMStyle::GetStyleContext(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"),
     parentStyle = aPresShell->StyleSet()->AsServo()->
       ResolveForDeclarations(nullptr, declarations);
   MOZ_RELEASE_ASSERT(parentStyle, "Should have a valid parent style");
-             "GetFontParentStyleContext should have returned an error if the presshell is being destroyed.");
+             "We should have returned an error above if the presshell is "
+             "being destroyed.");
   RefPtr<ServoStyleContext> sc =
     styleSet->ResolveForDeclarations(parentStyle->AsServo(), declarations);
   // The font getter is required to be reserialized based on what we
   // parsed (including having line-height removed).  (Older drafts of
   // the spec required font sizes be converted to pixels, but that no
   // longer seems to be required.)
@@ -3085,17 +3092,17 @@ CanvasRenderingContext2D::ParseFilter(co
   RefPtr<ServoStyleContext> computedValues =
   if (!computedValues) {
-     return false;
+    return false;
   const nsStyleEffects* effects = computedValues->ComputedData()->GetStyleEffects();
   // XXX: This mFilters is a one shot object, we probably could avoid copying.
   aFilterChain = effects->mFilters;
   return true;