mirror of
https://github.com/servo/servo.git
synced 2025-06-10 17:43:16 +00:00
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>
This commit is contained in:
parent
7f0d0830e7
commit
967925c119
4 changed files with 17 additions and 18 deletions
|
@ -127,6 +127,7 @@ builtinNames = {
|
|||
IDLType.Tags.int32array: 'Int32Array',
|
||||
IDLType.Tags.uint32array: 'Uint32Array',
|
||||
IDLType.Tags.float32array: 'Float32Array',
|
||||
IDLType.Tags.float64array: 'Float64Array',
|
||||
}
|
||||
|
||||
numericTags = [
|
||||
|
@ -6514,6 +6515,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
|||
'js::typedarray::Int32Array',
|
||||
'js::typedarray::Uint32Array',
|
||||
'js::typedarray::Float32Array',
|
||||
'js::typedarray::Float64Array',
|
||||
'crate::dom',
|
||||
'crate::dom::bindings',
|
||||
'crate::dom::bindings::codegen::InterfaceObjectMap',
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::ptr::NonNull;
|
||||
use std::{f64, ptr};
|
||||
|
||||
use cssparser::{Parser, ParserInput};
|
||||
|
@ -12,7 +11,7 @@ use euclid::default::Transform3D;
|
|||
use euclid::Angle;
|
||||
use js::jsapi::JSObject;
|
||||
use js::rust::{CustomAutoRooterGuard, HandleObject};
|
||||
use js::typedarray::{CreateWith, Float32Array, Float64Array};
|
||||
use js::typedarray::{Float32Array, Float64Array};
|
||||
use style::parser::ParserContext;
|
||||
|
||||
use crate::dom::bindings::cell::{DomRefCell, Ref};
|
||||
|
@ -691,14 +690,10 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
|
|||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-tofloat64array
|
||||
#[allow(unsafe_code)]
|
||||
fn ToFloat64Array(&self, cx: JSContext) -> NonNull<JSObject> {
|
||||
let arr = self.matrix.borrow().to_array();
|
||||
unsafe {
|
||||
fn ToFloat64Array(&self, cx: JSContext) -> Float64Array {
|
||||
rooted!(in (*cx) let mut array = ptr::null_mut::<JSObject>());
|
||||
let _ = Float64Array::create(*cx, CreateWith::Slice(&arr), array.handle_mut()).unwrap();
|
||||
NonNull::new_unchecked(array.get())
|
||||
}
|
||||
create_typed_array(cx, &self.matrix.borrow().to_array(), array.handle_mut())
|
||||
.expect("Converting matrix to float64 array should never fail")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
3
third_party/WebIDL/WebIDL.py
vendored
3
third_party/WebIDL/WebIDL.py
vendored
|
@ -2408,6 +2408,7 @@ class IDLType(IDLObject):
|
|||
"int32array",
|
||||
"uint32array",
|
||||
"float32array",
|
||||
"float64array",
|
||||
"dictionary",
|
||||
"enum",
|
||||
"callback",
|
||||
|
@ -3648,7 +3649,7 @@ class IDLBuiltinType(IDLType):
|
|||
Types.Int32Array: IDLType.Tags.int32array,
|
||||
Types.Uint32Array: IDLType.Tags.uint32array,
|
||||
Types.Float32Array: IDLType.Tags.float32array,
|
||||
Types.Float64Array: IDLType.Tags.interface,
|
||||
Types.Float64Array: IDLType.Tags.float64array,
|
||||
Types.ReadableStream: IDLType.Tags.interface,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue