diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2013-12-17 10:08:01 -0800 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2013-12-17 18:07:41 -0800 |
commit | c506e52c7c6e80ea875e9d1ce95597cf3bc8bcc1 (patch) | |
tree | e2d427594d58d12abba49ac77a811c1229f5222f /src/components/main/css | |
parent | ee9873bdb5563fe6119d2a8365f814a281ac73c6 (diff) | |
download | servo-c506e52c7c6e80ea875e9d1ce95597cf3bc8bcc1.tar.gz servo-c506e52c7c6e80ea875e9d1ce95597cf3bc8bcc1.zip |
layout: Add a lifetime to `LayoutNode` to prevent layout from stuffing
them into evil places.
Diffstat (limited to 'src/components/main/css')
-rw-r--r-- | src/components/main/css/matching.rs | 32 | ||||
-rw-r--r-- | src/components/main/css/node_style.rs | 2 | ||||
-rw-r--r-- | src/components/main/css/node_util.rs | 2 |
3 files changed, 25 insertions, 11 deletions
diff --git a/src/components/main/css/matching.rs b/src/components/main/css/matching.rs index 4ca64a8a138..efd84f36b7e 100644 --- a/src/components/main/css/matching.rs +++ b/src/components/main/css/matching.rs @@ -4,18 +4,19 @@ // High-level interface to CSS selector matching. -use std::cell::Cell; -use std::comm; -use std::task; -use std::vec; -use std::rt; -use extra::arc::{Arc, RWArc}; - use css::node_style::StyledNode; use layout::incremental; use layout::util::LayoutDataAccess; +use extra::arc::{Arc, RWArc}; use script::dom::node::LayoutNode; +use std::cast; +use std::cell::Cell; +use std::comm; +use std::libc::uintptr_t; +use std::rt; +use std::task; +use std::vec; use style::{TNode, Stylist, cascade}; pub trait MatchMethods { @@ -26,7 +27,7 @@ pub trait MatchMethods { fn cascade_subtree(&self, parent: Option<LayoutNode>); } -impl MatchMethods for LayoutNode { +impl<'self> MatchMethods for LayoutNode<'self> { fn match_node(&self, stylist: &Stylist) { let applicable_declarations = do self.with_element |element| { let style_attribute = match element.style_attribute { @@ -63,7 +64,20 @@ impl MatchMethods for LayoutNode { if nodes.len() > 0 { let chan = chan.clone(); let stylist = stylist.clone(); - do task::spawn_with((nodes, stylist)) |(nodes, stylist)| { + + // FIXME(pcwalton): This transmute is to work around the fact that we have no + // mechanism for safe fork/join parallelism. If we had such a thing, then we could + // close over the lifetime-bounded `LayoutNode`. But we can't, so we force it with + // a transmute. + let evil: uintptr_t = unsafe { + cast::transmute(nodes) + }; + + do task::spawn_with((evil, stylist)) |(evil, stylist)| { + let nodes: ~[LayoutNode] = unsafe { + cast::transmute(evil) + }; + let nodes = Cell::new(nodes); do stylist.read |stylist| { for node in nodes.take().move_iter() { diff --git a/src/components/main/css/node_style.rs b/src/components/main/css/node_style.rs index 6e2abaa81d1..824b50e991a 100644 --- a/src/components/main/css/node_style.rs +++ b/src/components/main/css/node_style.rs @@ -17,7 +17,7 @@ pub trait StyledNode { fn restyle_damage(&self) -> RestyleDamage; } -impl StyledNode for LayoutNode { +impl<'self> StyledNode for LayoutNode<'self> { #[inline] fn style<'a>(&'a self) -> &'a Arc<ComputedValues> { self.get_css_select_results() diff --git a/src/components/main/css/node_util.rs b/src/components/main/css/node_util.rs index 3b24f85e9de..72acf5dc08c 100644 --- a/src/components/main/css/node_util.rs +++ b/src/components/main/css/node_util.rs @@ -18,7 +18,7 @@ pub trait NodeUtil { fn set_restyle_damage(self, damage: RestyleDamage); } -impl NodeUtil for LayoutNode { +impl<'self> NodeUtil for LayoutNode<'self> { /** * Provides the computed style for the given node. If CSS selector * Returns the style results for the given node. If CSS selector |