Skip to content

Commit a8f5ebe

Browse files
shannonboothawesomekling
authored andcommitted
LibWeb: Port DOM::Node from DeprecatedString
1 parent 89bbf53 commit a8f5ebe

File tree

8 files changed

+26
-27
lines changed

8 files changed

+26
-27
lines changed

Userland/Libraries/LibWeb/DOM/Document.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ DeprecatedString Document::title() const
720720
// element that is a child of the document element.
721721
if (auto const* document_element = this->document_element(); is<SVG::SVGElement>(document_element)) {
722722
if (auto const* title_element = document_element->first_child_of_type<SVG::SVGTitleElement>())
723-
value = title_element->child_text_content();
723+
value = title_element->child_text_content().to_deprecated_string();
724724
}
725725

726726
// 2. Otherwise, let value be the child text content of the title element, or the empty string if the title element
@@ -761,7 +761,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
761761
}
762762

763763
// 3. String replace all with the given value within element.
764-
element->string_replace_all(title.to_deprecated_string());
764+
element->string_replace_all(title);
765765
}
766766

767767
// -> If the document element is in the HTML namespace
@@ -790,7 +790,7 @@ WebIDL::ExceptionOr<void> Document::set_title(String const& title)
790790
}
791791

792792
// 4. String replace all with the given value within element.
793-
element->string_replace_all(title.to_deprecated_string());
793+
element->string_replace_all(title);
794794
}
795795

796796
// -> Otherwise

Userland/Libraries/LibWeb/DOM/Node.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void Node::set_text_content(Optional<String> const& maybe_content)
179179
{
180180
// The textContent setter steps are to, if the given value is null, act as if it was the empty string instead,
181181
// and then do as described below, switching on the interface this implements:
182-
auto content = maybe_content.value_or(String {}).to_deprecated_string();
182+
auto content = maybe_content.value_or(String {});
183183

184184
// If DocumentFragment or Element, string replace all with the given value within this.
185185
if (is<DocumentFragment>(this) || is<Element>(this)) {
@@ -190,15 +190,15 @@ void Node::set_text_content(Optional<String> const& maybe_content)
190190
else if (is<CharacterData>(this)) {
191191

192192
auto* character_data_node = verify_cast<CharacterData>(this);
193-
character_data_node->set_data(MUST(String::from_deprecated_string(content)));
193+
character_data_node->set_data(content);
194194

195195
// FIXME: CharacterData::set_data is not spec compliant. Make this match the spec when set_data becomes spec compliant.
196196
// Do note that this will make this function able to throw an exception.
197197
}
198198

199199
// If Attr, set an existing attribute value with this and the given value.
200200
if (is<Attr>(*this)) {
201-
static_cast<Attr&>(*this).set_value(MUST(String::from_deprecated_string(content)));
201+
static_cast<Attr&>(*this).set_value(content);
202202
}
203203

204204
// Otherwise, do nothing.
@@ -278,10 +278,10 @@ void Node::invalidate_style()
278278
document().schedule_style_update();
279279
}
280280

281-
DeprecatedString Node::child_text_content() const
281+
String Node::child_text_content() const
282282
{
283283
if (!is<ParentNode>(*this))
284-
return DeprecatedString::empty();
284+
return String {};
285285

286286
StringBuilder builder;
287287
verify_cast<ParentNode>(*this).for_each_child([&](auto& child) {
@@ -291,7 +291,7 @@ DeprecatedString Node::child_text_content() const
291291
builder.append(maybe_content.value());
292292
}
293293
});
294-
return builder.to_deprecated_string();
294+
return MUST(builder.to_string());
295295
}
296296

297297
// https://dom.spec.whatwg.org/#concept-tree-root
@@ -1316,14 +1316,14 @@ void Node::replace_all(JS::GCPtr<Node> node)
13161316
}
13171317

13181318
// https://dom.spec.whatwg.org/#string-replace-all
1319-
void Node::string_replace_all(DeprecatedString const& string)
1319+
void Node::string_replace_all(String const& string)
13201320
{
13211321
// 1. Let node be null.
13221322
JS::GCPtr<Node> node;
13231323

13241324
// 2. If string is not the empty string, then set node to a new Text node whose data is string and node document is parent’s node document.
13251325
if (!string.is_empty())
1326-
node = heap().allocate<Text>(realm(), document(), MUST(String::from_deprecated_string(string)));
1326+
node = heap().allocate<Text>(realm(), document(), string);
13271327

13281328
// 3. Replace all with node within parent.
13291329
replace_all(node);
@@ -1471,18 +1471,18 @@ JS::NonnullGCPtr<Node> Node::get_root_node(GetRootNodeOptions const& options)
14711471
return root();
14721472
}
14731473

1474-
DeprecatedString Node::debug_description() const
1474+
String Node::debug_description() const
14751475
{
14761476
StringBuilder builder;
14771477
builder.append(node_name().to_deprecated_fly_string().to_lowercase());
14781478
if (is_element()) {
1479-
auto& element = static_cast<DOM::Element const&>(*this);
1479+
auto const& element = static_cast<DOM::Element const&>(*this);
14801480
if (auto id = element.get_attribute(HTML::AttributeNames::id); id.has_value())
14811481
builder.appendff("#{}", id.value());
14821482
for (auto const& class_name : element.class_names())
14831483
builder.appendff(".{}", class_name);
14841484
}
1485-
return builder.to_deprecated_string();
1485+
return MUST(builder.to_string());
14861486
}
14871487

