Remove null-checks for infallible array allocations. (Bug 520234) r=bzbarsky a=blocking2.0:beta7

This commit is contained in:
L. David Baron 2010-09-15 08:11:27 -07:00
parent 22f1628b98
commit 4bf96ebd3a
3 changed files with 8 additions and 62 deletions

View File

@ -1799,11 +1799,6 @@ CSSParserImpl::ParseMediaQueryExpression(nsMediaQuery* aQuery)
// Two integers separated by '/', with optional whitespace on
// either side of the '/'.
nsRefPtr<nsCSSValue::Array> a = nsCSSValue::Array::Create(2);
if (!a) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
SkipUntil(')');
return PR_FALSE;
}
expr->mValue.SetArrayValue(a, eCSSUnit_Array);
// We don't bother with ParseNonNegativeVariant since we have to
// check for != 0 as well; no need to worry about the UngetToken
@ -4520,10 +4515,6 @@ CSSParserImpl::ParseCounter(nsCSSValue& aValue)
nsRefPtr<nsCSSValue::Array> val =
nsCSSValue::Array::Create(unit == eCSSUnit_Counter ? 2 : 3);
if (!val) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
break;
}
val->Item(0).SetStringValue(mToken.mIdent, eCSSUnit_Ident);
@ -6648,10 +6639,6 @@ CSSParserImpl::ParseBorderImage()
// <uri> [<number> | <percentage>]{1,4}
// [ / <border-width>{1,4} ]? [stretch | repeat | round]{0,2}
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(11);
if (!arr) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
return PR_FALSE;
}
nsCSSValue& url = arr->Item(0);
nsCSSValue& splitTop = arr->Item(1);
@ -6935,10 +6922,6 @@ CSSParserImpl::ParseCalc(nsCSSValue &aValue, PRInt32 aVariantMask)
do {
// The toplevel of a calc() is always an nsCSSValue::Array of length 1.
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(1);
if (!arr) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
break;
}
if (!ParseCalcAdditiveExpression(arr->Item(0), aVariantMask))
break;
@ -6993,10 +6976,6 @@ CSSParserImpl::ParseCalcAdditiveExpression(nsCSSValue& aValue,
return PR_FALSE;
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(2);
if (!arr) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
return PR_FALSE;
}
arr->Item(0) = aValue;
storage = &arr->Item(1);
aValue.SetArrayValue(arr, unit);
@ -7098,10 +7077,6 @@ CSSParserImpl::ParseCalcMultiplicativeExpression(nsCSSValue& aValue,
}
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(2);
if (!arr) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
return PR_FALSE;
}
arr->Item(0) = aValue;
storage = &arr->Item(1);
aValue.SetArrayValue(arr, unit);
@ -7671,11 +7646,7 @@ CSSParserImpl::ParseFunction(const nsString &aFunction,
foundValues.Length() + 1 : MAX_ALLOWED_ELEMS);
nsRefPtr<nsCSSValue::Array> convertedArray =
nsCSSValue::Array::Create(numElements);
if (!convertedArray) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
return PR_FALSE;
}
/* Copy things over. */
convertedArray->Item(0).SetStringValue(functionName, eCSSUnit_Ident);
for (PRUint16 index = 0; index + 1 < numElements; ++index)
@ -8519,10 +8490,6 @@ CSSParserImpl::ParseTransitionTimingFunctionValues(nsCSSValue& aValue)
"unexpected initial state");
nsRefPtr<nsCSSValue::Array> val = nsCSSValue::Array::Create(4);
if (!val) {
mScanner.SetLowLevelError(NS_ERROR_OUT_OF_MEMORY);
return PR_FALSE;
}
float x1, x2, y1, y2;
if (!ParseTransitionTimingFunctionValueComponent(x1, ',', PR_TRUE) ||

View File

@ -162,7 +162,6 @@ static nsresult
MakeArray(const nsSize& aSize, nsCSSValue& aResult)
{
nsRefPtr<nsCSSValue::Array> a = nsCSSValue::Array::Create(2);
NS_ENSURE_TRUE(a, NS_ERROR_OUT_OF_MEMORY);
a->Item(0).SetIntValue(aSize.width, eCSSUnit_Integer);
a->Item(1).SetIntValue(aSize.height, eCSSUnit_Integer);

View File

@ -229,25 +229,20 @@ ExtractCalcValue(const nsCSSValue& aValue)
return ExtractCalcValueInternal(aValue);
}
static bool
static void
SetCalcValue(const nsStyleCoord::Calc* aCalc, nsCSSValue& aValue)
{
nsRefPtr<nsCSSValue::Array> arr = nsCSSValue::Array::Create(1);
if (!arr)
return false;
if (!aCalc->mHasPercent) {
nscoordToCSSValue(aCalc->mLength, arr->Item(0));
} else {
nsCSSValue::Array *arr2 = nsCSSValue::Array::Create(2);
if (!arr2)
return false;
arr->Item(0).SetArrayValue(arr2, eCSSUnit_Calc_Plus);
nscoordToCSSValue(aCalc->mLength, arr2->Item(0));
arr2->Item(1).SetPercentValue(aCalc->mPercent);
}
aValue.SetArrayValue(arr, eCSSUnit_Calc);
return true;
}
// CLASS METHODS
@ -785,9 +780,6 @@ AddShadowItems(double aCoeff1, const nsCSSValue &aValue1,
nsCSSValue::Array *array1 = aValue1.GetArrayValue();
nsCSSValue::Array *array2 = aValue2.GetArrayValue();
nsRefPtr<nsCSSValue::Array> resultArray = nsCSSValue::Array::Create(6);
if (!resultArray) {
return PR_FALSE;
}
for (size_t i = 0; i < 4; ++i) {
AddCSSValuePixel(aCoeff1, array1->Item(i), aCoeff2, array2->Item(i),
@ -1463,15 +1455,9 @@ nsStyleAnimation::AddWeighted(nsCSSProperty aProperty,
(aCoeff2 != 0.0 && v2.mHasPercent);
nsCSSValue *val = new nsCSSValue();
nsCSSValue::Array *arr = nsCSSValue::Array::Create(1);
if (!arr) {
return PR_FALSE;
}
val->SetArrayValue(arr, eCSSUnit_Calc);
if (hasPct) {
nsCSSValue::Array *arr2 = nsCSSValue::Array::Create(2);
if (!arr2) {
return PR_FALSE;
}
arr2->Item(0).SetFloatValue(len, eCSSUnit_Pixel);
arr2->Item(1).SetPercentValue(pct);
arr->Item(0).SetArrayValue(arr2, eCSSUnit_Calc_Plus);
@ -2097,8 +2083,7 @@ StyleCoordToValue(const nsStyleCoord& aCoord, nsStyleAnimation::Value& aValue)
break;
case eStyleUnit_Calc: {
nsAutoPtr<nsCSSValue> val(new nsCSSValue);
if (!SetCalcValue(aCoord.GetCalcValue(), *val))
return PR_FALSE;
SetCalcValue(aCoord.GetCalcValue(), *val);
aValue.SetAndAdoptCSSValueValue(val.forget(),
nsStyleAnimation::eUnit_Calc);
break;
@ -2120,8 +2105,7 @@ StyleCoordToCSSValue(const nsStyleCoord& aCoord, nsCSSValue& aCSSValue)
aCSSValue.SetPercentValue(aCoord.GetPercentValue());
break;
case eStyleUnit_Calc:
if (!SetCalcValue(aCoord.GetCalcValue(), aCSSValue))
return PR_FALSE;
SetCalcValue(aCoord.GetCalcValue(), aCSSValue);
break;
default:
NS_ABORT_IF_FALSE(PR_FALSE, "unexpected unit");
@ -2436,8 +2420,7 @@ nsStyleAnimation::ExtractComputedValue(nsCSSProperty aProperty,
calc.mLength = pos.mXPosition.mLength;
calc.mPercent = pos.mXPosition.mPercent;
calc.mHasPercent = PR_TRUE;
if (!SetCalcValue(&calc, item->mXValue))
return PR_FALSE;
SetCalcValue(&calc, item->mXValue);
}
if (pos.mYPosition.mLength == 0) {
item->mYValue.SetPercentValue(pos.mYPosition.mPercent);
@ -2448,8 +2431,7 @@ nsStyleAnimation::ExtractComputedValue(nsCSSProperty aProperty,
calc.mLength = pos.mYPosition.mLength;
calc.mPercent = pos.mYPosition.mPercent;
calc.mHasPercent = PR_TRUE;
if (!SetCalcValue(&calc, item->mYValue))
return PR_FALSE;
SetCalcValue(&calc, item->mYValue);
}
}
@ -2488,8 +2470,7 @@ nsStyleAnimation::ExtractComputedValue(nsCSSProperty aProperty,
calc.mLength = size.mWidth.mLength;
calc.mPercent = size.mWidth.mPercent;
calc.mHasPercent = PR_TRUE;
if (!SetCalcValue(&calc, item->mXValue))
return PR_FALSE;
SetCalcValue(&calc, item->mXValue);
}
break;
}
@ -2512,8 +2493,7 @@ nsStyleAnimation::ExtractComputedValue(nsCSSProperty aProperty,
calc.mLength = size.mHeight.mLength;
calc.mPercent = size.mHeight.mPercent;
calc.mHasPercent = PR_TRUE;
if (!SetCalcValue(&calc, item->mYValue))
return PR_FALSE;
SetCalcValue(&calc, item->mYValue);
}
break;
}