mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
LibWeb: Port Text interface from DeprecatedString to String
This commit is contained in:
parent
6789a2dd8e
commit
bcb6851c07
Notes:
sideshowbarker
2024-07-17 01:06:10 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/bcb6851c07 Pull-request: https://github.com/SerenityOS/serenity/pull/20968
15 changed files with 25 additions and 25 deletions
|
@ -51,7 +51,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> OptionConstructor::construct
|
|||
|
||||
// 3. If text is not the empty string, then append to option a new Text node whose data is text.
|
||||
if (vm.argument_count() > 0) {
|
||||
auto text = TRY(vm.argument(0).to_deprecated_string(vm));
|
||||
auto text = TRY(vm.argument(0).to_string(vm));
|
||||
if (!text.is_empty()) {
|
||||
auto new_text_node = vm.heap().allocate<DOM::Text>(realm, document, text);
|
||||
MUST(option_element->append_child(*new_text_node));
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 this’s 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.
|
||||
|
|
|
@ -805,7 +805,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children)
|
|||
auto text = verify_cast<Text>(this);
|
||||
|
||||
// Set copy’s 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 parent’s 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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 this’s data to data and this’s node document to current global object’s 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 node’s 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 node’s parent.
|
||||
JS::GCPtr<Node> parent = this->parent();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = "");
|
||||
|
||||
|
|
|
@ -502,7 +502,7 @@ void HTMLInputElement::create_shadow_tree_if_needed()
|
|||
m_placeholder_element = heap().allocate<PlaceholderElement>(realm(), document());
|
||||
MUST(m_placeholder_element->style_for_bindings()->set_property(CSS::PropertyID::Height, "1lh"sv));
|
||||
|
||||
m_placeholder_text_node = heap().allocate<DOM::Text>(realm(), document(), initial_value);
|
||||
m_placeholder_text_node = heap().allocate<DOM::Text>(realm(), document(), MUST(String::from_deprecated_string(initial_value)));
|
||||
m_placeholder_text_node->set_data(deprecated_attribute(HTML::AttributeNames::placeholder));
|
||||
m_placeholder_text_node->set_owner_input_element({}, *this);
|
||||
MUST(m_placeholder_element->append_child(*m_placeholder_text_node));
|
||||
|
@ -511,7 +511,7 @@ void HTMLInputElement::create_shadow_tree_if_needed()
|
|||
m_inner_text_element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
MUST(m_inner_text_element->style_for_bindings()->set_property(CSS::PropertyID::Height, "1lh"sv));
|
||||
|
||||
m_text_node = heap().allocate<DOM::Text>(realm(), document(), initial_value);
|
||||
m_text_node = heap().allocate<DOM::Text>(realm(), document(), MUST(String::from_deprecated_string(initial_value)));
|
||||
if (m_type == TypeAttributeState::FileUpload) {
|
||||
// NOTE: file upload state is mutable, but we don't allow the text node to be modifed
|
||||
m_text_node->set_always_editable(false);
|
||||
|
|
|
@ -1009,7 +1009,7 @@ DOM::Text* HTMLParser::find_character_insertion_node()
|
|||
if (adjusted_insertion_location.insert_before_sibling) {
|
||||
if (is_empty_text_node(adjusted_insertion_location.insert_before_sibling->previous_sibling()))
|
||||
return static_cast<DOM::Text*>(adjusted_insertion_location.insert_before_sibling->previous_sibling());
|
||||
auto new_text_node = realm().heap().allocate<DOM::Text>(realm(), document(), "");
|
||||
auto new_text_node = realm().heap().allocate<DOM::Text>(realm(), document(), String {});
|
||||
adjusted_insertion_location.parent->insert_before(*new_text_node, *adjusted_insertion_location.insert_before_sibling);
|
||||
return new_text_node;
|
||||
}
|
||||
|
@ -1017,7 +1017,7 @@ DOM::Text* HTMLParser::find_character_insertion_node()
|
|||
return nullptr;
|
||||
if (is_empty_text_node(adjusted_insertion_location.parent->last_child()))
|
||||
return static_cast<DOM::Text*>(adjusted_insertion_location.parent->last_child());
|
||||
auto new_text_node = realm().heap().allocate<DOM::Text>(realm(), document(), "");
|
||||
auto new_text_node = realm().heap().allocate<DOM::Text>(realm(), document(), String {});
|
||||
MUST(adjusted_insertion_location.parent->append_child(*new_text_node));
|
||||
return new_text_node;
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ ErrorOr<void> TreeBuilder::create_pseudo_element_if_needed(DOM::Element& element
|
|||
|
||||
// FIXME: Handle images, and multiple values
|
||||
if (pseudo_element_content.type == CSS::ContentData::Type::String) {
|
||||
auto text = document.heap().allocate<DOM::Text>(document.realm(), document, pseudo_element_content.data.to_deprecated_string());
|
||||
auto text = document.heap().allocate<DOM::Text>(document.realm(), document, pseudo_element_content.data);
|
||||
auto text_node = document.heap().allocate_without_realm<Layout::TextNode>(document, *text);
|
||||
text_node->set_generated_for(generated_for, element);
|
||||
|
||||
|
|
Loading…
Reference in a new issue