mirror of
https://github.com/servo/servo.git
synced 2025-06-20 23:28:59 +01:00
Implement JSManaged for DOM objects.
This commit is contained in:
parent
061269f963
commit
625325434b
137 changed files with 3644 additions and 2778 deletions
|
@ -3,9 +3,10 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::HTMLCollectionBinding;
|
||||
use dom::bindings::js::JS;
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::utils::Fallible;
|
||||
use dom::node::AbstractNode;
|
||||
use dom::element::Element;
|
||||
use dom::window::Window;
|
||||
use servo_util::str::DOMString;
|
||||
|
||||
|
@ -13,14 +14,15 @@ use js::jsapi::{JSObject, JSContext};
|
|||
|
||||
use std::ptr;
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub struct HTMLCollection {
|
||||
elements: ~[AbstractNode],
|
||||
elements: ~[JS<Element>],
|
||||
reflector_: Reflector,
|
||||
window: @mut Window,
|
||||
window: JS<Window>,
|
||||
}
|
||||
|
||||
impl HTMLCollection {
|
||||
pub fn new_inherited(window: @mut Window, elements: ~[AbstractNode]) -> HTMLCollection {
|
||||
pub fn new_inherited(window: JS<Window>, elements: ~[JS<Element>]) -> HTMLCollection {
|
||||
HTMLCollection {
|
||||
elements: elements,
|
||||
reflector_: Reflector::new(),
|
||||
|
@ -28,18 +30,18 @@ impl HTMLCollection {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: @mut Window, elements: ~[AbstractNode]) -> @mut HTMLCollection {
|
||||
reflect_dom_object(@mut HTMLCollection::new_inherited(window, elements),
|
||||
window, HTMLCollectionBinding::Wrap)
|
||||
pub fn new(window: &JS<Window>, elements: ~[JS<Element>]) -> JS<HTMLCollection> {
|
||||
reflect_dom_object(~HTMLCollection::new_inherited(window.clone(), elements),
|
||||
window.get(), HTMLCollectionBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn Length(&self) -> u32 {
|
||||
self.elements.len() as u32
|
||||
}
|
||||
|
||||
pub fn Item(&self, index: u32) -> Option<AbstractNode> {
|
||||
pub fn Item(&self, index: u32) -> Option<JS<Element>> {
|
||||
if index < self.Length() {
|
||||
Some(self.elements[index])
|
||||
Some(self.elements[index].clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -49,7 +51,7 @@ impl HTMLCollection {
|
|||
Ok(ptr::null())
|
||||
}
|
||||
|
||||
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<AbstractNode> {
|
||||
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<Element>> {
|
||||
*found = true;
|
||||
self.Item(index)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue