Bug 1254419 - Throw if we fail to allocate memory for a values array in getProperties()
MozReview-Commit-ID: BmDC51qWXcu
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -1819,33 +1819,36 @@ CreatePropertyValue(nsCSSProperty aPrope
aResult.mEasing.Construct(NS_LITERAL_STRING("linear"));
}
aResult.mComposite = CompositeOperation::Replace;
}
void
KeyframeEffectReadOnly::GetProperties(
- nsTArray<AnimationPropertyDetails>& aProperties) const
+ nsTArray<AnimationPropertyDetails>& aProperties,
+ ErrorResult& aRv) const
{
for (const AnimationProperty& property : mProperties) {
AnimationPropertyDetails propertyDetails;
propertyDetails.mProperty =
NS_ConvertASCIItoUTF16(nsCSSProps::GetStringValue(property.mProperty));
propertyDetails.mRunningOnCompositor = property.mIsRunningOnCompositor;
nsXPIDLString localizedString;
if (property.mPerformanceWarning &&
property.mPerformanceWarning->ToLocalizedString(localizedString)) {
propertyDetails.mWarning.Construct(localizedString);
}
- if (!propertyDetails.mValues.SetCapacity(
- property.mSegments.Length(), mozilla::fallible)) {
- MOZ_CRASH("Out of memory allocating values array");
+ if (!propertyDetails.mValues.SetCapacity(property.mSegments.Length(),
+ mozilla::fallible)) {
+ aRv.Throw(NS_ERROR_FAILURE);
+ aProperties.Clear();
+ return;
}
for (size_t segmentIdx = 0, segmentLen = property.mSegments.Length();
segmentIdx < segmentLen;
segmentIdx++)
{
const AnimationPropertySegment& segment = property.mSegments[segmentIdx];
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -204,17 +204,18 @@ public:
JS::Handle<JSObject*> aFrames,
const UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
ErrorResult& aRv);
void GetTarget(Nullable<OwningElementOrCSSPseudoElement>& aRv) const;
void GetFrames(JSContext*& aCx,
nsTArray<JSObject*>& aResult,
ErrorResult& aRv);
- void GetProperties(nsTArray<AnimationPropertyDetails>& aProperties) const;
+ void GetProperties(nsTArray<AnimationPropertyDetails>& aProperties,
+ ErrorResult& aRv) const;
// Temporary workaround to return both the target element and pseudo-type
// until we implement PseudoElement (bug 1174575).
void GetTarget(Element*& aTarget,
CSSPseudoElementType& aPseudoType) const {
aTarget = mTarget;
aPseudoType = mPseudoType;
}
--- a/dom/webidl/KeyframeEffect.webidl
+++ b/dom/webidl/KeyframeEffect.webidl
@@ -56,17 +56,17 @@ dictionary AnimationPropertyValueDetails
dictionary AnimationPropertyDetails {
required DOMString property;
required boolean runningOnCompositor;
DOMString warning;
required sequence<AnimationPropertyValueDetails> values;
};
partial interface KeyframeEffectReadOnly {
- [ChromeOnly] sequence<AnimationPropertyDetails> getProperties();
+ [ChromeOnly, Throws] sequence<AnimationPropertyDetails> getProperties();
};
[Func="nsDocument::IsWebAnimationsEnabled",
Constructor ((Element or CSSPseudoElement)? target,
object? frames,
optional (unrestricted double or KeyframeEffectOptions) options)]
interface KeyframeEffect : KeyframeEffectReadOnly {
// Bug 1067769 - Allow setting KeyframeEffect.target