14881488
// https://dom.spec.whatwg.org/#concept-node-length
@@ -1935,9 +1935,9 @@ ErrorOr<String> Node::accessible_description(Document const& document) const
19351935
return builder.to_string();
19361936
}
19371937

1938-
Optional<StringView> Node::first_valid_id(DeprecatedString const& value, Document const& document)
1938+
Optional<StringView> Node::first_valid_id(StringView value, Document const& document)
19391939
{
1940-
auto id_list = value.split_view(Infra::is_ascii_whitespace);
1940+
auto id_list = value.split_view_if(Infra::is_ascii_whitespace);
19411941
for (auto const& id : id_list) {
19421942
if (document.get_element_by_id(MUST(FlyString::from_utf8(id))))
19431943
return id;

Userland/Libraries/LibWeb/DOM/Node.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#pragma once
88

99
#include <AK/Badge.h>
10-
#include <AK/DeprecatedString.h>
1110
#include <AK/FlyString.h>
1211
#include <AK/JsonObjectSerializer.h>
1312
#include <AK/RefPtr.h>
@@ -161,7 +160,7 @@ class Node : public EventTarget {
161160
const HTML::HTMLElement* enclosing_html_element() const;
162161
const HTML::HTMLElement* enclosing_html_element_with_attribute(FlyString const&) const;
163162

164-
DeprecatedString child_text_content() const;
163+
String child_text_content() const;
165164

166165
Node& root();
167166
Node const& root() const
@@ -242,7 +241,7 @@ class Node : public EventTarget {
242241
WebIDL::ExceptionOr<String> serialize_fragment(DOMParsing::RequireWellFormed) const;
243242

244243
void replace_all(JS::GCPtr<Node>);
245-
void string_replace_all(DeprecatedString const&);
244+
void string_replace_all(String const&);
246245

247246
bool is_same_node(Node const*) const;
248247
bool is_equal_node(Node const*) const;
@@ -251,7 +250,7 @@ class Node : public EventTarget {
251250

252251
bool is_uninteresting_whitespace_node() const;
253252

254-
DeprecatedString debug_description() const;
253+
String debug_description() const;
255254

256255
size_t length() const;
257256

@@ -707,7 +706,7 @@ class Node : public EventTarget {
707706
void append_child_impl(JS::NonnullGCPtr<Node>);
708707
void remove_child_impl(JS::NonnullGCPtr<Node>);
709708

710-
static Optional<StringView> first_valid_id(DeprecatedString const&, Document const&);
709+
static Optional<StringView> first_valid_id(StringView, Document const&);
711710
static ErrorOr<void> append_without_space(StringBuilder, StringView const&);
712711
static ErrorOr<void> append_with_space(StringBuilder, StringView const&);
713712
static ErrorOr<void> prepend_without_space(StringBuilder, StringView const&);

Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ String HTMLAnchorElement::text() const
114114
void HTMLAnchorElement::set_text(String const& text)
115115
{
116116
// The text attribute's setter must string replace all with the given value within this element.
117-
string_replace_all(text.to_deprecated_string());
117+
string_replace_all(text);
118118
}
119119

120120
// https://html.spec.whatwg.org/multipage/text-level-semantics.html#dom-a-referrerpolicy

Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ String HTMLOptionElement::text() const
106106
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text
107107
void HTMLOptionElement::set_text(String const& text)
108108
{
109-
string_replace_all(text.to_deprecated_string());
109+
string_replace_all(text);
110110
}
111111

112112
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-index

Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ void HTMLScriptElement::prepare_script()
429429

430430
// 2. Fetch an inline module script graph, given source text, base URL, settings object, options, and with the following steps given result:
431431
// FIXME: Pass options
432-
fetch_inline_module_script_graph(realm(), m_document->url().to_deprecated_string(), source_text, base_url, document().relevant_settings_object(), steps);
432+
fetch_inline_module_script_graph(realm(), m_document->url().to_deprecated_string(), source_text.to_deprecated_string(), base_url, document().relevant_settings_object(), steps);
433433
}
434434
// -> "importmap"
435435
else if (m_script_type == ScriptType::ImportMap) {

Userland/Libraries/LibWeb/HTML/HTMLTitleElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ void HTMLTitleElement::children_changed()
3838
DeprecatedString HTMLTitleElement::text()
3939
{
4040
// The text attribute's getter must return this title element's child text content.
41-
return child_text_content();
41+
return child_text_content().to_deprecated_string();
4242
}
4343

4444
// https://html.spec.whatwg.org/multipage/semantics.html#dom-title-text
4545
void HTMLTitleElement::set_text(String const& value)
4646
{
4747
// The text attribute's setter must string replace all with the given value within this title element.
48-
string_replace_all(value.to_deprecated_string());
48+
string_replace_all(value);
4949
}
5050

5151
}

Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Optional<TextAnchor> SVGTextContentElement::text_anchor() const
4747

4848
DeprecatedString SVGTextContentElement::text_contents() const
4949
{
50-
return child_text_content().trim_whitespace();
50+
return child_text_content().to_deprecated_string().trim_whitespace();
5151
}
5252

5353
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars

0 commit comments

Comments
 (0)