aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-06-24 03:00:32 -0600
committerbors-servo <metajack+bors@gmail.com>2015-06-24 03:00:32 -0600
commit469b9550f6feec56d87ea5c772cb76453c13036a (patch)
tree8ce1ccf9be4bb47c8dc3575f0d4301ba7907544f /components/script/dom
parent95d643c995a271fac11ab3d9aac97f2d0aac8934 (diff)
parenta42e11a95f7cdc0c45147f7861c7185b690ebbc2 (diff)
downloadservo-469b9550f6feec56d87ea5c772cb76453c13036a.tar.gz
servo-469b9550f6feec56d87ea5c772cb76453c13036a.zip
Auto merge of #6443 - Ms2ger:cleanup-layout, r=pcwalton
Various layout cleanup. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6443) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/node.rs52
1 files changed, 33 insertions, 19 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 851140e3929..919136a4afd 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -53,6 +53,7 @@ use script_traits::UntrustedNodeAddress;
use util::geometry::Au;
use util::namespace;
use util::str::DOMString;
+use util::task_state;
use selectors::parser::{Selector, AttrSelector, NamespaceConstraint};
use selectors::parser::parse_author_origin_selector_list_from_str;
use selectors::matching::matches;
@@ -222,7 +223,7 @@ pub struct LayoutData {
unsafe impl Send for LayoutData {}
pub struct LayoutDataRef {
- pub data_cell: RefCell<Option<LayoutData>>,
+ data_cell: RefCell<Option<LayoutData>>,
}
no_jsmanaged_fields!(LayoutDataRef);
@@ -236,7 +237,8 @@ impl LayoutDataRef {
/// Sends layout data, if any, back to the layout task to be destroyed.
pub fn dispose(&self) {
- if let Some(mut layout_data) = mem::replace(&mut *self.borrow_mut(), None) {
+ debug_assert!(task_state::get().is_script());
+ if let Some(mut layout_data) = mem::replace(&mut *self.data_cell.borrow_mut(), None) {
let layout_chan = layout_data.chan.take();
match layout_chan {
None => {}
@@ -248,18 +250,20 @@ impl LayoutDataRef {
}
}
- /// Borrows the layout data immutably, *asserting that there are no mutators*. Bad things will
+ /// Borrows the layout data immutably, *assuming that there are no mutators*. Bad things will
/// happen if you try to mutate the layout data while this is held. This is the only thread-
/// safe layout data accessor.
#[inline]
#[allow(unsafe_code)]
pub unsafe fn borrow_unchecked(&self) -> *const Option<LayoutData> {
+ debug_assert!(task_state::get().is_layout());
self.data_cell.as_unsafe_cell().get() as *const _
}
/// Borrows the layout data immutably. This function is *not* thread-safe.
#[inline]
pub fn borrow<'a>(&'a self) -> Ref<'a,Option<LayoutData>> {
+ debug_assert!(task_state::get().is_layout());
self.data_cell.borrow()
}
@@ -270,6 +274,7 @@ impl LayoutDataRef {
/// on it. This has already resulted in one bug!
#[inline]
pub fn borrow_mut<'a>(&'a self) -> RefMut<'a,Option<LayoutData>> {
+ debug_assert!(task_state::get().is_layout());
self.data_cell.borrow_mut()
}
}
@@ -1086,6 +1091,13 @@ pub trait LayoutNodeHelpers {
unsafe fn get_flag(&self, flag: NodeFlags) -> bool;
#[allow(unsafe_code)]
unsafe fn set_flag(&self, flag: NodeFlags, value: bool);
+
+ #[allow(unsafe_code)]
+ unsafe fn layout_data(&self) -> Ref<Option<LayoutData>>;
+ #[allow(unsafe_code)]
+ unsafe fn layout_data_mut(&self) -> RefMut<Option<LayoutData>>;
+ #[allow(unsafe_code)]
+ unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData>;
}
impl LayoutNodeHelpers for LayoutJS<Node> {
@@ -1157,6 +1169,24 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
(*this).flags.set(flags);
}
+
+ #[inline]
+ #[allow(unsafe_code)]
+ unsafe fn layout_data(&self) -> Ref<Option<LayoutData>> {
+ (*self.unsafe_get()).layout_data.borrow()
+ }
+
+ #[inline]
+ #[allow(unsafe_code)]
+ unsafe fn layout_data_mut(&self) -> RefMut<Option<LayoutData>> {
+ (*self.unsafe_get()).layout_data.borrow_mut()
+ }
+
+ #[inline]
+ #[allow(unsafe_code)]
+ unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
+ (*self.unsafe_get()).layout_data.borrow_unchecked()
+ }
}
pub trait RawLayoutNodeHelpers {
@@ -1456,22 +1486,6 @@ impl Node {
}
}
- #[inline]
- pub fn layout_data(&self) -> Ref<Option<LayoutData>> {
- self.layout_data.borrow()
- }
-
- #[inline]
- pub fn layout_data_mut(&self) -> RefMut<Option<LayoutData>> {
- self.layout_data.borrow_mut()
- }
-
- #[inline]
- #[allow(unsafe_code)]
- pub unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
- self.layout_data.borrow_unchecked()
- }
-
// https://dom.spec.whatwg.org/#concept-node-adopt
pub fn adopt(node: &Node, document: &Document) {
// Step 1.