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"),
aPresShell->GetDocument());
MOZ_ASSERT(declarations);
parentStyle = aPresShell->StyleSet()->AsServo()->
ResolveForDeclarations(nullptr, declarations);
}
MOZ_RELEASE_ASSERT(parentStyle, "Should have a valid parent style");
MOZ_ASSERT(!aPresShell->IsDestroying(),
- "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 =
ResolveFilterStyleForServo(aString,
parentStyle,
presShell,
aError);
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;
}