aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/attrlist.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/dom/attrlist.rs')
-rw-r--r--src/components/script/dom/attrlist.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/components/script/dom/attrlist.rs b/src/components/script/dom/attrlist.rs
index cfa6c2c083f..e707a42b13f 100644
--- a/src/components/script/dom/attrlist.rs
+++ b/src/components/script/dom/attrlist.rs
@@ -4,7 +4,7 @@
use dom::attr::Attr;
use dom::bindings::codegen::BindingDeclarations::AttrListBinding;
-use dom::bindings::js::JS;
+use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::Element;
use dom::window::Window;
@@ -17,28 +17,36 @@ pub struct AttrList {
}
impl AttrList {
- pub fn new_inherited(window: JS<Window>, elem: JS<Element>) -> AttrList {
+ pub fn new_inherited(window: &JSRef<Window>, elem: &JSRef<Element>) -> AttrList {
AttrList {
reflector_: Reflector::new(),
- window: window,
- owner: elem
+ window: window.unrooted(),
+ owner: elem.unrooted(),
}
}
- pub fn new(window: &JS<Window>, elem: &JS<Element>) -> JS<AttrList> {
- reflect_dom_object(~AttrList::new_inherited(window.clone(), elem.clone()),
+ pub fn new(window: &JSRef<Window>, elem: &JSRef<Element>) -> Temporary<AttrList> {
+ reflect_dom_object(~AttrList::new_inherited(window, elem),
window, AttrListBinding::Wrap)
}
+}
+
+pub trait AttrListMethods {
+ fn Length(&self) -> u32;
+ fn Item(&self, index: u32) -> Option<Temporary<Attr>>;
+ fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<Attr>>;
+}
- pub fn Length(&self) -> u32 {
- self.owner.get().attrs.len() as u32
+impl<'a> AttrListMethods for JSRef<'a, AttrList> {
+ fn Length(&self) -> u32 {
+ self.owner.root().attrs.len() as u32
}
- pub fn Item(&self, index: u32) -> Option<JS<Attr>> {
- self.owner.get().attrs.as_slice().get(index as uint).map(|x| x.clone())
+ fn Item(&self, index: u32) -> Option<Temporary<Attr>> {
+ self.owner.root().attrs.as_slice().get(index as uint).map(|x| Temporary::new(x.clone()))
}
- pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<Attr>> {
+ fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
let item = self.Item(index);
*found = item.is_some();
item