Bug 1270310 - Part 3: Make string assignment in HTMLInputElement::GetValueInternal fallible. r=peterv

This makes the string assignment fallible and also adds checks for the return
value from GetValueInternal and GetValue.
This commit is contained in:
Eric Rahm
2016-05-20 16:15:52 -07:00
parent 60a1d1bb37
commit 81d8432217
3 changed files with 23 additions and 8 deletions

View File

@@ -1527,7 +1527,10 @@ HTMLInputElement::SetWidth(uint32_t aWidth)
NS_IMETHODIMP
HTMLInputElement::GetValue(nsAString& aValue)
{
GetValueInternal(aValue);
nsresult rv = GetValueInternal(aValue);
if (NS_FAILED(rv)) {
return rv;
}
// Don't return non-sanitized value for types that are experimental on mobile.
if (IsExperimentalMobileType(mType)) {
@@ -1544,8 +1547,8 @@ HTMLInputElement::GetValueInternal(nsAString& aValue) const
case VALUE_MODE_VALUE:
if (IsSingleLineTextControl(false)) {
mInputData.mState->GetValue(aValue, true);
} else {
aValue.Assign(mInputData.mValue);
} else if (!aValue.Assign(mInputData.mValue, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
@@ -1681,6 +1684,15 @@ HTMLInputElement::GetValueAsDecimal() const
: decimalValue;
}
void
HTMLInputElement::GetValue(nsAString& aValue, ErrorResult& aRv)
{
nsresult rv = GetValue(aValue);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
}
void
HTMLInputElement::SetValue(const nsAString& aValue, ErrorResult& aRv)
{
@@ -5763,9 +5775,12 @@ HTMLInputElement::SaveState()
inputState = new HTMLInputElementState();
nsAutoString value;
GetValue(value);
nsresult rv =
nsLinebreakConverter::ConvertStringLineBreaks(
nsresult rv = GetValue(value);
if (NS_FAILED(rv)) {
return rv;
}
rv = nsLinebreakConverter::ConvertStringLineBreaks(
value,
nsLinebreakConverter::eLinebreakPlatform,
nsLinebreakConverter::eLinebreakContent);