From e894499c17b920494c008c30566fc1465aab4671 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Tue, 30 Sep 2014 20:36:38 -0700 Subject: [PATCH] Disambiguate methods without using trait objects --- components/script/dom/element.rs | 24 ++++++++++++++-- components/script/dom/node.rs | 48 ++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 821ac1f9909..a0d843a4dba 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.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 = 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(this: T, name: &str) -> bool { + this.has_class(name) + } + + has_class(*self, name) } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 554f3686e03..6067b901613 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -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> { - (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> { + this.parent_node() + } + + parent_node(*self).map(|node| *node.root()) } fn first_child(&self) -> Option> { - (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> { + this.first_child() + } + + first_child(*self).map(|node| *node.root()) } fn prev_sibling(&self) -> Option> { - (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> { + this.prev_sibling() + } + + prev_sibling(*self).map(|node| *node.root()) } fn next_sibling(&self) -> Option> { - (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> { + 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> {