aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/gamepad.rs
diff options
context:
space:
mode:
authorTaym Haddadi <haddadi.taym@gmail.com>2024-01-30 09:45:29 +0100
committerGitHub <noreply@github.com>2024-01-30 08:45:29 +0000
commit967925c119f7af5131e4857aadeeaafb66f5fa33 (patch)
tree9166d9475b41496d1327de3eeab03e19c6d68161 /components/script/dom/gamepad.rs
parent7f0d0830e779f37da8aa7f7025edcebe57b2db26 (diff)
downloadservo-967925c119f7af5131e4857aadeeaafb66f5fa33.tar.gz
servo-967925c119f7af5131e4857aadeeaafb66f5fa33.zip
webidlg: Handle `Float64Array` as a `TypedArray` rather than a raw `JSObject` (#31189)
* WebIDL use FLoat64Array Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Use to_vec to convert array to vec * avoid allocating a new vec --------- Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
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