Skip to content

Commit

Permalink
Add methods to XRInputSourceArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 8, 2019
1 parent 0777233 commit 868e5cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions components/script/dom/webidls/XRInputSourceArray.webidl
Expand Up @@ -6,7 +6,7 @@

[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
interface XRInputSourceArray {
// iterable<XRInputSource>;
// readonly attribute unsigned long length;
// getter XRInputSource(unsigned long index);
iterable<XRInputSource>;
readonly attribute unsigned long length;
getter XRInputSource(unsigned long index);
};
16 changes: 16 additions & 0 deletions components/script/dom/xrinputsourcearray.rs
Expand Up @@ -4,6 +4,7 @@

use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding;
use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding::XRInputSourceArrayMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
Expand Down Expand Up @@ -46,3 +47,18 @@ impl XRInputSourceArray {
});
}
}

impl XRInputSourceArrayMethods for XRInputSourceArray {
/// https://immersive-web.github.io/webxr/#dom-xrinputsourcearray-length
fn Length(&self) -> u32 {
self.input_sources.borrow().len() as u32
}

/// https://immersive-web.github.io/webxr/#xrinputsourcearray
fn IndexedGetter(&self, n: u32) -> Option<DomRoot<XRInputSource>> {
self.input_sources
.borrow()
.get(n as usize)
.map(|x| DomRoot::from_ref(&**x))
}
}

0 comments on commit 868e5cb

Please sign in to comment.