aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/gamepad.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/gamepad.rs')
-rw-r--r--components/script/dom/gamepad.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/components/script/dom/gamepad.rs b/components/script/dom/gamepad.rs
index e24f0848222..b0e7f04b818 100644
--- a/components/script/dom/gamepad.rs
+++ b/components/script/dom/gamepad.rs
@@ -3,11 +3,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::cell::Cell;
-use std::ptr::NonNull;
use dom_struct::dom_struct;
-use js::jsapi::{Heap, JSObject};
+use js::typedarray::{Float64, Float64Array};
+use super::bindings::typedarrays::HeapTypedArray;
use crate::dom::bindings::codegen::Bindings::GamepadBinding::{GamepadHand, GamepadMethods};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
@@ -31,7 +31,7 @@ pub struct Gamepad {
timestamp: Cell<f64>,
mapping_type: String,
#[ignore_malloc_size_of = "mozjs"]
- axes: Heap<*mut JSObject>,
+ axes: HeapTypedArray<Float64>,
buttons: Dom<GamepadButtonList>,
pose: Option<Dom<GamepadPose>>,
#[ignore_malloc_size_of = "Defined in rust-webvr"]
@@ -60,7 +60,7 @@ impl Gamepad {
connected: Cell::new(connected),
timestamp: Cell::new(timestamp),
mapping_type: mapping_type,
- axes: Heap::default(),
+ axes: HeapTypedArray::default(),
buttons: Dom::from_ref(buttons),
pose: pose.map(Dom::from_ref),
hand: hand,
@@ -94,10 +94,11 @@ impl GamepadMethods for Gamepad {
DOMString::from(self.mapping_type.clone())
}
- #[allow(unsafe_code)]
// https://w3c.github.io/gamepad/#dom-gamepad-axes
- fn Axes(&self, _cx: JSContext) -> NonNull<JSObject> {
- unsafe { NonNull::new_unchecked(self.axes.get()) }
+ fn Axes(&self, _cx: JSContext) -> Float64Array {
+ self.axes
+ .get_internal()
+ .expect("Failed to get gamepad axes.")
}
// https://w3c.github.io/gamepad/#dom-gamepad-buttons