diff options
Diffstat (limited to 'components/script/dom/webxr/xrhand.rs')
-rw-r--r-- | components/script/dom/webxr/xrhand.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/components/script/dom/webxr/xrhand.rs b/components/script/dom/webxr/xrhand.rs index a9253ccb72b..b466cf32086 100644 --- a/components/script/dom/webxr/xrhand.rs +++ b/components/script/dom/webxr/xrhand.rs @@ -3,9 +3,12 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use dom_struct::dom_struct; +use js::jsapi::JSContext; +use js::rust::MutableHandleValue; use webxr_api::{FingerJoint, Hand, Joint}; use crate::dom::bindings::codegen::Bindings::XRHandBinding::{XRHandJoint, XRHandMethods}; +use crate::dom::bindings::conversions::ToJSValConvertible; use crate::dom::bindings::iterable::Iterable; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot}; @@ -163,19 +166,30 @@ impl XRHandMethods<crate::DomTypeHolder> for XRHand { } } +/// A wrapper to work around a crown error—Root<T> has a crown annotation on it that is not present +/// on the Iterable::Value associated type. The absence is harmless in this case. +pub(crate) struct ValueWrapper(pub DomRoot<XRJointSpace>); + +impl ToJSValConvertible for ValueWrapper { + #[allow(unsafe_code)] + unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { + self.0.to_jsval(cx, rval) + } +} + impl Iterable for XRHand { type Key = XRHandJoint; - type Value = DomRoot<XRJointSpace>; + type Value = ValueWrapper; fn get_iterable_length(&self) -> u32 { JOINT_SPACE_MAP.len() as u32 } - fn get_value_at_index(&self, n: u32) -> DomRoot<XRJointSpace> { + fn get_value_at_index(&self, n: u32) -> ValueWrapper { let joint = JOINT_SPACE_MAP[n as usize].1; self.spaces .get(joint) - .map(|j| DomRoot::from_ref(&**j)) + .map(|j| ValueWrapper(DomRoot::from_ref(&**j))) .expect("Failed to get joint pose") } |