Bug 1414000 - Assert that either the pres context is nullptr OR that there are no properties when filling in base styles; r=hiro

The call stack where this assertion would otherwise fail is as follows:

 KeyframeEffectReadOnly::UpdateProperties
   KeyframeEffectReadOnly::DoUpdateProperties
     KeyframeEffectReadOnly::BuildProperties
       KeyframeUtils::GetAnimationPropertiesFromKeyframes
         KeyframeUtils.cpp::GetComputedKeyframeValues
     KeyframeEffectReadOnly::EnsureBaseStyles

In bug 1407898 we made GetComputedKeyframes return an empty list when the pres
context is nullptr so if we get a null pres context in EnsureBaseStyles (which
uses the same method for getting the pres context:
nsContentUtils::GetContextForContent) we know that |aProperties| will be empty.
Also, if |aProperties| is empty we're not going to dereferences |presContext| so
we don't need to assert that it is non-null.

I have not included the crashtest in this patch for the same reason as described
in bug 1407898 comment 6.

MozReview-Commit-ID: 6OZ2yJfRLMV

--HG--
extra : rebase_source : b2a711a54623ea177560cf1b69b3c332654bc938
This commit is contained in:
Brian Birtles 2017-12-20 17:34:57 +09:00
parent a2baf1925a
commit 235c83fc0c

View File

@ -523,10 +523,19 @@ KeyframeEffectReadOnly::EnsureBaseStyles(
nsPresContext* presContext =
nsContentUtils::GetContextForContent(mTarget->mElement);
MOZ_ASSERT(presContext,
"nsPresContext should not be nullptr since this EnsureBaseStyles "
"supposed to be called right after getting computed values with "
"a valid nsPresContext");
// If |aProperties| is empty we're not going to dereference |presContext| so
// we don't care if it is nullptr.
//
// We could just return early when |aProperties| is empty and save looking up
// the pres context, but that won't save any effort normally since we don't
// call this function if we have no keyframes to begin with. Furthermore, the
// case where |presContext| is nullptr is so rare (we've only ever seen in
// fuzzing, and even then we've never been able to reproduce it reliably)
// it's not worth the runtime cost of an extra branch.
MOZ_ASSERT(presContext || aProperties.IsEmpty(),
"Typically presContext should not be nullptr but if it is"
" we should have also failed to calculate the computed values"
" passed-in as aProperties");
RefPtr<ServoStyleContext> baseStyleContext;
for (const AnimationProperty& property : aProperties) {