Bug 1270310 - Part 3: Make string assignment in HTMLInputElement::GetValueInternal fallible. r=smaug
This makes the string assignment fallible and also adds checks for the return value from GetValueInternal and GetValue.
This commit is contained in:
@@ -2015,7 +2015,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)) {
|
||||
@@ -2032,8 +2035,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;
|
||||
|
||||
@@ -2169,6 +2172,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)
|
||||
{
|
||||
@@ -6314,9 +6326,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);
|
||||
|
||||
Reference in New Issue
Block a user