mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
LibWeb: Port CharacterData from DeprecatedString to String
The existing implementation has some pre-existing issues where it is incorrectly assumes that byte offsets are given through the IDL instead of UTF-16 code units. While making these changes, leave some FIXMEs for that.
This commit is contained in:
parent
3b12a13f17
commit
b603e860af
18 changed files with 87 additions and 81 deletions
|
@ -162,7 +162,7 @@ Optional<String> Node::text_content() const
|
|||
|
||||
// If CharacterData, return this’s data.
|
||||
if (is<CharacterData>(this))
|
||||
return MUST(String::from_deprecated_string(static_cast<CharacterData const&>(*this).data()));
|
||||
return static_cast<CharacterData const&>(*this).data();
|
||||
|
||||
// If Attr node, return this's value.
|
||||
if (is<Attr>(*this))
|
||||
|
@ -188,7 +188,7 @@ void Node::set_text_content(Optional<String> const& maybe_content)
|
|||
else if (is<CharacterData>(this)) {
|
||||
|
||||
auto* character_data_node = verify_cast<CharacterData>(this);
|
||||
character_data_node->set_data(content);
|
||||
character_data_node->set_data(MUST(String::from_deprecated_string(content)));
|
||||
|
||||
// FIXME: CharacterData::set_data is not spec compliant. Make this match the spec when set_data becomes spec compliant.
|
||||
// Do note that this will make this function able to throw an exception.
|
||||
|
@ -217,7 +217,7 @@ Optional<String> Node::node_value() const
|
|||
|
||||
// If CharacterData, return this’s data.
|
||||
if (is<CharacterData>(this)) {
|
||||
return MUST(String::from_deprecated_string(verify_cast<CharacterData>(this)->data()));
|
||||
return verify_cast<CharacterData>(this)->data();
|
||||
}
|
||||
|
||||
// Otherwise, return null.
|
||||
|
@ -236,7 +236,7 @@ void Node::set_node_value(Optional<String> const& maybe_value)
|
|||
verify_cast<Attr>(this)->set_value(value.to_deprecated_string());
|
||||
} else if (is<CharacterData>(this)) {
|
||||
// If CharacterData, replace data with node this, offset 0, count this’s length, and data the given value.
|
||||
verify_cast<CharacterData>(this)->set_data(value.to_deprecated_string());
|
||||
verify_cast<CharacterData>(this)->set_data(value);
|
||||
}
|
||||
|
||||
// Otherwise, do nothing.
|
||||
|
@ -854,21 +854,21 @@ 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, MUST(String::from_deprecated_string(text->data())));
|
||||
auto text_copy = heap().allocate<Text>(realm(), *document, text->data());
|
||||
copy = move(text_copy);
|
||||
} else if (is<Comment>(this)) {
|
||||
// Comment
|
||||
auto comment = verify_cast<Comment>(this);
|
||||
|
||||
// Set copy’s data to that of node.
|
||||
auto comment_copy = heap().allocate<Comment>(realm(), *document, MUST(String::from_deprecated_string(comment->data())));
|
||||
auto comment_copy = heap().allocate<Comment>(realm(), *document, comment->data());
|
||||
copy = move(comment_copy);
|
||||
} else if (is<ProcessingInstruction>(this)) {
|
||||
// ProcessingInstruction
|
||||
auto processing_instruction = verify_cast<ProcessingInstruction>(this);
|
||||
|
||||
// Set copy’s target and data to those of node.
|
||||
auto processing_instruction_copy = heap().allocate<ProcessingInstruction>(realm(), *document, processing_instruction->data(), processing_instruction->target());
|
||||
auto processing_instruction_copy = heap().allocate<ProcessingInstruction>(realm(), *document, processing_instruction->data().to_deprecated_string(), processing_instruction->target());
|
||||
copy = processing_instruction_copy;
|
||||
}
|
||||
// Otherwise, Do nothing.
|
||||
|
@ -1143,7 +1143,7 @@ bool Node::is_uninteresting_whitespace_node() const
|
|||
{
|
||||
if (!is<Text>(*this))
|
||||
return false;
|
||||
if (!static_cast<Text const&>(*this).data().is_whitespace())
|
||||
if (!static_cast<Text const&>(*this).data().bytes_as_string_view().is_whitespace())
|
||||
return false;
|
||||
if (!layout_node())
|
||||
return true;
|
||||
|
@ -1491,7 +1491,8 @@ size_t Node::length() const
|
|||
// 2. If node is a CharacterData node, then return node’s data’s length.
|
||||
if (is_character_data()) {
|
||||
auto* character_data_node = verify_cast<CharacterData>(this);
|
||||
return character_data_node->data().length();
|
||||
// FIXME: This should be in UTF-16 code units, not byte size.
|
||||
return character_data_node->data().bytes().size();
|
||||
}
|
||||
|
||||
// 3. Return the number of node’s children.
|
||||
|
@ -1874,7 +1875,7 @@ ErrorOr<String> Node::name_or_description(NameOrDescription target, Document con
|
|||
// G. Otherwise, if the current node is a Text node, return its textual contents.
|
||||
if (is_text()) {
|
||||
auto const* text_node = static_cast<DOM::Text const*>(this);
|
||||
return String::from_deprecated_string(text_node->data());
|
||||
return text_node->data();
|
||||
}
|
||||
// TODO: H. Otherwise, if the current node is a descendant of an element whose Accessible Name or Accessible Description is being computed, and contains descendants, proceed to 2F.i.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue