diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index a2aab2061e..c1f8a34ee0 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1252,9 +1252,8 @@ void Document::set_hovered_node(Node* node) JS::NonnullGCPtr Document::get_elements_by_name(String const& name) { - auto deprecated_name = name.to_byte_string(); - return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [deprecated_name](Element const& element) { - return element.name() == deprecated_name; + return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [name](Element const& element) { + return element.name() == name; }); } diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index a52f58449c..cede5c8531 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -459,6 +459,11 @@ void Element::attribute_changed(FlyString const& name, Optional const& v m_id = {}; else m_id = value_or_empty; + } else if (name == HTML::AttributeNames::name) { + if (!value.has_value()) + m_name = {}; + else + m_name = value_or_empty; } else if (name == HTML::AttributeNames::class_) { auto new_classes = value_or_empty.bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace); m_classes.clear(); diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index a4fa22d418..2f7e4a504d 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -174,8 +174,6 @@ public: Layout::NodeWithStyle* layout_node(); Layout::NodeWithStyle const* layout_node() const; - ByteString name() const { return deprecated_attribute(HTML::AttributeNames::name); } - CSS::StyleProperties* computed_css_values() { return m_computed_css_values.ptr(); } CSS::StyleProperties const* computed_css_values() const { return m_computed_css_values.ptr(); } void set_computed_css_values(RefPtr); @@ -368,6 +366,7 @@ public: Directionality directionality() const; Optional const& id() const { return m_id; } + Optional const& name() const { return m_name; } virtual JS::GCPtr> take_lazy_load_resumption_steps(Badge) { @@ -417,6 +416,7 @@ private: Optional m_dir; Optional m_id; + Optional m_name; using PseudoElementLayoutNodes = Array, to_underlying(CSS::Selector::PseudoElement::Type::KnownPseudoElementCount)>; OwnPtr m_pseudo_element_nodes; diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp index d1c12857e6..a0635bf326 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp @@ -84,17 +84,15 @@ Element* HTMLCollection::item(size_t index) const } // https://dom.spec.whatwg.org/#dom-htmlcollection-nameditem-key -Element* HTMLCollection::named_item(FlyString const& name_) const +Element* HTMLCollection::named_item(FlyString const& name) const { - auto name = name_.to_deprecated_fly_string(); - // 1. If key is the empty string, return null. if (name.is_empty()) return nullptr; auto elements = collect_matching_elements(); // 2. Return the first element in the collection for which at least one of the following is true: // - it has an ID which is key; - if (auto it = elements.find_if([&](auto& entry) { return entry->id().has_value() && entry->id().value() == name_; }); it != elements.end()) + if (auto it = elements.find_if([&](auto& entry) { return entry->id().has_value() && entry->id().value() == name; }); it != elements.end()) return *it; // - it is in the HTML namespace and has a name attribute whose value is key; if (auto it = elements.find_if([&](auto& entry) { return entry->namespace_uri() == Namespace::HTML && entry->name() == name; }); it != elements.end()) diff --git a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp index 6faa61899a..c327f996b6 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLFormControlsCollection.cpp @@ -39,8 +39,6 @@ Variant> HTMLFormControlsCollection:: if (name.is_empty()) return {}; - auto const deprecated_name = name.to_deprecated_fly_string(); - // 2. If, at the time the method is called, there is exactly one node in the collection that has either an id attribute or a name attribute equal to name, then return that node and stop the algorithm. // 3. Otherwise, if there are no nodes in the collection that have either an id attribute or a name attribute equal to name, then return null and stop the algorithm. Element* matching_element = nullptr; @@ -48,7 +46,7 @@ Variant> HTMLFormControlsCollection:: auto collection = collect_matching_elements(); for (auto const& element : collection) { - if (element->id() != name && element->name() != deprecated_name) + if (element->id() != name && element->name() != name) continue; if (matching_element) { @@ -68,12 +66,12 @@ Variant> HTMLFormControlsCollection:: // 4. Otherwise, create a new RadioNodeList object representing a live view of the HTMLFormControlsCollection object, further filtered so that the only nodes in the // RadioNodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the RadioNodeList object must be sorted in tree // order. Return that RadioNodeList object. - return JS::make_handle(RadioNodeList::create(realm(), root(), LiveNodeList::Scope::Descendants, [name, deprecated_name](Node const& node) { + return JS::make_handle(RadioNodeList::create(realm(), root(), LiveNodeList::Scope::Descendants, [name](Node const& node) { if (!is(node)) return false; auto const& element = verify_cast(node); - return element.id() == name || element.name() == deprecated_name; + return element.id() == name || element.name() == name; })); } diff --git a/Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp b/Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp index 54e318631b..6d4374e25e 100644 --- a/Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp +++ b/Userland/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp @@ -103,19 +103,17 @@ WebIDL::ExceptionOr>> construct_entry_list(J // FIXME: 3. If the field is a form-associated custom element, then perform the entry construction algorithm given field and entry list, then continue. // 4. If either the field element does not have a name attribute specified, or its name attribute's value is the empty string, then continue. - if (control->name().is_empty()) + if (!control->name().has_value() || control->name()->is_empty()) continue; // 5. Let name be the value of the field element's name attribute. - auto name = TRY_OR_THROW_OOM(vm, String::from_byte_string(control->name())); + auto name = control->name().value(); // 6. If the field element is a select element, then for each option element in the select element's list of options whose selectedness is true and that is not disabled, create an entry with name and the value of the option element, and append it to entry list. if (auto* select_element = dynamic_cast(control.ptr())) { for (auto const& option_element : select_element->list_of_options()) { if (option_element->selected() && !option_element->disabled()) { - auto option_name = TRY_OR_THROW_OOM(vm, String::from_byte_string(option_element->name())); - auto option_value = option_element->value(); - TRY_OR_THROW_OOM(vm, entry_list.try_append(XHR::FormDataEntry { .name = move(option_name), .value = move(option_value) })); + entry_list.append(XHR::FormDataEntry { .name = name.to_string(), .value = option_element->value() }); } } } @@ -128,7 +126,7 @@ WebIDL::ExceptionOr>> construct_entry_list(J // 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())); - TRY_OR_THROW_OOM(vm, entry_list.try_append(XHR::FormDataEntry { .name = move(checkbox_or_radio_element_name), .value = move(value) })); + entry_list.append(XHR::FormDataEntry { .name = move(checkbox_or_radio_element_name), .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(control.ptr()); file_element && file_element->type_state() == HTMLInputElement::TypeAttributeState::FileUpload) { @@ -137,13 +135,13 @@ WebIDL::ExceptionOr>> construct_entry_list(J FileAPI::FilePropertyBag options {}; options.type = "application/octet-stream"_string; auto file = TRY(FileAPI::File::create(realm, {}, String {}, options)); - TRY_OR_THROW_OOM(vm, entry_list.try_append(XHR::FormDataEntry { .name = move(name), .value = JS::make_handle(file) })); + entry_list.append(XHR::FormDataEntry { .name = name.to_string(), .value = JS::make_handle(file) }); } // 2. Otherwise, for each file in selected files, create an entry with name and a File object representing the file, and append it to entry list. else { for (size_t i = 0; i < file_element->files()->length(); i++) { auto file = JS::NonnullGCPtr { *file_element->files()->item(i) }; - TRY_OR_THROW_OOM(vm, entry_list.try_append(XHR::FormDataEntry { .name = move(name), .value = JS::make_handle(file) })); + entry_list.append(XHR::FormDataEntry { .name = name.to_string(), .value = JS::make_handle(file) }); } } } @@ -153,11 +151,11 @@ WebIDL::ExceptionOr>> construct_entry_list(J auto charset = encoding.has_value() ? encoding.value() : "UTF-8"_string; // 2. Create an entry with name and charset, and append it to entry list. - TRY_OR_THROW_OOM(vm, entry_list.try_append(XHR::FormDataEntry { .name = move(name), .value = move(charset) })); + entry_list.append(XHR::FormDataEntry { .name = name.to_string(), .value = move(charset) }); } // 10. Otherwise, create an entry with name and the value of the field element, and append it to entry list. else { - TRY_OR_THROW_OOM(vm, entry_list.try_append(XHR::FormDataEntry { .name = move(name), .value = control_as_form_associated_element->value() })); + entry_list.append(XHR::FormDataEntry { .name = name.to_string(), .value = control_as_form_associated_element->value() }); } // FIXME: 11. If the element has a dirname attribute, and that attribute's value is not the empty string, then: