mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Implement NodeHelpers::len()
This commit is contained in:
parent
738f006afe
commit
d8c5092a6e
1 changed files with 12 additions and 0 deletions
|
@ -427,6 +427,7 @@ pub trait NodeHelpers {
|
|||
fn is_parent_of(self, child: JSRef<Node>) -> bool;
|
||||
|
||||
fn type_id(self) -> NodeTypeId;
|
||||
fn len(self) -> u32;
|
||||
|
||||
fn parent_node(self) -> Option<Temporary<Node>>;
|
||||
fn first_child(self) -> Option<Temporary<Node>>;
|
||||
|
@ -567,6 +568,17 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
self.type_id
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-length
|
||||
fn len(self) -> u32 {
|
||||
match self.type_id {
|
||||
NodeTypeId::DocumentType => 0,
|
||||
NodeTypeId::CharacterData(_) => {
|
||||
CharacterDataCast::to_ref(self).unwrap().Length()
|
||||
},
|
||||
_ => self.children().count() as u32
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_node(self) -> Option<Temporary<Node>> {
|
||||
self.parent_node.get().map(Temporary::from_rooted)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue