mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Use the try macro for the result of accept_node.
This commit is contained in:
parent
2992dbd41b
commit
057b14dd5c
1 changed files with 23 additions and 29 deletions
|
@ -160,16 +160,16 @@ impl<'a> PrivateTreeWalkerHelpers for JSRef<'a, TreeWalker> {
|
||||||
None => break,
|
None => break,
|
||||||
Some(node) => {
|
Some(node) => {
|
||||||
// "1. Filter node and let result be the return value."
|
// "1. Filter node and let result be the return value."
|
||||||
match self.accept_node(node) {
|
let result = try!(self.accept_node(node));
|
||||||
Err(e) => return Err(e),
|
match result {
|
||||||
// "2. If result is FILTER_ACCEPT, then set the currentNode
|
// "2. If result is FILTER_ACCEPT, then set the currentNode
|
||||||
// attribute to node and return node."
|
// attribute to node and return node."
|
||||||
Ok(NodeFilterConstants::FILTER_ACCEPT) => {
|
NodeFilterConstants::FILTER_ACCEPT => {
|
||||||
self.current_node.set(JS::from_rooted(node));
|
self.current_node.set(JS::from_rooted(node));
|
||||||
return Ok(Some(Temporary::from_rooted(node)))
|
return Ok(Some(Temporary::from_rooted(node)))
|
||||||
},
|
},
|
||||||
// "3. If result is FILTER_SKIP, run these subsubsteps:"
|
// "3. If result is FILTER_SKIP, run these subsubsteps:"
|
||||||
Ok(NodeFilterConstants::FILTER_SKIP) => {
|
NodeFilterConstants::FILTER_SKIP => {
|
||||||
// "1. Let child be node's first child if type is first,
|
// "1. Let child be node's first child if type is first,
|
||||||
// and node's last child if type is last."
|
// and node's last child if type is last."
|
||||||
match next_child(node) {
|
match next_child(node) {
|
||||||
|
@ -247,12 +247,11 @@ impl<'a> PrivateTreeWalkerHelpers for JSRef<'a, TreeWalker> {
|
||||||
// "1. Set node to sibling."
|
// "1. Set node to sibling."
|
||||||
node = sibling_op.unwrap().root().get_unsound_ref_forever();
|
node = sibling_op.unwrap().root().get_unsound_ref_forever();
|
||||||
// "2. Filter node and let result be the return value."
|
// "2. Filter node and let result be the return value."
|
||||||
let result = self.accept_node(node);
|
let result = try!(self.accept_node(node));
|
||||||
// "3. If result is FILTER_ACCEPT, then set the currentNode
|
// "3. If result is FILTER_ACCEPT, then set the currentNode
|
||||||
// attribute to node and return node."
|
// attribute to node and return node."
|
||||||
match result {
|
match result {
|
||||||
Err(e) => return Err(e),
|
NodeFilterConstants::FILTER_ACCEPT => {
|
||||||
Ok(NodeFilterConstants::FILTER_ACCEPT) => {
|
|
||||||
self.current_node.set(JS::from_rooted(node));
|
self.current_node.set(JS::from_rooted(node));
|
||||||
return Ok(Some(Temporary::from_rooted(node)))
|
return Ok(Some(Temporary::from_rooted(node)))
|
||||||
},
|
},
|
||||||
|
@ -265,7 +264,7 @@ impl<'a> PrivateTreeWalkerHelpers for JSRef<'a, TreeWalker> {
|
||||||
// then set sibling to node's next sibling if type is next,
|
// then set sibling to node's next sibling if type is next,
|
||||||
// and node's previous sibling if type is previous."
|
// and node's previous sibling if type is previous."
|
||||||
match (result, &sibling_op) {
|
match (result, &sibling_op) {
|
||||||
(Ok(NodeFilterConstants::FILTER_REJECT), _)
|
(NodeFilterConstants::FILTER_REJECT, _)
|
||||||
| (_, &None) => sibling_op = next_sibling(node),
|
| (_, &None) => sibling_op = next_sibling(node),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -278,9 +277,8 @@ impl<'a> PrivateTreeWalkerHelpers for JSRef<'a, TreeWalker> {
|
||||||
// "5. Filter node and if the return value is FILTER_ACCEPT, then return null."
|
// "5. Filter node and if the return value is FILTER_ACCEPT, then return null."
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
node = n;
|
node = n;
|
||||||
match self.accept_node(node) {
|
match try!(self.accept_node(node)) {
|
||||||
Err(e) => return Err(e),
|
NodeFilterConstants::FILTER_ACCEPT => return Ok(None),
|
||||||
Ok(NodeFilterConstants::FILTER_ACCEPT) => return Ok(None),
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,9 +367,8 @@ impl<'a> TreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> {
|
||||||
node = n.root().get_unsound_ref_forever();
|
node = n.root().get_unsound_ref_forever();
|
||||||
// "2. If node is not null and filtering node returns FILTER_ACCEPT,
|
// "2. If node is not null and filtering node returns FILTER_ACCEPT,
|
||||||
// then set the currentNode attribute to node, return node."
|
// then set the currentNode attribute to node, return node."
|
||||||
match self.accept_node(node) {
|
match try!(self.accept_node(node)) {
|
||||||
Err(e) => return Err(e),
|
NodeFilterConstants::FILTER_ACCEPT => {
|
||||||
Ok(NodeFilterConstants::FILTER_ACCEPT) => {
|
|
||||||
self.current_node.set(JS::from_rooted(node));
|
self.current_node.set(JS::from_rooted(node));
|
||||||
return Ok(Some(Temporary::from_rooted(node)))
|
return Ok(Some(Temporary::from_rooted(node)))
|
||||||
},
|
},
|
||||||
|
@ -432,12 +429,12 @@ impl<'a> TreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> {
|
||||||
// "4. If result is FILTER_ACCEPT, then
|
// "4. If result is FILTER_ACCEPT, then
|
||||||
// set the currentNode attribute to node and return node."
|
// set the currentNode attribute to node and return node."
|
||||||
loop {
|
loop {
|
||||||
match self.accept_node(node) {
|
let result = try!(self.accept_node(node));
|
||||||
Err(e) => return Err(e),
|
match result {
|
||||||
Ok(NodeFilterConstants::FILTER_REJECT) => break,
|
NodeFilterConstants::FILTER_REJECT => break,
|
||||||
_ if node.first_child().is_some() =>
|
_ if node.first_child().is_some() =>
|
||||||
node = node.last_child().unwrap().root().get_unsound_ref_forever(),
|
node = node.last_child().unwrap().root().get_unsound_ref_forever(),
|
||||||
Ok(NodeFilterConstants::FILTER_ACCEPT) => {
|
NodeFilterConstants::FILTER_ACCEPT => {
|
||||||
self.current_node.set(JS::from_rooted(node));
|
self.current_node.set(JS::from_rooted(node));
|
||||||
return Ok(Some(Temporary::from_rooted(node)))
|
return Ok(Some(Temporary::from_rooted(node)))
|
||||||
},
|
},
|
||||||
|
@ -461,9 +458,8 @@ impl<'a> TreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> {
|
||||||
}
|
}
|
||||||
// "5. Filter node and if the return value is FILTER_ACCEPT, then
|
// "5. Filter node and if the return value is FILTER_ACCEPT, then
|
||||||
// set the currentNode attribute to node and return node."
|
// set the currentNode attribute to node and return node."
|
||||||
match self.accept_node(node) {
|
match try!(self.accept_node(node)) {
|
||||||
Err(e) => return Err(e),
|
NodeFilterConstants::FILTER_ACCEPT => {
|
||||||
Ok(NodeFilterConstants::FILTER_ACCEPT) => {
|
|
||||||
self.current_node.set(JS::from_rooted(node));
|
self.current_node.set(JS::from_rooted(node));
|
||||||
return Ok(Some(Temporary::from_rooted(node)))
|
return Ok(Some(Temporary::from_rooted(node)))
|
||||||
},
|
},
|
||||||
|
@ -479,13 +475,13 @@ impl<'a> TreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> {
|
||||||
// "1. Let node be the value of the currentNode attribute."
|
// "1. Let node be the value of the currentNode attribute."
|
||||||
let mut node = self.current_node.get().root().get_unsound_ref_forever();
|
let mut node = self.current_node.get().root().get_unsound_ref_forever();
|
||||||
// "2. Let result be FILTER_ACCEPT."
|
// "2. Let result be FILTER_ACCEPT."
|
||||||
let mut result = Ok(NodeFilterConstants::FILTER_ACCEPT);
|
let mut result = NodeFilterConstants::FILTER_ACCEPT;
|
||||||
// "3. Run these substeps:"
|
// "3. Run these substeps:"
|
||||||
loop {
|
loop {
|
||||||
// "1. While result is not FILTER_REJECT and node has a child, run these subsubsteps:"
|
// "1. While result is not FILTER_REJECT and node has a child, run these subsubsteps:"
|
||||||
loop {
|
loop {
|
||||||
match result {
|
match result {
|
||||||
Ok(NodeFilterConstants::FILTER_REJECT) => break,
|
NodeFilterConstants::FILTER_REJECT => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
match node.first_child() {
|
match node.first_child() {
|
||||||
|
@ -494,12 +490,11 @@ impl<'a> TreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> {
|
||||||
// "1. Set node to its first child."
|
// "1. Set node to its first child."
|
||||||
node = child.root().get_unsound_ref_forever();
|
node = child.root().get_unsound_ref_forever();
|
||||||
// "2. Filter node and set result to the return value."
|
// "2. Filter node and set result to the return value."
|
||||||
result = self.accept_node(node);
|
result = try!(self.accept_node(node));
|
||||||
// "3. If result is FILTER_ACCEPT, then
|
// "3. If result is FILTER_ACCEPT, then
|
||||||
// set the currentNode attribute to node and return node."
|
// set the currentNode attribute to node and return node."
|
||||||
match result {
|
match result {
|
||||||
Err(e) => return Err(e),
|
NodeFilterConstants::FILTER_ACCEPT => {
|
||||||
Ok(NodeFilterConstants::FILTER_ACCEPT) => {
|
|
||||||
self.current_node.set(JS::from_rooted(node));
|
self.current_node.set(JS::from_rooted(node));
|
||||||
return Ok(Some(Temporary::from_rooted(node)))
|
return Ok(Some(Temporary::from_rooted(node)))
|
||||||
},
|
},
|
||||||
|
@ -516,12 +511,11 @@ impl<'a> TreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
node = n.root().get_unsound_ref_forever();
|
node = n.root().get_unsound_ref_forever();
|
||||||
// "3. Filter node and set result to the return value."
|
// "3. Filter node and set result to the return value."
|
||||||
result = self.accept_node(node);
|
result = try!(self.accept_node(node));
|
||||||
// "4. If result is FILTER_ACCEPT, then
|
// "4. If result is FILTER_ACCEPT, then
|
||||||
// set the currentNode attribute to node and return node."
|
// set the currentNode attribute to node and return node."
|
||||||
match result {
|
match result {
|
||||||
Err(e) => return Err(e),
|
NodeFilterConstants::FILTER_ACCEPT => {
|
||||||
Ok(NodeFilterConstants::FILTER_ACCEPT) => {
|
|
||||||
self.current_node.set(JS::from_rooted(node));
|
self.current_node.set(JS::from_rooted(node));
|
||||||
return Ok(Some(Temporary::from_rooted(node)))
|
return Ok(Some(Temporary::from_rooted(node)))
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue