aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/clientrectlist.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/script/dom/clientrectlist.rs')
-rw-r--r--src/components/script/dom/clientrectlist.rs32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/components/script/dom/clientrectlist.rs b/src/components/script/dom/clientrectlist.rs
index 906cfaa65e9..d48cfadf2d7 100644
--- a/src/components/script/dom/clientrectlist.rs
+++ b/src/components/script/dom/clientrectlist.rs
@@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::BindingDeclarations::ClientRectListBinding;
-use dom::bindings::js::JS;
+use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::clientrect::ClientRect;
use dom::window::Window;
@@ -16,34 +16,42 @@ pub struct ClientRectList {
}
impl ClientRectList {
- pub fn new_inherited(window: JS<Window>,
- rects: Vec<JS<ClientRect>>) -> ClientRectList {
+ pub fn new_inherited(window: &JSRef<Window>,
+ rects: Vec<JSRef<ClientRect>>) -> ClientRectList {
ClientRectList {
reflector_: Reflector::new(),
- rects: rects,
- window: window,
+ rects: rects.iter().map(|rect| rect.unrooted()).collect(),
+ window: window.unrooted(),
}
}
- pub fn new(window: &JS<Window>,
- rects: Vec<JS<ClientRect>>) -> JS<ClientRectList> {
- reflect_dom_object(~ClientRectList::new_inherited(window.clone(), rects),
+ pub fn new(window: &JSRef<Window>,
+ rects: Vec<JSRef<ClientRect>>) -> Temporary<ClientRectList> {
+ reflect_dom_object(~ClientRectList::new_inherited(window, rects),
window, ClientRectListBinding::Wrap)
}
+}
+
+pub trait ClientRectListMethods {
+ fn Length(&self) -> u32;
+ fn Item(&self, index: u32) -> Option<Temporary<ClientRect>>;
+ fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<ClientRect>>;
+}
- pub fn Length(&self) -> u32 {
+impl<'a> ClientRectListMethods for JSRef<'a, ClientRectList> {
+ fn Length(&self) -> u32 {
self.rects.len() as u32
}
- pub fn Item(&self, index: u32) -> Option<JS<ClientRect>> {
+ fn Item(&self, index: u32) -> Option<Temporary<ClientRect>> {
if index < self.rects.len() as u32 {
- Some(self.rects.get(index as uint).clone())
+ Some(Temporary::new(self.rects.get(index as uint).clone()))
} else {
None
}
}
- pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<ClientRect>> {
+ fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<ClientRect>> {
*found = index < self.rects.len() as u32;
self.Item(index)
}