diff --git a/Userland/Libraries/LibWeb/DOM/Attr.h b/Userland/Libraries/LibWeb/DOM/Attr.h index 4a264b9b2f..04a970d8fa 100644 --- a/Userland/Libraries/LibWeb/DOM/Attr.h +++ b/Userland/Libraries/LibWeb/DOM/Attr.h @@ -24,7 +24,7 @@ public: virtual ~Attr() override = default; - virtual DeprecatedFlyString node_name() const override { return name(); } + virtual FlyString node_name() const override { return MUST(FlyString::from_deprecated_fly_string(name())); } DeprecatedFlyString const& namespace_uri() const { return m_qualified_name.namespace_(); } DeprecatedFlyString const& prefix() const { return m_qualified_name.prefix(); } diff --git a/Userland/Libraries/LibWeb/DOM/CDATASection.h b/Userland/Libraries/LibWeb/DOM/CDATASection.h index e15f308826..b2d831344a 100644 --- a/Userland/Libraries/LibWeb/DOM/CDATASection.h +++ b/Userland/Libraries/LibWeb/DOM/CDATASection.h @@ -18,7 +18,7 @@ public: virtual ~CDATASection() override; // ^Node - virtual DeprecatedFlyString node_name() const override { return "#cdata-section"; } + virtual FlyString node_name() const override { return "#cdata-section"_fly_string; } private: CDATASection(Document&, String const&); diff --git a/Userland/Libraries/LibWeb/DOM/Comment.h b/Userland/Libraries/LibWeb/DOM/Comment.h index f654d157f7..226a9ef789 100644 --- a/Userland/Libraries/LibWeb/DOM/Comment.h +++ b/Userland/Libraries/LibWeb/DOM/Comment.h @@ -18,7 +18,7 @@ public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&, String const& data); virtual ~Comment() override = default; - virtual DeprecatedFlyString node_name() const override { return "#comment"; } + virtual FlyString node_name() const override { return "#comment"_fly_string; } private: Comment(Document&, String const&); diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 78e2f982d8..5717349f4a 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -706,7 +706,7 @@ DeprecatedString Document::title() const // 2. Otherwise, let value be the child text content of the title element, or the empty string if the title element // is null. else if (auto title_element = this->title_element()) { - value = title_element->text_content(); + value = title_element->text_content().value_or(String {}).to_deprecated_string(); } // 3. Strip and collapse ASCII whitespace in value. diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 3b162cc7ca..25eedd3082 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -130,7 +130,7 @@ public: CSS::StyleSheetList* style_sheets_for_bindings() { return &style_sheets(); } - virtual DeprecatedFlyString node_name() const override { return "#document"; } + virtual FlyString node_name() const override { return "#document"_fly_string; } void set_hovered_node(Node*); Node* hovered_node() { return m_hovered_node.ptr(); } diff --git a/Userland/Libraries/LibWeb/DOM/DocumentFragment.h b/Userland/Libraries/LibWeb/DOM/DocumentFragment.h index f34aa27819..d4832fb0ef 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentFragment.h +++ b/Userland/Libraries/LibWeb/DOM/DocumentFragment.h @@ -23,7 +23,7 @@ public: virtual ~DocumentFragment() override = default; - virtual DeprecatedFlyString node_name() const override { return "#document-fragment"; } + virtual FlyString node_name() const override { return "#document-fragment"_fly_string; } Element* host() { return m_host.ptr(); } Element const* host() const { return m_host.ptr(); } diff --git a/Userland/Libraries/LibWeb/DOM/DocumentType.h b/Userland/Libraries/LibWeb/DOM/DocumentType.h index 236ddadcb6..ceda81d188 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentType.h +++ b/Userland/Libraries/LibWeb/DOM/DocumentType.h @@ -23,7 +23,7 @@ public: virtual ~DocumentType() override = default; - virtual DeprecatedFlyString node_name() const override { return "#doctype"; } + virtual FlyString node_name() const override { return "#doctype"_fly_string; } String const& name() const { return m_name; } void set_name(String const& name) { m_name = name; } diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index fabd955248..aedb1b9a82 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -76,7 +76,7 @@ public: DeprecatedFlyString const& qualified_name() const { return m_qualified_name.as_string(); } DeprecatedString const& html_uppercased_qualified_name() const { return m_html_uppercased_qualified_name; } - virtual DeprecatedFlyString node_name() const final { return html_uppercased_qualified_name(); } + virtual FlyString node_name() const final { return MUST(FlyString::from_deprecated_fly_string(html_uppercased_qualified_name())); } DeprecatedFlyString const& local_name() const { return m_qualified_name.local_name(); } // NOTE: This is for the JS bindings diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 5ca21cd032..28a91030de 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -108,10 +108,10 @@ void Node::visit_edges(Cell::Visitor& visitor) } // https://dom.spec.whatwg.org/#dom-node-baseuri -DeprecatedString Node::base_uri() const +String Node::base_uri() const { // Return this’s node document’s document base URL, serialized. - return document().base_url().to_deprecated_string(); + return MUST(document().base_url().to_string()); } const HTML::HTMLAnchorElement* Node::enclosing_link_element() const @@ -141,18 +141,18 @@ const HTML::HTMLElement* Node::enclosing_html_element_with_attribute(DeprecatedF } // https://dom.spec.whatwg.org/#concept-descendant-text-content -DeprecatedString Node::descendant_text_content() const +String Node::descendant_text_content() const { StringBuilder builder; for_each_in_subtree_of_type([&](auto& text_node) { builder.append(text_node.data()); return IterationDecision::Continue; }); - return builder.to_deprecated_string(); + return MUST(builder.to_string()); } // https://dom.spec.whatwg.org/#dom-node-textcontent -DeprecatedString Node::text_content() const +Optional Node::text_content() const { // The textContent getter steps are to return the following, switching on the interface this implements: @@ -162,21 +162,22 @@ DeprecatedString Node::text_content() const // If CharacterData, return this’s data. if (is(this)) - return static_cast(*this).data(); + return MUST(String::from_deprecated_string(static_cast(*this).data())); // If Attr node, return this's value. if (is(*this)) - return static_cast(*this).value(); + return MUST(String::from_deprecated_string(static_cast(*this).value())); // Otherwise, return null return {}; } // https://dom.spec.whatwg.org/#ref-for-dom-node-textcontent%E2%91%A0 -void Node::set_text_content(DeprecatedString const& content) +void Node::set_text_content(Optional const& maybe_content) { // The textContent setter steps are to, if the given value is null, act as if it was the empty string instead, // and then do as described below, switching on the interface this implements: + auto content = maybe_content.value_or(String {}).to_deprecated_string(); // If DocumentFragment or Element, string replace all with the given value within this. if (is(this) || is(this)) { @@ -205,18 +206,18 @@ void Node::set_text_content(DeprecatedString const& content) } // https://dom.spec.whatwg.org/#dom-node-nodevalue -DeprecatedString Node::node_value() const +Optional Node::node_value() const { // The nodeValue getter steps are to return the following, switching on the interface this implements: // If Attr, return this’s value. if (is(this)) { - return verify_cast(this)->value(); + return MUST(String::from_deprecated_string(verify_cast(this)->value())); } // If CharacterData, return this’s data. if (is(this)) { - return verify_cast(this)->data(); + return MUST(String::from_deprecated_string(verify_cast(this)->data())); } // Otherwise, return null. @@ -224,17 +225,18 @@ DeprecatedString Node::node_value() const } // https://dom.spec.whatwg.org/#ref-for-dom-node-nodevalue%E2%91%A0 -void Node::set_node_value(DeprecatedString const& value) +void Node::set_node_value(Optional const& maybe_value) { // The nodeValue setter steps are to, if the given value is null, act as if it was the empty string instead, // and then do as described below, switching on the interface this implements: + auto value = maybe_value.value_or(String {}); // If Attr, set an existing attribute value with this and the given value. if (is(this)) { - verify_cast(this)->set_value(value); + verify_cast(this)->set_value(value.to_deprecated_string()); } else if (is(this)) { // If CharacterData, replace data with node this, offset 0, count this’s length, and data the given value. - verify_cast(this)->set_data(value); + verify_cast(this)->set_data(value.to_deprecated_string()); } // Otherwise, do nothing. @@ -281,8 +283,11 @@ DeprecatedString Node::child_text_content() const StringBuilder builder; verify_cast(*this).for_each_child([&](auto& child) { - if (is(child)) - builder.append(verify_cast(child).text_content()); + if (is(child)) { + auto maybe_content = verify_cast(child).text_content(); + if (maybe_content.has_value()) + builder.append(maybe_content.value()); + } }); return builder.to_deprecated_string(); } @@ -1149,7 +1154,7 @@ bool Node::is_uninteresting_whitespace_node() const void Node::serialize_tree_as_json(JsonObjectSerializer& object) const { - MUST(object.add("name"sv, node_name().view())); + MUST(object.add("name"sv, node_name())); MUST(object.add("id"sv, id())); if (is_document()) { MUST(object.add("type"sv, "document")); @@ -1465,7 +1470,7 @@ JS::NonnullGCPtr Node::get_root_node(GetRootNodeOptions const& options) DeprecatedString Node::debug_description() const { StringBuilder builder; - builder.append(node_name().to_lowercase()); + builder.append(node_name().to_deprecated_fly_string().to_lowercase()); if (is_element()) { auto& element = static_cast(*this); if (auto id = element.get_attribute(HTML::AttributeNames::id); !id.is_null()) diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 45499ca9b2..62aadf7834 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -136,16 +136,16 @@ public: JS::NonnullGCPtr child_nodes(); Vector> children_as_vector() const; - virtual DeprecatedFlyString node_name() const = 0; + virtual FlyString node_name() const = 0; - DeprecatedString base_uri() const; + String base_uri() const; - DeprecatedString descendant_text_content() const; - DeprecatedString text_content() const; - void set_text_content(DeprecatedString const&); + String descendant_text_content() const; + Optional text_content() const; + void set_text_content(Optional const&); - DeprecatedString node_value() const; - void set_node_value(DeprecatedString const&); + Optional node_value() const; + void set_node_value(Optional const&); JS::GCPtr navigable() const; diff --git a/Userland/Libraries/LibWeb/DOM/Node.idl b/Userland/Libraries/LibWeb/DOM/Node.idl index 688c7fd7fd..b2f290f6c1 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.idl +++ b/Userland/Libraries/LibWeb/DOM/Node.idl @@ -3,7 +3,7 @@ #import // https://dom.spec.whatwg.org/#node -[Exposed=Window, UseDeprecatedAKString] +[Exposed=Window] interface Node : EventTarget { readonly attribute unsigned short nodeType; diff --git a/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.h b/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.h index ad5e448468..a4cfd12eec 100644 --- a/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.h +++ b/Userland/Libraries/LibWeb/DOM/ProcessingInstruction.h @@ -17,7 +17,7 @@ class ProcessingInstruction final : public CharacterData { public: virtual ~ProcessingInstruction() override = default; - virtual DeprecatedFlyString node_name() const override { return m_target; } + virtual FlyString node_name() const override { return MUST(FlyString::from_deprecated_fly_string(m_target)); } DeprecatedString const& target() const { return m_target; } diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h index 036fc50d1d..3eedffbd51 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.h +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.h @@ -37,7 +37,7 @@ private: virtual void initialize(JS::Realm&) override; // ^Node - virtual DeprecatedFlyString node_name() const override { return "#shadow-root"; } + virtual FlyString node_name() const override { return "#shadow-root"_fly_string; } virtual bool is_shadow_root() const final { return true; } // NOTE: The specification doesn't seem to specify a default value for mode. Assuming closed for now. diff --git a/Userland/Libraries/LibWeb/DOM/StyleElementUtils.cpp b/Userland/Libraries/LibWeb/DOM/StyleElementUtils.cpp index 0f3fbb3084..f9842dfcfd 100644 --- a/Userland/Libraries/LibWeb/DOM/StyleElementUtils.cpp +++ b/Userland/Libraries/LibWeb/DOM/StyleElementUtils.cpp @@ -51,7 +51,7 @@ void StyleElementUtils::update_a_style_block(DOM::Element& style_element) // FIXME: This is a bit awkward, as the spec doesn't actually tell us when to parse the CSS text, // so we just do it here and pass the parsed sheet to create_a_css_style_sheet(). - auto* sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(style_element.document()), style_element.text_content()); + auto* sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(style_element.document()), style_element.text_content().value_or(String {})); if (!sheet) return; diff --git a/Userland/Libraries/LibWeb/DOM/Text.h b/Userland/Libraries/LibWeb/DOM/Text.h index 6e401ff065..90e35dd1c5 100644 --- a/Userland/Libraries/LibWeb/DOM/Text.h +++ b/Userland/Libraries/LibWeb/DOM/Text.h @@ -31,7 +31,7 @@ public: static WebIDL::ExceptionOr> construct_impl(JS::Realm& realm, String const& data); // ^Node - virtual DeprecatedFlyString node_name() const override { return "#text"; } + virtual FlyString node_name() const override { return "#text"_fly_string; } virtual bool is_editable() const override { return m_always_editable || CharacterData::is_editable(); } void set_always_editable(bool b) { m_always_editable = b; } diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 2dcefeb9ab..28b20a57bb 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -144,7 +144,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho else if (is(layout_node.dom_node())) tag_name = verify_cast(*layout_node.dom_node()).local_name(); else - tag_name = layout_node.dom_node()->node_name(); + tag_name = layout_node.dom_node()->node_name().to_deprecated_fly_string(); DeprecatedString identifier = ""; if (layout_node.dom_node() && is(*layout_node.dom_node())) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp index a8b14681ab..f4bb1479b3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp @@ -108,7 +108,7 @@ Optional HTMLAnchorElement::default_role() const String HTMLAnchorElement::text() const { // The text attribute's getter must return this element's descendant text content. - return MUST(String::from_deprecated_string(descendant_text_content())); + return descendant_text_content(); } // https://html.spec.whatwg.org/multipage/text-level-semantics.html#dom-a-text diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index e0b8ae366a..72390694a6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -137,7 +137,7 @@ String HTMLElement::inner_text() // innerText for element being rendered takes visibility into account, so force a layout and then walk the layout tree. document().update_layout(); if (!layout_node()) - return MUST(String::from_deprecated_string(text_content())); + return text_content().value_or(String {}); Function recurse = [&](auto& node) { for (auto* child = node.first_child(); child; child = child->next_sibling()) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp index 8e813be978..7bfd1ddb49 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp @@ -106,7 +106,7 @@ void HTMLTextAreaElement::create_shadow_tree_if_needed() m_text_node->set_editable_text_node_owner(Badge {}, *this); // NOTE: If `children_changed()` was called before now, `m_raw_value` will hold the text content. // Otherwise, it will get filled in whenever that does get called. - m_text_node->set_text_content(m_raw_value); + m_text_node->set_text_content(MUST(String::from_deprecated_string(m_raw_value))); MUST(m_inner_text_element->append_child(*m_text_node)); MUST(element->append_child(*m_inner_text_element)); @@ -122,7 +122,7 @@ void HTMLTextAreaElement::children_changed() if (!m_dirty) { m_raw_value = child_text_content(); if (m_text_node) - m_text_node->set_text_content(m_raw_value); + m_text_node->set_text_content(MUST(String::from_deprecated_string(m_raw_value))); } } diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index 76a5fd4c9d..4dff5726ab 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -81,7 +81,7 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMap {}, m_document); script_element.set_force_async(Badge {}, false); } - if (HTML::TagNames::template_ == m_current_node->node_name()) { + if (HTML::TagNames::template_ == m_current_node->node_name().to_deprecated_fly_string()) { // When an XML parser would append a node to a template element, it must instead append it to the template element's template contents (a DocumentFragment node). MUST(static_cast(*m_current_node).content()->append_child(node)); } else { diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 3595ad9291..6bb62fef3a 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -1164,7 +1164,7 @@ Messages::WebDriverClient::GetElementTextResponse WebDriverConnection::get_eleme auto rendered_text = element->text_content(); // 5. Return success with data rendered text. - return rendered_text; + return rendered_text.value_or(String {}).to_deprecated_string(); } // 12.4.6 Get Element Tag Name, https://w3c.github.io/webdriver/#dfn-get-element-tag-name