mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Fix remaining MutHeap methods not to expose JS<T>.
This commit is contained in:
parent
57584e74c6
commit
5bdf6bb1d3
7 changed files with 42 additions and 41 deletions
|
@ -180,7 +180,7 @@ impl Attr {
|
|||
name: name,
|
||||
namespace: namespace,
|
||||
prefix: prefix,
|
||||
owner: MutNullableHeap::new(owner.map(JS::from_ref)),
|
||||
owner: MutNullableHeap::new(owner),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,22 +211,26 @@ pub struct MutHeap<T: HeapGCValue> {
|
|||
val: UnsafeCell<T>,
|
||||
}
|
||||
|
||||
impl<T: HeapGCValue> MutHeap<T> {
|
||||
impl<T: Reflectable> MutHeap<JS<T>> {
|
||||
/// Create a new `MutHeap`.
|
||||
pub fn new(initial: T) -> MutHeap<T> {
|
||||
pub fn new(initial: &T) -> MutHeap<JS<T>> {
|
||||
MutHeap {
|
||||
val: UnsafeCell::new(initial),
|
||||
val: UnsafeCell::new(JS::from_ref(initial)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set this `MutHeap` to the given value.
|
||||
pub fn set(&self, val: T) {
|
||||
unsafe { *self.val.get() = val; }
|
||||
pub fn set(&self, val: &T) {
|
||||
unsafe {
|
||||
*self.val.get() = JS::from_ref(val);
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the value in this `MutHeap`.
|
||||
pub fn get(&self) -> T {
|
||||
unsafe { ptr::read(self.val.get()) }
|
||||
pub fn get(&self) -> Root<T> {
|
||||
unsafe {
|
||||
ptr::read(self.val.get()).root()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,16 +251,14 @@ pub struct MutNullableHeap<T: HeapGCValue> {
|
|||
ptr: UnsafeCell<Option<T>>
|
||||
}
|
||||
|
||||
impl<T: HeapGCValue> MutNullableHeap<T> {
|
||||
/// Create a new `MutNullableHeap`.
|
||||
pub fn new(initial: Option<T>) -> MutNullableHeap<T> {
|
||||
MutNullableHeap {
|
||||
ptr: UnsafeCell::new(initial)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Reflectable> MutNullableHeap<JS<T>> {
|
||||
/// Create a new `MutNullableHeap`.
|
||||
pub fn new(initial: Option<&T>) -> MutNullableHeap<JS<T>> {
|
||||
MutNullableHeap {
|
||||
ptr: UnsafeCell::new(initial.map(JS::from_ref))
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieve a copy of the current inner value. If it is `None`, it is
|
||||
/// initialized with the result of `cb` first.
|
||||
pub fn or_init<F>(&self, cb: F) -> Root<T>
|
||||
|
|
|
@ -1367,7 +1367,7 @@ impl Node {
|
|||
last_child: Default::default(),
|
||||
next_sibling: Default::default(),
|
||||
prev_sibling: Default::default(),
|
||||
owner_doc: MutNullableHeap::new(doc.map(JS::from_ref)),
|
||||
owner_doc: MutNullableHeap::new(doc),
|
||||
child_list: Default::default(),
|
||||
children_count: Cell::new(0u32),
|
||||
flags: Cell::new(flags),
|
||||
|
|
|
@ -36,7 +36,7 @@ impl NodeIterator {
|
|||
NodeIterator {
|
||||
reflector_: Reflector::new(),
|
||||
root_node: JS::from_ref(root_node),
|
||||
reference_node: MutHeap::new(JS::from_ref(root_node)),
|
||||
reference_node: MutHeap::new(root_node),
|
||||
pointer_before_reference_node: Cell::new(true),
|
||||
what_to_show: what_to_show,
|
||||
filter: filter
|
||||
|
@ -87,7 +87,7 @@ impl NodeIteratorMethods for NodeIterator {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-nodeiterator-referencenode
|
||||
fn ReferenceNode(&self) -> Root<Node> {
|
||||
self.reference_node.get().root()
|
||||
self.reference_node.get()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-nodeiterator-pointerbeforereferencenode
|
||||
|
@ -99,7 +99,7 @@ impl NodeIteratorMethods for NodeIterator {
|
|||
fn NextNode(&self) -> Fallible<Option<Root<Node>>> {
|
||||
// https://dom.spec.whatwg.org/#concept-NodeIterator-traverse
|
||||
// Step 1.
|
||||
let node = self.reference_node.get().root();
|
||||
let node = self.reference_node.get();
|
||||
|
||||
// Step 2.
|
||||
let mut before_node = self.pointer_before_reference_node.get();
|
||||
|
@ -114,7 +114,7 @@ impl NodeIteratorMethods for NodeIterator {
|
|||
// Step 3-3.
|
||||
if result == NodeFilterConstants::FILTER_ACCEPT {
|
||||
// Step 4.
|
||||
self.reference_node.set(JS::from_ref(node.r()));
|
||||
self.reference_node.set(node.r());
|
||||
self.pointer_before_reference_node.set(before_node);
|
||||
|
||||
return Ok(Some(node));
|
||||
|
@ -129,7 +129,7 @@ impl NodeIteratorMethods for NodeIterator {
|
|||
// Step 3-3.
|
||||
if result == NodeFilterConstants::FILTER_ACCEPT {
|
||||
// Step 4.
|
||||
self.reference_node.set(JS::from_ref(following_node.r()));
|
||||
self.reference_node.set(following_node.r());
|
||||
self.pointer_before_reference_node.set(before_node);
|
||||
|
||||
return Ok(Some(following_node));
|
||||
|
@ -143,7 +143,7 @@ impl NodeIteratorMethods for NodeIterator {
|
|||
fn PreviousNode(&self) -> Fallible<Option<Root<Node>>> {
|
||||
// https://dom.spec.whatwg.org/#concept-NodeIterator-traverse
|
||||
// Step 1.
|
||||
let node = self.reference_node.get().root();
|
||||
let node = self.reference_node.get();
|
||||
|
||||
// Step 2.
|
||||
let mut before_node = self.pointer_before_reference_node.get();
|
||||
|
@ -158,7 +158,7 @@ impl NodeIteratorMethods for NodeIterator {
|
|||
// Step 3-3.
|
||||
if result == NodeFilterConstants::FILTER_ACCEPT {
|
||||
// Step 4.
|
||||
self.reference_node.set(JS::from_ref(node.r()));
|
||||
self.reference_node.set(node.r());
|
||||
self.pointer_before_reference_node.set(before_node);
|
||||
|
||||
return Ok(Some(node));
|
||||
|
@ -174,7 +174,7 @@ impl NodeIteratorMethods for NodeIterator {
|
|||
// Step 3-3.
|
||||
if result == NodeFilterConstants::FILTER_ACCEPT {
|
||||
// Step 4.
|
||||
self.reference_node.set(JS::from_ref(preceding_node.r()));
|
||||
self.reference_node.set(preceding_node.r());
|
||||
self.pointer_before_reference_node.set(before_node);
|
||||
|
||||
return Ok(Some(preceding_node));
|
||||
|
|
|
@ -103,8 +103,7 @@ impl ChildrenList {
|
|||
let last_visited = node.GetFirstChild();
|
||||
ChildrenList {
|
||||
node: JS::from_ref(node),
|
||||
last_visited:
|
||||
MutNullableHeap::new(last_visited.as_ref().map(JS::from_rooted)),
|
||||
last_visited: MutNullableHeap::new(last_visited.as_ref().map(Root::r)),
|
||||
last_index: Cell::new(0u32),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ impl StorageEvent {
|
|||
oldValue: oldValue,
|
||||
newValue: newValue,
|
||||
url: url,
|
||||
storageArea: MutNullableHeap::new(storageArea.map(JS::from_ref))
|
||||
storageArea: MutNullableHeap::new(storageArea)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue