Fix remaining MutHeap methods not to expose JS<T>.

This commit is contained in:
Eli Friedman 2015-10-14 18:15:44 -07:00
parent 57584e74c6
commit 5bdf6bb1d3
7 changed files with 42 additions and 41 deletions

View file

@ -35,7 +35,7 @@ impl TreeWalker {
TreeWalker {
reflector_: Reflector::new(),
root_node: JS::from_ref(root_node),
current_node: MutHeap::new(JS::from_ref(root_node)),
current_node: MutHeap::new(root_node),
what_to_show: what_to_show,
filter: filter
}
@ -85,18 +85,18 @@ impl TreeWalkerMethods for TreeWalker {
// https://dom.spec.whatwg.org/#dom-treewalker-currentnode
fn CurrentNode(&self) -> Root<Node> {
self.current_node.get().root()
self.current_node.get()
}
// https://dom.spec.whatwg.org/#dom-treewalker-currentnode
fn SetCurrentNode(&self, node: &Node) {
self.current_node.set(JS::from_ref(node));
self.current_node.set(node);
}
// https://dom.spec.whatwg.org/#dom-treewalker-parentnode
fn ParentNode(&self) -> Fallible<Option<Root<Node>>> {
// "1. Let node be the value of the currentNode attribute."
let mut node = self.current_node.get().root();
let mut node = self.current_node.get();
// "2. While node is not null and is not root, run these substeps:"
while !self.is_root_node(node.r()) {
// "1. Let node be node's parent."
@ -106,7 +106,7 @@ impl TreeWalkerMethods for TreeWalker {
// "2. If node is not null and filtering node returns FILTER_ACCEPT,
// then set the currentNode attribute to node, return node."
if NodeFilterConstants::FILTER_ACCEPT == try!(self.accept_node(node.r())) {
self.current_node.set(JS::from_rooted(&node));
self.current_node.set(&node);
return Ok(Some(node))
}
},
@ -148,7 +148,7 @@ impl TreeWalkerMethods for TreeWalker {
// https://dom.spec.whatwg.org/#dom-treewalker-previousnode
fn PreviousNode(&self) -> Fallible<Option<Root<Node>>> {
// "1. Let node be the value of the currentNode attribute."
let mut node = self.current_node.get().root();
let mut node = self.current_node.get();
// "2. While node is not root, run these substeps:"
while !self.is_root_node(node.r()) {
// "1. Let sibling be the previous sibling of node."
@ -170,7 +170,7 @@ impl TreeWalkerMethods for TreeWalker {
_ if node.GetFirstChild().is_some() =>
node = node.GetLastChild().unwrap(),
NodeFilterConstants::FILTER_ACCEPT => {
self.current_node.set(JS::from_rooted(&node));
self.current_node.set(&node);
return Ok(Some(node))
},
_ => break
@ -194,7 +194,7 @@ impl TreeWalkerMethods for TreeWalker {
// "5. Filter node and if the return value is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node."
if NodeFilterConstants::FILTER_ACCEPT == try!(self.accept_node(node.r())) {
self.current_node.set(JS::from_rooted(&node));
self.current_node.set(&node);
return Ok(Some(node))
}
}
@ -205,7 +205,7 @@ impl TreeWalkerMethods for TreeWalker {
// https://dom.spec.whatwg.org/#dom-treewalker-nextnode
fn NextNode(&self) -> Fallible<Option<Root<Node>>> {
// "1. Let node be the value of the currentNode attribute."
let mut node = self.current_node.get().root();
let mut node = self.current_node.get();
// "2. Let result be FILTER_ACCEPT."
let mut result = NodeFilterConstants::FILTER_ACCEPT;
// "3. Run these substeps:"
@ -225,7 +225,7 @@ impl TreeWalkerMethods for TreeWalker {
// "3. If result is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node."
if NodeFilterConstants::FILTER_ACCEPT == result {
self.current_node.set(JS::from_rooted(&node));
self.current_node.set(&node);
return Ok(Some(node))
}
}
@ -243,7 +243,7 @@ impl TreeWalkerMethods for TreeWalker {
// "4. If result is FILTER_ACCEPT, then
// set the currentNode attribute to node and return node."
if NodeFilterConstants::FILTER_ACCEPT == result {
self.current_node.set(JS::from_rooted(&node));
self.current_node.set(&node);
return Ok(Some(node))
}
}
@ -267,7 +267,7 @@ impl TreeWalker {
{
// "To **traverse children** of type *type*, run these steps:"
// "1. Let node be the value of the currentNode attribute."
let cur = self.current_node.get().root();
let cur = self.current_node.get();
// "2. Set node to node's first child if type is first, and node's last child if type is last."
// "3. If node is null, return null."
@ -284,7 +284,7 @@ impl TreeWalker {
// "2. If result is FILTER_ACCEPT, then set the currentNode
// attribute to node and return node."
NodeFilterConstants::FILTER_ACCEPT => {
self.current_node.set(JS::from_rooted(&node));
self.current_node.set(&node);
return Ok(Some(Root::from_ref(node.r())))
},
// "3. If result is FILTER_SKIP, run these subsubsteps:"
@ -342,7 +342,7 @@ impl TreeWalker {
{
// "To **traverse siblings** of type *type* run these steps:"
// "1. Let node be the value of the currentNode attribute."
let mut node = self.current_node.get().root();
let mut node = self.current_node.get();
// "2. If node is root, return null."
if self.is_root_node(node.r()) {
return Ok(None)
@ -361,7 +361,7 @@ impl TreeWalker {
// "3. If result is FILTER_ACCEPT, then set the currentNode
// attribute to node and return node."
if NodeFilterConstants::FILTER_ACCEPT == result {
self.current_node.set(JS::from_rooted(&node));
self.current_node.set(&node);
return Ok(Some(node))
}
@ -447,7 +447,7 @@ impl TreeWalker {
}
fn is_current_node(&self, node: &Node) -> bool {
JS::from_ref(node) == self.current_node.get()
node == &*self.current_node.get()
}
}