Bug 1254419 - Throw if we fail to allocate memory for a values array in getProperties() draft
authorBrian Birtles <birtles@gmail.com>
Thu, 17 Mar 2016 12:47:14 +0800
changeset 341489 3e519dd3d7426a318c390e3a843fe9c0d11c0ff2
parent 341465 19a3926794a025bbe15c6754bd513d4f08fb7516
child 516403 0662805d4518260110fb992fe44d0e2eb7e2e09e
push id13223
push userbbirtles@mozilla.com
push dateThu, 17 Mar 2016 04:47:28 +0000
bugs1254419
milestone48.0a1
Bug 1254419 - Throw if we fail to allocate memory for a values array in getProperties() MozReview-Commit-ID: BmDC51qWXcu
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffect.h
dom/webidl/KeyframeEffect.webidl
--- 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