Skip to content

Commit

Permalink
Remove the 'static lifetime parameters from TElement methods
Browse files Browse the repository at this point in the history
This improves the static correctness of layout's use of DOM nodes.

Fixes #2595.
  • Loading branch information
Cameron Zwarich committed Sep 27, 2014
1 parent bf025e9 commit b2a3519
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions components/layout/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,9 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
}

/// Methods for interacting with HTMLObjectElement nodes
trait ObjectElement {
trait ObjectElement<'a> {
/// Returns None if this node is not matching attributes.
fn get_type_and_data(&self) -> (Option<&'static str>, Option<&'static str>);
fn get_type_and_data(&self) -> (Option<&'a str>, Option<&'a str>);

/// Returns true if this node has object data that is correct uri.
fn has_object_data(&self) -> bool;
Expand All @@ -1088,8 +1088,8 @@ trait ObjectElement {
fn get_object_data(&self) -> Option<Url>;
}

impl<'ln> ObjectElement for ThreadSafeLayoutNode<'ln> {
fn get_type_and_data(&self) -> (Option<&'static str>, Option<&'static str>) {
impl<'ln> ObjectElement<'ln> for ThreadSafeLayoutNode<'ln> {
fn get_type_and_data(&self) -> (Option<&'ln str>, Option<&'ln str>) {
let elem = self.as_element();
(elem.get_attr(&namespace::Null, "type"), elem.get_attr(&namespace::Null, "data"))
}
Expand Down
6 changes: 3 additions & 3 deletions components/layout/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
}

#[inline]
fn get_attr(&self, namespace: &Namespace, name: &str) -> Option<&'static str> {
fn get_attr(&self, namespace: &Namespace, name: &str) -> Option<&'le str> {
unsafe { self.element.get_attr_val_for_layout(namespace, name) }
}

fn get_link(&self) -> Option<&'static str> {
fn get_link(&self) -> Option<&'le str> {
// FIXME: This is HTML only.
match self.element.node.type_id_for_layout() {
// http://www.whatwg.org/specs/web-apps/current-work/multipage/selectors.html#
Expand Down Expand Up @@ -791,7 +791,7 @@ pub struct ThreadSafeLayoutElement<'le> {

impl<'le> ThreadSafeLayoutElement<'le> {
#[inline]
pub fn get_attr(&self, namespace: &Namespace, name: &str) -> Option<&'static str> {
pub fn get_attr(&self, namespace: &Namespace, name: &str) -> Option<&'le str> {
unsafe { self.element.get_attr_val_for_layout(namespace, name) }
}
}
Expand Down
14 changes: 7 additions & 7 deletions components/script/dom/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ impl Element {
}

pub trait RawLayoutElementHelpers {
unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str) -> Option<&'static str>;
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &str) -> Option<&'a str>;
unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &str) -> Option<Atom>;
unsafe fn has_class_for_layout(&self, name: &str) -> bool;
}

impl RawLayoutElementHelpers for Element {
#[inline]
#[allow(unrooted_must_root)]
unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str)
-> Option<&'static str> {
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &str)
-> Option<&'a str> {
// cast to point to T in RefCell<T> directly
let attrs: *const Vec<JS<Attr>> = mem::transmute(&self.attrs);
(*attrs).iter().find(|attr: & &JS<Attr>| {
Expand Down Expand Up @@ -949,12 +949,12 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
}

impl<'a> style::TElement<'a> for JSRef<'a, Element> {
fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'static str> {
fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'a str> {
self.get_attribute(namespace.clone(), attr).root().map(|attr| {
unsafe { mem::transmute(attr.deref().value().as_slice()) }
})
}
fn get_link(&self) -> Option<&'static str> {
fn get_link(&self) -> Option<&'a str> {
// FIXME: This is HTML only.
let node: JSRef<Node> = NodeCast::from_ref(*self);
match node.type_id() {
Expand All @@ -966,10 +966,10 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
_ => None,
}
}
fn get_local_name<'a>(&'a self) -> &'a Atom {
fn get_local_name<'b>(&'b self) -> &'b Atom {
(self as &ElementHelpers).get_local_name()
}
fn get_namespace<'a>(&'a self) -> &'a Namespace {
fn get_namespace<'b>(&'b self) -> &'b Namespace {
(self as &ElementHelpers).get_namespace()
}
fn get_hover_state(&self) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions components/style/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ pub trait TNode<'a, E: TElement<'a>> : Clone {
}

pub trait TElement<'a> {
fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'static str>;
fn get_link(&self) -> Option<&'static str>;
fn get_local_name<'a>(&'a self) -> &'a Atom;
fn get_namespace<'a>(&'a self) -> &'a Namespace;
fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'a str>;
fn get_link(&self) -> Option<&'a str>;
fn get_local_name<'b>(&'b self) -> &'b Atom;
fn get_namespace<'b>(&'b self) -> &'b Namespace;
fn get_hover_state(&self) -> bool;
fn get_id(&self) -> Option<Atom>;
fn get_disabled_state(&self) -> bool;
Expand Down

5 comments on commit b2a3519

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging zwarich/servo/telement-lifetimes = b2a3519 into bors-servo-integration-3501-telement-lifetimes

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zwarich/servo/telement-lifetimes = b2a3519 merged ok, testing candidate = c9c8d63

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to bors-servo-integration-3501-telement-lifetimes = c9c8d63

Please sign in to comment.