mirror of
https://github.com/servo/servo.git
synced 2025-06-13 02:44:29 +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.int32array: 'Int32Array',
|
||||||
IDLType.Tags.uint32array: 'Uint32Array',
|
IDLType.Tags.uint32array: 'Uint32Array',
|
||||||
IDLType.Tags.float32array: 'Float32Array',
|
IDLType.Tags.float32array: 'Float32Array',
|
||||||
|
IDLType.Tags.float64array: 'Float64Array',
|
||||||
}
|
}
|
||||||
|
|
||||||
numericTags = [
|
numericTags = [
|
||||||
|
@ -6514,6 +6515,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
||||||
'js::typedarray::Int32Array',
|
'js::typedarray::Int32Array',
|
||||||
'js::typedarray::Uint32Array',
|
'js::typedarray::Uint32Array',
|
||||||
'js::typedarray::Float32Array',
|
'js::typedarray::Float32Array',
|
||||||
|
'js::typedarray::Float64Array',
|
||||||
'crate::dom',
|
'crate::dom',
|
||||||
'crate::dom::bindings',
|
'crate::dom::bindings',
|
||||||
'crate::dom::bindings::codegen::InterfaceObjectMap',
|
'crate::dom::bindings::codegen::InterfaceObjectMap',
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::ptr::NonNull;
|
|
||||||
use std::{f64, ptr};
|
use std::{f64, ptr};
|
||||||
|
|
||||||
use cssparser::{Parser, ParserInput};
|
use cssparser::{Parser, ParserInput};
|
||||||
|
@ -12,7 +11,7 @@ use euclid::default::Transform3D;
|
||||||
use euclid::Angle;
|
use euclid::Angle;
|
||||||
use js::jsapi::JSObject;
|
use js::jsapi::JSObject;
|
||||||
use js::rust::{CustomAutoRooterGuard, HandleObject};
|
use js::rust::{CustomAutoRooterGuard, HandleObject};
|
||||||
use js::typedarray::{CreateWith, Float32Array, Float64Array};
|
use js::typedarray::{Float32Array, Float64Array};
|
||||||
use style::parser::ParserContext;
|
use style::parser::ParserContext;
|
||||||
|
|
||||||
use crate::dom::bindings::cell::{DomRefCell, Ref};
|
use crate::dom::bindings::cell::{DomRefCell, Ref};
|
||||||
|
@ -691,14 +690,10 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-tofloat64array
|
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-tofloat64array
|
||||||
#[allow(unsafe_code)]
|
fn ToFloat64Array(&self, cx: JSContext) -> Float64Array {
|
||||||
fn ToFloat64Array(&self, cx: JSContext) -> NonNull<JSObject> {
|
|
||||||
let arr = self.matrix.borrow().to_array();
|
|
||||||
unsafe {
|
|
||||||
rooted!(in (*cx) let mut array = ptr::null_mut::<JSObject>());
|
rooted!(in (*cx) let mut array = ptr::null_mut::<JSObject>());
|
||||||
let _ = Float64Array::create(*cx, CreateWith::Slice(&arr), array.handle_mut()).unwrap();
|
create_typed_array(cx, &self.matrix.borrow().to_array(), array.handle_mut())
|
||||||
NonNull::new_unchecked(array.get())
|
.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/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::ptr::NonNull;
|
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
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::codegen::Bindings::GamepadBinding::{GamepadHand, GamepadMethods};
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::num::Finite;
|
use crate::dom::bindings::num::Finite;
|
||||||
|
@ -31,7 +31,7 @@ pub struct Gamepad {
|
||||||
timestamp: Cell<f64>,
|
timestamp: Cell<f64>,
|
||||||
mapping_type: String,
|
mapping_type: String,
|
||||||
#[ignore_malloc_size_of = "mozjs"]
|
#[ignore_malloc_size_of = "mozjs"]
|
||||||
axes: Heap<*mut JSObject>,
|
axes: HeapTypedArray<Float64>,
|
||||||
buttons: Dom<GamepadButtonList>,
|
buttons: Dom<GamepadButtonList>,
|
||||||
pose: Option<Dom<GamepadPose>>,
|
pose: Option<Dom<GamepadPose>>,
|
||||||
#[ignore_malloc_size_of = "Defined in rust-webvr"]
|
#[ignore_malloc_size_of = "Defined in rust-webvr"]
|
||||||
|
@ -60,7 +60,7 @@ impl Gamepad {
|
||||||
connected: Cell::new(connected),
|
connected: Cell::new(connected),
|
||||||
timestamp: Cell::new(timestamp),
|
timestamp: Cell::new(timestamp),
|
||||||
mapping_type: mapping_type,
|
mapping_type: mapping_type,
|
||||||
axes: Heap::default(),
|
axes: HeapTypedArray::default(),
|
||||||
buttons: Dom::from_ref(buttons),
|
buttons: Dom::from_ref(buttons),
|
||||||
pose: pose.map(Dom::from_ref),
|
pose: pose.map(Dom::from_ref),
|
||||||
hand: hand,
|
hand: hand,
|
||||||
|
@ -94,10 +94,11 @@ impl GamepadMethods for Gamepad {
|
||||||
DOMString::from(self.mapping_type.clone())
|
DOMString::from(self.mapping_type.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
// https://w3c.github.io/gamepad/#dom-gamepad-axes
|
// https://w3c.github.io/gamepad/#dom-gamepad-axes
|
||||||
fn Axes(&self, _cx: JSContext) -> NonNull<JSObject> {
|
fn Axes(&self, _cx: JSContext) -> Float64Array {
|
||||||
unsafe { NonNull::new_unchecked(self.axes.get()) }
|
self.axes
|
||||||
|
.get_internal()
|
||||||
|
.expect("Failed to get gamepad axes.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/gamepad/#dom-gamepad-buttons
|
// 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",
|
"int32array",
|
||||||
"uint32array",
|
"uint32array",
|
||||||
"float32array",
|
"float32array",
|
||||||
|
"float64array",
|
||||||
"dictionary",
|
"dictionary",
|
||||||
"enum",
|
"enum",
|
||||||
"callback",
|
"callback",
|
||||||
|
@ -3648,7 +3649,7 @@ class IDLBuiltinType(IDLType):
|
||||||
Types.Int32Array: IDLType.Tags.int32array,
|
Types.Int32Array: IDLType.Tags.int32array,
|
||||||
Types.Uint32Array: IDLType.Tags.uint32array,
|
Types.Uint32Array: IDLType.Tags.uint32array,
|
||||||
Types.Float32Array: IDLType.Tags.float32array,
|
Types.Float32Array: IDLType.Tags.float32array,
|
||||||
Types.Float64Array: IDLType.Tags.interface,
|
Types.Float64Array: IDLType.Tags.float64array,
|
||||||
Types.ReadableStream: IDLType.Tags.interface,
|
Types.ReadableStream: IDLType.Tags.interface,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue