From 235c83fc0cee024c181f08a0cc78019e34497585 Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Wed, 20 Dec 2017 17:34:57 +0900 Subject: [PATCH] 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 --- dom/animation/KeyframeEffectReadOnly.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dom/animation/KeyframeEffectReadOnly.cpp b/dom/animation/KeyframeEffectReadOnly.cpp index aefad6229c1e..1f3687c3264a 100644 --- a/dom/animation/KeyframeEffectReadOnly.cpp +++ b/dom/animation/KeyframeEffectReadOnly.cpp @@ -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 baseStyleContext; for (const AnimationProperty& property : aProperties) {