1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:07:36 +00:00

LibWeb: Port Text interface from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-09-06 15:17:20 +12:00 committed by Tim Flynn
parent 6789a2dd8e
commit bcb6851c07
15 changed files with 25 additions and 25 deletions

View file

@ -9,7 +9,7 @@
namespace Web::DOM {
CDATASection::CDATASection(Document& document, DeprecatedString const& data)
CDATASection::CDATASection(Document& document, String const& data)
: Text(document, NodeType::CDATA_SECTION_NODE, data)
{
}

View file

@ -21,7 +21,7 @@ public:
virtual DeprecatedFlyString node_name() const override { return "#cdata-section"; }
private:
CDATASection(Document&, DeprecatedString const&);
CDATASection(Document&, String const&);
virtual void initialize(JS::Realm&) override;
};

View file

@ -118,7 +118,7 @@ JS::NonnullGCPtr<Document> DOMImplementation::create_html_document(Optional<Stri
MUST(head_element->append_child(title_element));
// 2. Append a new Text node, with its data set to title (which could be the empty string) and its node document set to doc, to the title element created earlier.
auto text_node = heap().allocate<Text>(realm(), html_document, title->to_deprecated_string());
auto text_node = heap().allocate<Text>(realm(), html_document, title.value());
MUST(title_element->append_child(*text_node));
}

View file

@ -1422,7 +1422,7 @@ JS::NonnullGCPtr<DocumentFragment> Document::create_document_fragment()
JS::NonnullGCPtr<Text> Document::create_text_node(DeprecatedString const& data)
{
return heap().allocate<Text>(realm(), *this, data);
return heap().allocate<Text>(realm(), *this, MUST(String::from_deprecated_string(data)));
}
JS::NonnullGCPtr<Comment> Document::create_comment(DeprecatedString const& data)

View file

@ -119,7 +119,7 @@ static bool build_image_document(DOM::Document& document, ByteBuffer const& data
MUST(head_element->append_child(title_element));
auto basename = LexicalPath::basename(document.url().serialize_path());
auto title_text = document.heap().allocate<DOM::Text>(document.realm(), document, DeprecatedString::formatted("{} [{}x{}]", basename, bitmap->width(), bitmap->height()));
auto title_text = document.heap().allocate<DOM::Text>(document.realm(), document, MUST(String::formatted("{} [{}x{}]", basename, bitmap->width(), bitmap->height())));
MUST(title_element->append_child(*title_text));
auto body_element = DOM::create_element(document, HTML::TagNames::body, Namespace::HTML).release_value_but_fixme_should_propagate_errors();

View file

@ -1424,7 +1424,7 @@ WebIDL::ExceptionOr<JS::GCPtr<Element>> Element::insert_adjacent_element(Depreca
WebIDL::ExceptionOr<void> Element::insert_adjacent_text(DeprecatedString const& where, DeprecatedString const& data)
{
// 1. Let text be a new Text node whose data is data and node document is thiss node document.
auto text = heap().allocate<DOM::Text>(realm(), document(), data);
auto text = heap().allocate<DOM::Text>(realm(), document(), MUST(String::from_deprecated_string(data)));
// 2. Run insert adjacent, given this, where, and text.
// Spec Note: This method returns nothing because it existed before we had a chance to design it.

View file

@ -805,7 +805,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children)
auto text = verify_cast<Text>(this);
// Set copys data to that of node.
auto text_copy = heap().allocate<Text>(realm(), *document, text->data());
auto text_copy = heap().allocate<Text>(realm(), *document, MUST(String::from_deprecated_string(text->data())));
copy = move(text_copy);
} else if (is<Comment>(this)) {
// Comment
@ -1257,7 +1257,7 @@ void Node::string_replace_all(DeprecatedString const& string)
// 2. If string is not the empty string, then set node to a new Text node whose data is string and node document is parents node document.
if (!string.is_empty())
node = heap().allocate<Text>(realm(), document(), string);
node = heap().allocate<Text>(realm(), document(), MUST(String::from_deprecated_string(string)));
// 3. Replace all with node within parent.
replace_all(node);

View file

@ -26,7 +26,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> convert_nodes_to_single_node(Vector<
if (node.has<JS::Handle<Node>>())
return *node.get<JS::Handle<Node>>();
return document.heap().allocate<DOM::Text>(document.realm(), document, node.get<DeprecatedString>());
return document.heap().allocate<DOM::Text>(document.realm(), document, MUST(String::from_deprecated_string(node.get<DeprecatedString>())));
};
if (nodes.size() == 1)

View file

@ -14,13 +14,13 @@
namespace Web::DOM {
Text::Text(Document& document, DeprecatedString const& data)
: CharacterData(document, NodeType::TEXT_NODE, data)
Text::Text(Document& document, String const& data)
: CharacterData(document, NodeType::TEXT_NODE, data.to_deprecated_string())
{
}
Text::Text(Document& document, NodeType type, DeprecatedString const& data)
: CharacterData(document, type, data)
Text::Text(Document& document, NodeType type, String const& data)
: CharacterData(document, type, data.to_deprecated_string())
{
}
@ -37,7 +37,7 @@ void Text::visit_edges(Cell::Visitor& visitor)
}
// https://dom.spec.whatwg.org/#dom-text-text
WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::construct_impl(JS::Realm& realm, DeprecatedString const& data)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::construct_impl(JS::Realm& realm, String const& data)
{
// The new Text(data) constructor steps are to set thiss data to data and thiss node document to current global objects associated Document.
auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
@ -67,7 +67,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::split_text(size_t offset)
auto new_data = TRY(substring_data(offset, count));
// 5. Let new node be a new Text node, with the same node document as node. Set new nodes data to new data.
auto new_node = heap().allocate<Text>(realm(), document(), new_data);
auto new_node = heap().allocate<Text>(realm(), document(), MUST(String::from_deprecated_string(new_data)));
// 6. Let parent be nodes parent.
JS::GCPtr<Node> parent = this->parent();

View file

@ -18,7 +18,7 @@ class Text : public CharacterData {
public:
virtual ~Text() override = default;
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> construct_impl(JS::Realm& realm, DeprecatedString const& data);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> construct_impl(JS::Realm& realm, String const& data);
// ^Node
virtual DeprecatedFlyString node_name() const override { return "#text"; }
@ -35,8 +35,8 @@ public:
void set_is_password_input(Badge<HTML::HTMLInputElement>, bool b) { m_is_password_input = b; }
protected:
Text(Document&, DeprecatedString const&);
Text(Document&, NodeType, DeprecatedString const&);
Text(Document&, String const&);
Text(Document&, NodeType, String const&);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -1,7 +1,7 @@
#import <DOM/CharacterData.idl>
// https://dom.spec.whatwg.org/#text
[Exposed=Window, UseDeprecatedAKString]
[Exposed=Window]
interface Text : CharacterData {
constructor(optional DOMString data = "");