mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +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
|
@ -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 {
|
||||
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())
|
||||
}
|
||||
fn ToFloat64Array(&self, cx: JSContext) -> Float64Array {
|
||||
rooted!(in (*cx) let mut array = ptr::null_mut::<JSObject>());
|
||||
create_typed_array(cx, &self.matrix.borrow().to_array(), array.handle_mut())
|
||||
.expect("Converting matrix to float64 array should never fail")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue