Skip to content
Permalink
Browse files

Disambiguate methods without using trait objects

  • Loading branch information
Cameron Zwarich
Cameron Zwarich committed Oct 1, 2014
1 parent be9618d commit e894499c17b920494c008c30566fc1465aab4671
Showing with 63 additions and 9 deletions.
  1. +21 −3 components/script/dom/element.rs
  2. +42 −6 components/script/dom/node.rs
@@ -966,10 +966,22 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
}
}
fn get_local_name<'b>(&'b self) -> &'b Atom {
(self as &ElementHelpers).get_local_name()
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn get_local_name<'a, T: ElementHelpers<'a>>(this: T) -> &'a Atom {
this.get_local_name()
}

get_local_name(*self)
}
fn get_namespace<'b>(&'b self) -> &'b Namespace {
(self as &ElementHelpers).get_namespace()
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn get_namespace<'a, T: ElementHelpers<'a>>(this: T) -> &'a Namespace {
this.get_namespace()
}

get_namespace(*self)
}
fn get_hover_state(&self) -> bool {
let node: JSRef<Node> = NodeCast::from_ref(*self);
@@ -993,6 +1005,12 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
node.get_enabled_state()
}
fn has_class(&self, name: &str) -> bool {
(self as &AttributeHandlers).has_class(name)
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn has_class<T: AttributeHandlers>(this: T, name: &str) -> bool {
this.has_class(name)
}

has_class(*self, name)
}
}
@@ -2036,27 +2036,63 @@ impl<'a> VirtualMethods for JSRef<'a, Node> {

impl<'a> style::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> {
fn parent_node(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).parent_node().map(|node| *node.root())
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn parent_node<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option<Temporary<Node>> {
this.parent_node()
}

parent_node(*self).map(|node| *node.root())
}

fn first_child(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).first_child().map(|node| *node.root())
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn first_child<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option<Temporary<Node>> {
this.first_child()
}

first_child(*self).map(|node| *node.root())
}

fn prev_sibling(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).prev_sibling().map(|node| *node.root())
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn prev_sibling<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option<Temporary<Node>> {
this.prev_sibling()
}

prev_sibling(*self).map(|node| *node.root())
}

fn next_sibling(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).next_sibling().map(|node| *node.root())
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn next_sibling<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option<Temporary<Node>> {
this.next_sibling()
}

next_sibling(*self).map(|node| *node.root())
}

fn is_document(&self) -> bool {
(self as &NodeHelpers).is_document()
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn is_document<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> bool {
this.is_document()
}

is_document(*self)
}

fn is_element(&self) -> bool {
(self as &NodeHelpers).is_element()
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn is_element<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> bool {
this.is_element()
}

is_element(*self)
}

fn as_element(&self) -> JSRef<'a, Element> {

0 comments on commit e894499

Please sign in to comment.
You can’t perform that action at this time.