diff options
author | Josh Matthews <josh@joshmatthews.net> | 2013-11-30 21:04:49 +0100 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2014-02-24 15:16:42 -0500 |
commit | 625325434b5c7dc72e784a592f7e014c16cf1018 (patch) | |
tree | 9078f192cd7f41132a64124b7f70a3bb51e0936d /src/components/script/dom/nodelist.rs | |
parent | 061269f9639199a7419e2467ebbe3c28cac1e8ff (diff) | |
download | servo-625325434b5c7dc72e784a592f7e014c16cf1018.tar.gz servo-625325434b5c7dc72e784a592f7e014c16cf1018.zip |
Implement JSManaged for DOM objects.
Diffstat (limited to 'src/components/script/dom/nodelist.rs')
-rw-r--r-- | src/components/script/dom/nodelist.rs | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/components/script/dom/nodelist.rs b/src/components/script/dom/nodelist.rs index 6857add6600..84de1a56d19 100644 --- a/src/components/script/dom/nodelist.rs +++ b/src/components/script/dom/nodelist.rs @@ -3,43 +3,46 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::NodeListBinding; +use dom::bindings::js::JS; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; -use dom::node::AbstractNode; +use dom::node::{Node, NodeHelpers}; use dom::window::Window; +#[deriving(Encodable)] enum NodeListType { - Simple(~[AbstractNode]), - Children(AbstractNode) + Simple(~[JS<Node>]), + Children(JS<Node>) } +#[deriving(Encodable)] pub struct NodeList { list_type: NodeListType, reflector_: Reflector, - window: @mut Window, + window: JS<Window> } impl NodeList { - pub fn new_inherited(window: @mut Window, + pub fn new_inherited(window: JS<Window>, list_type: NodeListType) -> NodeList { NodeList { list_type: list_type, reflector_: Reflector::new(), - window: window, + window: window } } - pub fn new(window: @mut Window, - list_type: NodeListType) -> @mut NodeList { - reflect_dom_object(@mut NodeList::new_inherited(window, list_type), - window, NodeListBinding::Wrap) + pub fn new(window: JS<Window>, + list_type: NodeListType) -> JS<NodeList> { + reflect_dom_object(~NodeList::new_inherited(window.clone(), list_type), + window.get(), NodeListBinding::Wrap) } - pub fn new_simple_list(window: @mut Window, elements: ~[AbstractNode]) -> @mut NodeList { - NodeList::new(window, Simple(elements)) + pub fn new_simple_list(window: &JS<Window>, elements: ~[JS<Node>]) -> JS<NodeList> { + NodeList::new(window.clone(), Simple(elements)) } - pub fn new_child_list(window: @mut Window, node: AbstractNode) -> @mut NodeList { - NodeList::new(window, Children(node)) + pub fn new_child_list(window: &JS<Window>, node: &JS<Node>) -> JS<NodeList> { + NodeList::new(window.clone(), Children(node.clone())) } pub fn Length(&self) -> u32 { @@ -49,15 +52,15 @@ impl NodeList { } } - pub fn Item(&self, index: u32) -> Option<AbstractNode> { + pub fn Item(&self, index: u32) -> Option<JS<Node>> { match self.list_type { _ if index >= self.Length() => None, - Simple(ref elems) => Some(elems[index]), + Simple(ref elems) => Some(elems[index].clone()), Children(ref node) => node.children().nth(index as uint) } } - pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<AbstractNode> { + pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<Node>> { let item = self.Item(index); *found = item.is_some(); item |