mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #6688 - Manishearth:smarter-root-lint, r=jdm
Handle type parameters in unused_must_root fixes #6651 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6688) <!-- Reviewable:end -->
This commit is contained in:
commit
8a6681ba70
11 changed files with 118 additions and 57 deletions
|
@ -81,6 +81,7 @@ impl<T: Reflectable> JS<T> {
|
|||
|
||||
/// An unrooted reference to a DOM object for use in layout. `Layout*Helpers`
|
||||
/// traits must be implemented on this.
|
||||
#[allow_unrooted_interior]
|
||||
pub struct LayoutJS<T> {
|
||||
ptr: NonZero<*const T>
|
||||
}
|
||||
|
@ -270,6 +271,12 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
|
|||
pub unsafe fn get_inner_as_layout(&self) -> Option<LayoutJS<T>> {
|
||||
self.ptr.get().map(|js| js.to_layout())
|
||||
}
|
||||
|
||||
/// Get a rooted value out of this object
|
||||
// FIXME(#6684)
|
||||
pub fn get_rooted(&self) -> Option<Root<T>> {
|
||||
self.get().map(|o| o.root())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: HeapGCValue+Copy> Default for MutNullableHeap<T> {
|
||||
|
@ -382,6 +389,7 @@ pub unsafe fn trace_roots(tracer: *mut JSTracer) {
|
|||
/// are additive, so this object's destruction will not invalidate other roots
|
||||
/// for the same JS value. `Root`s cannot outlive the associated
|
||||
/// `RootCollection` object.
|
||||
#[allow_unrooted_interior]
|
||||
pub struct Root<T: Reflectable> {
|
||||
/// Reference to rooted value that must not outlive this container
|
||||
ptr: NonZero<*const T>,
|
||||
|
|
|
@ -57,6 +57,7 @@ unsafe impl Send for TrustedReference {}
|
|||
/// shared among tasks for use in asynchronous operations. The underlying
|
||||
/// DOM object is guaranteed to live at least as long as the last outstanding
|
||||
/// `Trusted<T>` instance.
|
||||
#[allow_unrooted_interior]
|
||||
pub struct Trusted<T: Reflectable> {
|
||||
/// A pointer to the Rust DOM object of type T, but void to allow
|
||||
/// sending `Trusted<T>` between tasks, regardless of T's sendability.
|
||||
|
|
|
@ -455,6 +455,7 @@ impl<'a, T: JSTraceable> Drop for RootedTraceable<'a, T> {
|
|||
#[allow(unrooted_must_root)]
|
||||
#[no_move]
|
||||
#[derive(JSTraceable)]
|
||||
#[allow_unrooted_interior]
|
||||
pub struct RootedVec<T: JSTraceable + Reflectable> {
|
||||
v: Vec<T>
|
||||
}
|
||||
|
|
|
@ -413,8 +413,7 @@ pub fn reflect_dom_object<T: Reflectable>
|
|||
}
|
||||
|
||||
/// A struct to store a reference to the reflector of a DOM object.
|
||||
// Allowing unused_attribute because the lint sometimes doesn't run in order
|
||||
#[allow(raw_pointer_derive, unrooted_must_root, unused_attributes)]
|
||||
#[allow(raw_pointer_derive, unrooted_must_root)]
|
||||
#[must_root]
|
||||
#[servo_lang = "reflector"]
|
||||
// If you're renaming or moving this field, update the path in plugins::reflector as well
|
||||
|
|
|
@ -30,6 +30,7 @@ use std::default::Default;
|
|||
#[derive(JSTraceable)]
|
||||
#[privatize]
|
||||
#[allow(raw_pointer_derive)]
|
||||
#[must_root]
|
||||
pub struct BrowsingContext {
|
||||
history: Vec<SessionHistoryEntry>,
|
||||
active_index: usize,
|
||||
|
|
|
@ -328,14 +328,14 @@ impl<'a> PrivateNodeHelpers for &'a Node {
|
|||
match before {
|
||||
Some(ref before) => {
|
||||
assert!(before.parent_node.get().map(Root::from_rooted).r() == Some(self));
|
||||
match before.prev_sibling.get() {
|
||||
let prev_sibling = before.GetPreviousSibling();
|
||||
match prev_sibling {
|
||||
None => {
|
||||
assert!(Some(*before) == self.first_child.get().map(Root::from_rooted).r());
|
||||
self.first_child.set(Some(JS::from_ref(new_child)));
|
||||
},
|
||||
Some(ref prev_sibling) => {
|
||||
let prev_sibling = prev_sibling.root();
|
||||
prev_sibling.r().next_sibling.set(Some(JS::from_ref(new_child)));
|
||||
prev_sibling.next_sibling.set(Some(JS::from_ref(new_child)));
|
||||
new_child.prev_sibling.set(Some(JS::from_ref(prev_sibling.r())));
|
||||
},
|
||||
}
|
||||
|
@ -343,11 +343,11 @@ impl<'a> PrivateNodeHelpers for &'a Node {
|
|||
new_child.next_sibling.set(Some(JS::from_ref(before)));
|
||||
},
|
||||
None => {
|
||||
match self.last_child.get() {
|
||||
let last_child = self.GetLastChild();
|
||||
match last_child {
|
||||
None => self.first_child.set(Some(JS::from_ref(new_child))),
|
||||
Some(ref last_child) => {
|
||||
let last_child = last_child.root();
|
||||
assert!(last_child.r().next_sibling.get().is_none());
|
||||
assert!(last_child.next_sibling.get().is_none());
|
||||
last_child.r().next_sibling.set(Some(JS::from_ref(new_child)));
|
||||
new_child.prev_sibling.set(Some(JS::from_rooted(&last_child)));
|
||||
}
|
||||
|
@ -365,22 +365,22 @@ impl<'a> PrivateNodeHelpers for &'a Node {
|
|||
/// Fails unless `child` is a child of this node.
|
||||
fn remove_child(self, child: &Node) {
|
||||
assert!(child.parent_node.get().map(Root::from_rooted).r() == Some(self));
|
||||
|
||||
match child.prev_sibling.get() {
|
||||
let prev_sibling = child.GetPreviousSibling();
|
||||
match prev_sibling {
|
||||
None => {
|
||||
self.first_child.set(child.next_sibling.get());
|
||||
}
|
||||
Some(ref prev_sibling) => {
|
||||
prev_sibling.root().r().next_sibling.set(child.next_sibling.get());
|
||||
prev_sibling.next_sibling.set(child.next_sibling.get());
|
||||
}
|
||||
}
|
||||
|
||||
match child.next_sibling.get() {
|
||||
let next_sibling = child.GetNextSibling();
|
||||
match next_sibling {
|
||||
None => {
|
||||
self.last_child.set(child.prev_sibling.get());
|
||||
}
|
||||
Some(ref next_sibling) => {
|
||||
next_sibling.root().r().prev_sibling.set(child.prev_sibling.get());
|
||||
next_sibling.prev_sibling.set(child.prev_sibling.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1476,9 +1476,10 @@ impl Node {
|
|||
// https://dom.spec.whatwg.org/#concept-node-adopt
|
||||
pub fn adopt(node: &Node, document: &Document) {
|
||||
// Step 1.
|
||||
match node.parent_node.get() {
|
||||
let parent_node = node.GetParentNode();
|
||||
match parent_node {
|
||||
Some(ref parent) => {
|
||||
Node::remove(node, parent.root().r(), SuppressObserver::Unsuppressed);
|
||||
Node::remove(node, parent, SuppressObserver::Unsuppressed);
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue