Pārlūkot izejas kodu

LibWeb: Remove duplicated HTMLInputElement::name

This is already implemented by Element with a cache. Remove it - and
make use of this function where applicable.
Shannon Booth 1 gadu atpakaļ
vecāks
revīzija
2a94cddb02

+ 2 - 2
Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp

@@ -125,8 +125,8 @@ WebIDL::ExceptionOr<Optional<Vector<XHR::FormDataEntry>>> construct_entry_list(J
                 value = "on"_string;
 
             // 2. Create an entry with name and value, and append it to entry list.
-            auto checkbox_or_radio_element_name = TRY_OR_THROW_OOM(vm, String::from_byte_string(checkbox_or_radio_element->name()));
-            entry_list.append(XHR::FormDataEntry { .name = move(checkbox_or_radio_element_name), .value = move(value) });
+            auto checkbox_or_radio_element_name = checkbox_or_radio_element->name();
+            entry_list.append(XHR::FormDataEntry { .name = checkbox_or_radio_element_name->to_string(), .value = move(value) });
         }
         // 8. Otherwise, if the field element is an input element whose type attribute is in the File Upload state, then:
         else if (auto* file_element = dynamic_cast<HTML::HTMLInputElement*>(control.ptr()); file_element && file_element->type_state() == HTMLInputElement::TypeAttributeState::FileUpload) {

+ 4 - 7
Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp

@@ -965,9 +965,9 @@ static bool is_in_same_radio_button_group(HTML::HTMLInputElement const& a, HTML:
         && a.form() == b.form()
         // - They both have a name attribute, their name attributes are not empty, and the
         // value of a's name attribute equals the value of b's name attribute.
-        && a.has_attribute(HTML::AttributeNames::name)
-        && b.has_attribute(HTML::AttributeNames::name)
-        && non_empty_equals(a.name(), b.name()));
+        && a.name().has_value()
+        && b.name().has_value()
+        && non_empty_equals(a.name().value(), b.name().value()));
 }
 
 // https://html.spec.whatwg.org/multipage/input.html#radio-button-state-(type=radio)
@@ -979,8 +979,7 @@ void HTMLInputElement::set_checked_within_group()
     set_checked(true, ChangeSource::User);
 
     // No point iterating the tree if we have an empty name.
-    auto name = this->name();
-    if (name.is_empty())
+    if (!name().has_value() || name()->is_empty())
         return;
 
     document().for_each_in_inclusive_subtree_of_type<HTML::HTMLInputElement>([&](auto& element) {
@@ -1010,8 +1009,6 @@ void HTMLInputElement::legacy_pre_activation_behavior()
     // has its checkedness set to true, if any, and then set this element's
     // checkedness to true.
     if (type_state() == TypeAttributeState::RadioButton) {
-        ByteString name = this->name();
-
         document().for_each_in_inclusive_subtree_of_type<HTML::HTMLInputElement>([&](auto& element) {
             if (element.checked() && is_in_same_radio_button_group(*this, element)) {
                 m_legacy_pre_activation_behavior_checked_element_in_group = &element;

+ 0 - 1
Userland/Libraries/LibWeb/HTML/HTMLInputElement.h

@@ -65,7 +65,6 @@ public:
     WebIDL::ExceptionOr<void> set_type(String const&);
 
     ByteString default_value() const { return deprecated_attribute(HTML::AttributeNames::value); }
-    ByteString name() const { return deprecated_attribute(HTML::AttributeNames::name); }
 
     virtual String value() const override;
     WebIDL::ExceptionOr<void> set_value(String const&);