1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:07:35 +00:00

LibWeb: Make Range.setStart and Range.setEnd spec compliant

These functions are way more involved than simply setting their
respective boundary points :^)
This commit is contained in:
Luke Wilde 2022-01-31 18:05:54 +00:00 committed by Andreas Kling
parent af3c866898
commit 46ce50f74e
6 changed files with 185 additions and 11 deletions

View file

@ -973,4 +973,21 @@ String Node::debug_description() const
return builder.to_string();
}
// https://dom.spec.whatwg.org/#concept-node-length
size_t Node::length() const
{
// 1. If node is a DocumentType or Attr node, then return 0.
if (is_document_type() || is_attribute())
return 0;
// 2. If node is a CharacterData node, then return nodes datas length.
if (is_character_data()) {
auto* character_data_node = verify_cast<CharacterData>(this);
return character_data_node->data().length();
}
// 3. Return the number of nodes children.
return child_count();
}
}