mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Use Temporary in ChildElementIterator
This commit is contained in:
parent
bf7c791e3a
commit
11b4ff9e94
2 changed files with 11 additions and 14 deletions
|
@ -927,7 +927,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
// http://dom.spec.whatwg.org/#dom-document-documentelement
|
// http://dom.spec.whatwg.org/#dom-document-documentelement
|
||||||
fn GetDocumentElement(self) -> Option<Temporary<Element>> {
|
fn GetDocumentElement(self) -> Option<Temporary<Element>> {
|
||||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||||
node.child_elements().next().map(Temporary::from_rooted)
|
node.child_elements().next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagname
|
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagname
|
||||||
|
|
|
@ -413,7 +413,7 @@ pub trait NodeHelpers<'a> {
|
||||||
fn inclusive_ancestors(self) -> AncestorIterator;
|
fn inclusive_ancestors(self) -> AncestorIterator;
|
||||||
fn children(self) -> NodeChildrenIterator;
|
fn children(self) -> NodeChildrenIterator;
|
||||||
fn rev_children(self) -> ReverseChildrenIterator;
|
fn rev_children(self) -> ReverseChildrenIterator;
|
||||||
fn child_elements(self) -> ChildElementIterator<'a>;
|
fn child_elements(self) -> ChildElementIterator;
|
||||||
fn following_siblings(self) -> NodeChildrenIterator;
|
fn following_siblings(self) -> NodeChildrenIterator;
|
||||||
fn is_in_doc(self) -> bool;
|
fn is_in_doc(self) -> bool;
|
||||||
fn is_inclusive_ancestor_of(self, parent: JSRef<Node>) -> bool;
|
fn is_inclusive_ancestor_of(self, parent: JSRef<Node>) -> bool;
|
||||||
|
@ -870,14 +870,9 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_elements(self) -> ChildElementIterator<'a> {
|
fn child_elements(self) -> ChildElementIterator {
|
||||||
fn cast<'a>(n: Temporary<Node>) -> Option<JSRef<'a, Element>> {
|
|
||||||
let n = n.root();
|
|
||||||
ElementCast::to_ref(n.get_unsound_ref_forever())
|
|
||||||
}
|
|
||||||
|
|
||||||
self.children()
|
self.children()
|
||||||
.filter_map(cast as fn(_) -> _)
|
.filter_map(ElementCast::to_temporary as fn(_) -> _)
|
||||||
.peekable()
|
.peekable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1114,9 +1109,9 @@ impl RawLayoutNodeHelpers for Node {
|
||||||
// Iteration and traversal
|
// Iteration and traversal
|
||||||
//
|
//
|
||||||
|
|
||||||
pub type ChildElementIterator<'a> =
|
pub type ChildElementIterator =
|
||||||
Peekable<FilterMap<NodeChildrenIterator,
|
Peekable<FilterMap<NodeChildrenIterator,
|
||||||
fn(Temporary<Node>) -> Option<JSRef<'a, Element>>>>;
|
fn(Temporary<Node>) -> Option<Temporary<Element>>>>;
|
||||||
|
|
||||||
pub struct NodeChildrenIterator {
|
pub struct NodeChildrenIterator {
|
||||||
current: Option<Temporary<Node>>,
|
current: Option<Temporary<Node>>,
|
||||||
|
@ -1946,7 +1941,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
||||||
0 => (),
|
0 => (),
|
||||||
// Step 6.1.2
|
// Step 6.1.2
|
||||||
1 => {
|
1 => {
|
||||||
if self.child_elements().any(|c| NodeCast::from_ref(c) != child) {
|
if self.child_elements()
|
||||||
|
.map(|c| c.root())
|
||||||
|
.any(|c| NodeCast::from_ref(c.r()) != child) {
|
||||||
return Err(HierarchyRequest);
|
return Err(HierarchyRequest);
|
||||||
}
|
}
|
||||||
if child.following_siblings()
|
if child.following_siblings()
|
||||||
|
@ -1962,8 +1959,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
||||||
// Step 6.2
|
// Step 6.2
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
if self.child_elements()
|
if self.child_elements()
|
||||||
.any(|c| NodeCast::from_ref(c) != child)
|
.map(|c| c.root())
|
||||||
{
|
.any(|c| NodeCast::from_ref(c.r()) != child) {
|
||||||
return Err(HierarchyRequest);
|
return Err(HierarchyRequest);
|
||||||
}
|
}
|
||||||
if child.following_siblings()
|
if child.following_siblings()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue