diff options
author | bors-servo <metajack+bors@gmail.com> | 2014-11-28 09:24:44 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2014-11-28 09:24:44 -0700 |
commit | 82050d1e535681ea993e4290d02bcf4b9f4ee5a2 (patch) | |
tree | 35fde6cd718b3e2da95986c00bb9997837000ce7 | |
parent | fafd3fd8ba6d2e43ad8cc34ac0f4cc9e835e6867 (diff) | |
parent | 1305ac4dd0e6764ac929c0e9303fb50ce291df74 (diff) | |
download | servo-82050d1e535681ea993e4290d02bcf4b9f4ee5a2.tar.gz servo-82050d1e535681ea993e4290d02bcf4b9f4ee5a2.zip |
auto merge of #4130 : saneyuki/servo/cast, r=Manishearth
Fix #4124
This also introduce `BarCast::from_actual()` which is used for up-cast for dom's actual data types (non JS pointer values).
-rw-r--r-- | components/layout/wrapper.rs | 10 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 12 | ||||
-rw-r--r-- | components/script/dom/element.rs | 5 | ||||
-rw-r--r-- | components/script/dom/htmlelement.rs | 5 | ||||
-rw-r--r-- | components/script/dom/node.rs | 5 | ||||
-rw-r--r-- | components/script/dom/uievent.rs | 5 |
6 files changed, 14 insertions, 28 deletions
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 4f774041979..11ef5b66822 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -39,7 +39,7 @@ use util::{PrivateLayoutData}; use gfx::display_list::OpaqueNode; use script::dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementCast}; use script::dom::bindings::codegen::InheritTypes::{HTMLImageElementCast, HTMLInputElementCast}; -use script::dom::bindings::codegen::InheritTypes::{TextCast}; +use script::dom::bindings::codegen::InheritTypes::{NodeCast, TextCast}; use script::dom::bindings::js::JS; use script::dom::element::{Element, HTMLAreaElementTypeId, HTMLAnchorElementTypeId}; use script::dom::element::{HTMLLinkElementTypeId, LayoutElementHelpers, RawLayoutElementHelpers}; @@ -508,7 +508,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> { fn get_link(self) -> Option<&'le str> { // FIXME: This is HTML only. - match self.element.node().type_id_for_layout() { + match NodeCast::from_actual(self.element).type_id_for_layout() { // http://www.whatwg.org/specs/web-apps/current-work/multipage/selectors.html# // selector-link ElementNodeTypeId(HTMLAnchorElementTypeId) | @@ -525,7 +525,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> { #[inline] fn get_hover_state(self) -> bool { unsafe { - self.element.node().get_hover_state_for_layout() + NodeCast::from_actual(self.element).get_hover_state_for_layout() } } @@ -539,14 +539,14 @@ impl<'le> TElement<'le> for LayoutElement<'le> { #[inline] fn get_disabled_state(self) -> bool { unsafe { - self.element.node().get_disabled_state_for_layout() + NodeCast::from_actual(self.element).get_disabled_state_for_layout() } } #[inline] fn get_enabled_state(self) -> bool { unsafe { - self.element.node().get_enabled_state_for_layout() + NodeCast::from_actual(self.element).get_enabled_state_for_layout() } } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 9a2cb83bcb1..fbb67e5bb9e 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -5185,7 +5185,8 @@ class GlobalGenRoots(): CGGeneric("use dom::bindings::js::{JS, JSRef, Temporary};\n"), CGGeneric("use dom::bindings::trace::JSTraceable;\n"), CGGeneric("use dom::bindings::utils::Reflectable;\n"), - CGGeneric("use js::jsapi::JSTracer;\n\n")] + CGGeneric("use js::jsapi::JSTracer;\n\n"), + CGGeneric("use std::mem;\n\n")] for descriptor in descriptors: name = descriptor.name protos = [CGGeneric('pub trait %s {}\n' % (name + 'Base'))] @@ -5199,13 +5200,13 @@ class GlobalGenRoots(): delegate = string.Template('''impl ${selfName} for ${baseName} { #[inline] fn ${fname}(&self) -> bool { - self.${parentName}().${fname}() + ${parentName}Cast::from_actual(self).${fname}() } } ''').substitute({'fname': 'is_' + name.lower(), 'selfName': name + 'Derived', 'baseName': protoDescriptor.concreteType, - 'parentName': protoDescriptor.prototypeChain[-2].lower()}) + 'parentName': protoDescriptor.prototypeChain[-2]}) derived += [CGGeneric(delegate)] derived += [CGGeneric('\n')] @@ -5251,6 +5252,11 @@ class GlobalGenRoots(): fn from_temporary<T: ${fromBound}+Reflectable>(derived: Temporary<T>) -> Temporary<Self> { unsafe { derived.transmute() } } + + #[inline(always)] + fn from_actual<'a, T: ${fromBound}+Reflectable>(derived: &T) -> &'a Self { + unsafe { mem::transmute(derived) } + } } ''').substitute({'checkFn': 'is_' + name.lower(), 'castTraitName': name + 'Cast', diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index b6da0dc39b1..79ecfe93743 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -184,11 +184,6 @@ impl Element { } #[inline] - pub fn node<'a>(&'a self) -> &'a Node { - &self.node - } - - #[inline] pub fn local_name<'a>(&'a self) -> &'a Atom { &self.local_name } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 7052fb873ad..75ad910ee2e 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -50,11 +50,6 @@ impl HTMLElement { let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, prefix, document); Node::reflect_node(box element, document, HTMLElementBinding::Wrap) } - - #[inline] - pub fn element<'a>(&'a self) -> &'a Element { - &self.element - } } trait PrivateHTMLElementHelpers { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index a1d724e2a88..f1185d73fe6 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1150,11 +1150,6 @@ impl Node { } #[inline] - pub fn eventtarget<'a>(&'a self) -> &'a EventTarget { - &self.eventtarget - } - - #[inline] pub fn layout_data(&self) -> Ref<Option<LayoutData>> { self.layout_data.borrow() } diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs index 036de7bfb64..ccd95eea81e 100644 --- a/components/script/dom/uievent.rs +++ b/components/script/dom/uievent.rs @@ -66,11 +66,6 @@ impl UIEvent { init.view.root_ref(), init.detail); Ok(event) } - - #[inline] - pub fn event<'a>(&'a self) -> &'a Event { - &self.event - } } impl<'a> UIEventMethods for JSRef<'a, UIEvent> { |