mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:37:34 +00:00
LibWeb: Move logic to check if valueAsNumber applies to its own function
This commit is contained in:
parent
c0751b2a49
commit
1a63639518
2 changed files with 20 additions and 2 deletions
|
@ -1206,7 +1206,7 @@ String HTMLInputElement::covert_number_to_string(double input) const
|
||||||
WebIDL::ExceptionOr<double> HTMLInputElement::value_as_number() const
|
WebIDL::ExceptionOr<double> HTMLInputElement::value_as_number() const
|
||||||
{
|
{
|
||||||
// On getting, if the valueAsNumber attribute does not apply, as defined for the input element's type attribute's current state, then return a Not-a-Number (NaN) value.
|
// On getting, if the valueAsNumber attribute does not apply, as defined for the input element's type attribute's current state, then return a Not-a-Number (NaN) value.
|
||||||
if (type_state() != TypeAttributeState::Date || type_state() != TypeAttributeState::Month || type_state() != TypeAttributeState::Week || type_state() != TypeAttributeState::Time || type_state() != TypeAttributeState::LocalDateAndTime || type_state() != TypeAttributeState::Number || type_state() != TypeAttributeState::Range)
|
if (!value_as_number_applies())
|
||||||
return NAN;
|
return NAN;
|
||||||
|
|
||||||
// Otherwise, run the algorithm to convert a string to a number defined for that state to the element's value;
|
// Otherwise, run the algorithm to convert a string to a number defined for that state to the element's value;
|
||||||
|
@ -1222,7 +1222,7 @@ WebIDL::ExceptionOr<void> HTMLInputElement::set_value_as_number(double value)
|
||||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "valueAsNumber: Value is infinite"sv };
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "valueAsNumber: Value is infinite"sv };
|
||||||
|
|
||||||
// Otherwise, if the valueAsNumber attribute does not apply, as defined for the input element's type attribute's current state, then throw an "InvalidStateError" DOMException.
|
// Otherwise, if the valueAsNumber attribute does not apply, as defined for the input element's type attribute's current state, then throw an "InvalidStateError" DOMException.
|
||||||
if (type_state() != TypeAttributeState::Date || type_state() != TypeAttributeState::Month || type_state() != TypeAttributeState::Week || type_state() != TypeAttributeState::Time || type_state() != TypeAttributeState::LocalDateAndTime || type_state() != TypeAttributeState::Number || type_state() != TypeAttributeState::Range)
|
if (!value_as_number_applies())
|
||||||
return WebIDL::InvalidStateError::create(realm(), "valueAsNumber: Invalid input type used"_fly_string);
|
return WebIDL::InvalidStateError::create(realm(), "valueAsNumber: Invalid input type used"_fly_string);
|
||||||
|
|
||||||
// Otherwise, if the new value is a Not-a-Number (NaN) value, then set the value of the element to the empty string.
|
// Otherwise, if the new value is a Not-a-Number (NaN) value, then set the value of the element to the empty string.
|
||||||
|
@ -1411,4 +1411,21 @@ bool HTMLInputElement::change_event_applies() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/input.html#the-input-element:dom-input-valueasnumber-3
|
||||||
|
bool HTMLInputElement::value_as_number_applies() const
|
||||||
|
{
|
||||||
|
switch (type_state()) {
|
||||||
|
case TypeAttributeState::Date:
|
||||||
|
case TypeAttributeState::Month:
|
||||||
|
case TypeAttributeState::Week:
|
||||||
|
case TypeAttributeState::Time:
|
||||||
|
case TypeAttributeState::LocalDateAndTime:
|
||||||
|
case TypeAttributeState::Number:
|
||||||
|
case TypeAttributeState::Range:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,6 +160,7 @@ public:
|
||||||
|
|
||||||
bool has_input_activation_behavior() const;
|
bool has_input_activation_behavior() const;
|
||||||
bool change_event_applies() const;
|
bool change_event_applies() const;
|
||||||
|
bool value_as_number_applies() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HTMLInputElement(DOM::Document&, DOM::QualifiedName);
|
HTMLInputElement(DOM::Document&, DOM::QualifiedName);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue