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
|
NS_IMETHODIMP
|
||||||
HTMLInputElement::GetValue(nsAString& aValue)
|
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.
|
// Don't return non-sanitized value for types that are experimental on mobile.
|
||||||
if (IsExperimentalMobileType(mType)) {
|
if (IsExperimentalMobileType(mType)) {
|
||||||
@@ -2032,8 +2035,8 @@ HTMLInputElement::GetValueInternal(nsAString& aValue) const
|
|||||||
case VALUE_MODE_VALUE:
|
case VALUE_MODE_VALUE:
|
||||||
if (IsSingleLineTextControl(false)) {
|
if (IsSingleLineTextControl(false)) {
|
||||||
mInputData.mState->GetValue(aValue, true);
|
mInputData.mState->GetValue(aValue, true);
|
||||||
} else {
|
} else if (!aValue.Assign(mInputData.mValue, fallible)) {
|
||||||
aValue.Assign(mInputData.mValue);
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
@@ -2169,6 +2172,15 @@ HTMLInputElement::GetValueAsDecimal() const
|
|||||||
: decimalValue;
|
: decimalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HTMLInputElement::GetValue(nsAString& aValue, ErrorResult& aRv)
|
||||||
|
{
|
||||||
|
nsresult rv = GetValue(aValue);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
aRv.Throw(rv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
HTMLInputElement::SetValue(const nsAString& aValue, ErrorResult& aRv)
|
HTMLInputElement::SetValue(const nsAString& aValue, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
@@ -6314,9 +6326,12 @@ HTMLInputElement::SaveState()
|
|||||||
|
|
||||||
inputState = new HTMLInputElementState();
|
inputState = new HTMLInputElementState();
|
||||||
nsAutoString value;
|
nsAutoString value;
|
||||||
GetValue(value);
|
nsresult rv = GetValue(value);
|
||||||
nsresult rv =
|
if (NS_FAILED(rv)) {
|
||||||
nsLinebreakConverter::ConvertStringLineBreaks(
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = nsLinebreakConverter::ConvertStringLineBreaks(
|
||||||
value,
|
value,
|
||||||
nsLinebreakConverter::eLinebreakPlatform,
|
nsLinebreakConverter::eLinebreakPlatform,
|
||||||
nsLinebreakConverter::eLinebreakContent);
|
nsLinebreakConverter::eLinebreakContent);
|
||||||
|
|||||||
@@ -632,7 +632,7 @@ public:
|
|||||||
SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
|
SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XPCOM GetValue() is OK
|
void GetValue(nsAString& aValue, ErrorResult& aRv);
|
||||||
void SetValue(const nsAString& aValue, ErrorResult& aRv);
|
void SetValue(const nsAString& aValue, ErrorResult& aRv);
|
||||||
|
|
||||||
Nullable<Date> GetValueAsDate(ErrorResult& aRv);
|
Nullable<Date> GetValueAsDate(ErrorResult& aRv);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ interface HTMLInputElement : HTMLElement {
|
|||||||
attribute DOMString type;
|
attribute DOMString type;
|
||||||
[Pure, SetterThrows]
|
[Pure, SetterThrows]
|
||||||
attribute DOMString defaultValue;
|
attribute DOMString defaultValue;
|
||||||
[Pure, TreatNullAs=EmptyString, SetterThrows]
|
[Pure, TreatNullAs=EmptyString, Throws]
|
||||||
attribute DOMString value;
|
attribute DOMString value;
|
||||||
[Throws, Pref="dom.experimental_forms"]
|
[Throws, Pref="dom.experimental_forms"]
|
||||||
attribute Date? valueAsDate;
|
attribute Date? valueAsDate;
|
||||||
|
|||||||
Reference in New Issue
Block a user