diff --git a/components/script/dom/dommatrix.rs b/components/script/dom/dommatrix.rs index 0eb0cc3e29e..f5658a9433f 100644 --- a/components/script/dom/dommatrix.rs +++ b/components/script/dom/dommatrix.rs @@ -12,7 +12,8 @@ use dom::dommatrixreadonly::{dommatrixinit_to_matrix, DOMMatrixReadOnly, entries use dom::globalscope::GlobalScope; use dom_struct::dom_struct; use euclid::Transform3D; - +use js::rust::CustomAutoRooterGuard; +use js::typedarray::{Float32Array, Float64Array}; #[dom_struct] pub struct DOMMatrix { @@ -56,315 +57,333 @@ impl DOMMatrix { pub fn from_readonly(global: &GlobalScope, ro: &DOMMatrixReadOnly) -> DomRoot { Self::new(global, ro.is_2d(), ro.matrix().clone()) } + + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-fromfloat32array + pub fn FromFloat32Array( + global: &GlobalScope, + mut array: CustomAutoRooterGuard) + -> Fallible> { + let vec: Vec = array.to_vec().iter().map(|&x| x as f64).collect(); + DOMMatrix::Constructor_(global, vec) + } + + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-fromfloat64array + pub fn FromFloat64Array( + global: &GlobalScope, + mut array: CustomAutoRooterGuard) + -> Fallible> { + let vec: Vec = array.to_vec(); + DOMMatrix::Constructor_(global, vec) + } } impl DOMMatrixMethods for DOMMatrix { - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m11 - fn M11(&self) -> f64 { - self.upcast::().M11() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m11 + fn M11(&self) -> f64 { + self.upcast::().M11() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m11 - fn SetM11(&self, value: f64) { - self.upcast::().set_m11(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m11 + fn SetM11(&self, value: f64) { + self.upcast::().set_m11(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m12 - fn M12(&self) -> f64 { - self.upcast::().M12() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m12 + fn M12(&self) -> f64 { + self.upcast::().M12() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m12 - fn SetM12(&self, value: f64) { - self.upcast::().set_m12(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m12 + fn SetM12(&self, value: f64) { + self.upcast::().set_m12(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m13 - fn M13(&self) -> f64 { - self.upcast::().M13() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m13 + fn M13(&self) -> f64 { + self.upcast::().M13() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m13 - fn SetM13(&self, value: f64) { - self.upcast::().set_m13(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m13 + fn SetM13(&self, value: f64) { + self.upcast::().set_m13(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m14 - fn M14(&self) -> f64 { - self.upcast::().M14() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m14 + fn M14(&self) -> f64 { + self.upcast::().M14() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m14 - fn SetM14(&self, value: f64) { - self.upcast::().set_m14(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m14 + fn SetM14(&self, value: f64) { + self.upcast::().set_m14(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m21 - fn M21(&self) -> f64 { - self.upcast::().M21() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m21 + fn M21(&self) -> f64 { + self.upcast::().M21() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m21 - fn SetM21(&self, value: f64) { - self.upcast::().set_m21(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m21 + fn SetM21(&self, value: f64) { + self.upcast::().set_m21(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m22 - fn M22(&self) -> f64 { - self.upcast::().M22() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m22 + fn M22(&self) -> f64 { + self.upcast::().M22() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m22 - fn SetM22(&self, value: f64) { - self.upcast::().set_m22(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m22 + fn SetM22(&self, value: f64) { + self.upcast::().set_m22(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m23 - fn M23(&self) -> f64 { - self.upcast::().M23() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m23 + fn M23(&self) -> f64 { + self.upcast::().M23() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m23 - fn SetM23(&self, value: f64) { - self.upcast::().set_m23(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m23 + fn SetM23(&self, value: f64) { + self.upcast::().set_m23(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m24 - fn M24(&self) -> f64 { - self.upcast::().M24() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m24 + fn M24(&self) -> f64 { + self.upcast::().M24() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m24 - fn SetM24(&self, value: f64) { - self.upcast::().set_m24(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m24 + fn SetM24(&self, value: f64) { + self.upcast::().set_m24(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m31 - fn M31(&self) -> f64 { - self.upcast::().M31() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m31 + fn M31(&self) -> f64 { + self.upcast::().M31() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m31 - fn SetM31(&self, value: f64) { - self.upcast::().set_m31(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m31 + fn SetM31(&self, value: f64) { + self.upcast::().set_m31(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m32 - fn M32(&self) -> f64 { - self.upcast::().M32() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m32 + fn M32(&self) -> f64 { + self.upcast::().M32() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m32 - fn SetM32(&self, value: f64) { - self.upcast::().set_m32(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m32 + fn SetM32(&self, value: f64) { + self.upcast::().set_m32(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m33 - fn M33(&self) -> f64 { - self.upcast::().M33() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m33 + fn M33(&self) -> f64 { + self.upcast::().M33() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m33 - fn SetM33(&self, value: f64) { - self.upcast::().set_m33(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m33 + fn SetM33(&self, value: f64) { + self.upcast::().set_m33(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m34 - fn M34(&self) -> f64 { - self.upcast::().M34() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m34 + fn M34(&self) -> f64 { + self.upcast::().M34() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m34 - fn SetM34(&self, value: f64) { - self.upcast::().set_m34(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m34 + fn SetM34(&self, value: f64) { + self.upcast::().set_m34(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m41 - fn M41(&self) -> f64 { - self.upcast::().M41() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m41 + fn M41(&self) -> f64 { + self.upcast::().M41() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m41 - fn SetM41(&self, value: f64) { - self.upcast::().set_m41(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m41 + fn SetM41(&self, value: f64) { + self.upcast::().set_m41(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m42 - fn M42(&self) -> f64 { - self.upcast::().M42() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m42 + fn M42(&self) -> f64 { + self.upcast::().M42() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m42 - fn SetM42(&self, value: f64) { - self.upcast::().set_m42(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m42 + fn SetM42(&self, value: f64) { + self.upcast::().set_m42(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m43 - fn M43(&self) -> f64 { - self.upcast::().M43() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m43 + fn M43(&self) -> f64 { + self.upcast::().M43() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m43 - fn SetM43(&self, value: f64) { - self.upcast::().set_m43(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m43 + fn SetM43(&self, value: f64) { + self.upcast::().set_m43(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m44 - fn M44(&self) -> f64 { - self.upcast::().M44() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m44 + fn M44(&self) -> f64 { + self.upcast::().M44() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m44 - fn SetM44(&self, value: f64) { - self.upcast::().set_m44(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m44 + fn SetM44(&self, value: f64) { + self.upcast::().set_m44(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-a - fn A(&self) -> f64 { - self.upcast::().A() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-a + fn A(&self) -> f64 { + self.upcast::().A() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-a - fn SetA(&self, value: f64) { - self.upcast::().set_m11(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-a + fn SetA(&self, value: f64) { + self.upcast::().set_m11(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-b - fn B(&self) -> f64 { - self.upcast::().B() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-b + fn B(&self) -> f64 { + self.upcast::().B() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-b - fn SetB(&self, value: f64) { - self.upcast::().set_m12(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-b + fn SetB(&self, value: f64) { + self.upcast::().set_m12(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-c - fn C(&self) -> f64 { - self.upcast::().C() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-c + fn C(&self) -> f64 { + self.upcast::().C() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-c - fn SetC(&self, value: f64) { - self.upcast::().set_m21(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-c + fn SetC(&self, value: f64) { + self.upcast::().set_m21(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-d - fn D(&self) -> f64 { - self.upcast::().D() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-d + fn D(&self) -> f64 { + self.upcast::().D() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-d - fn SetD(&self, value: f64) { - self.upcast::().set_m22(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-d + fn SetD(&self, value: f64) { + self.upcast::().set_m22(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-e - fn E(&self) -> f64 { - self.upcast::().E() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-e + fn E(&self) -> f64 { + self.upcast::().E() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-e - fn SetE(&self, value: f64) { - self.upcast::().set_m41(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-e + fn SetE(&self, value: f64) { + self.upcast::().set_m41(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-f - fn F(&self) -> f64 { - self.upcast::().F() - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-f + fn F(&self) -> f64 { + self.upcast::().F() + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-f - fn SetF(&self, value: f64) { - self.upcast::().set_m42(value); - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-f + fn SetF(&self, value: f64) { + self.upcast::().set_m42(value); + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-multiplyself - fn MultiplySelf(&self, other:&DOMMatrixInit) -> Fallible> { - // Steps 1-3. - self.upcast::().multiply_self(other) - // Step 4. - .and(Ok(DomRoot::from_ref(&self))) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-multiplyself + fn MultiplySelf(&self, other:&DOMMatrixInit) -> Fallible> { + // Steps 1-3. + self.upcast::().multiply_self(other) + // Step 4. + .and(Ok(DomRoot::from_ref(&self))) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-premultiplyself - fn PreMultiplySelf(&self, other:&DOMMatrixInit) -> Fallible> { - // Steps 1-3. - self.upcast::().pre_multiply_self(other) - // Step 4. - .and(Ok(DomRoot::from_ref(&self))) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-premultiplyself + fn PreMultiplySelf(&self, other:&DOMMatrixInit) -> Fallible> { + // Steps 1-3. + self.upcast::().pre_multiply_self(other) + // Step 4. + .and(Ok(DomRoot::from_ref(&self))) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-translateself - fn TranslateSelf(&self, tx: f64, ty: f64, tz: f64) -> DomRoot { - // Steps 1-2. - self.upcast::().translate_self(tx, ty, tz); - // Step 3. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-translateself + fn TranslateSelf(&self, tx: f64, ty: f64, tz: f64) -> DomRoot { + // Steps 1-2. + self.upcast::().translate_self(tx, ty, tz); + // Step 3. + DomRoot::from_ref(&self) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-scaleself - fn ScaleSelf(&self, scaleX: f64, scaleY: Option, scaleZ: f64, - originX: f64, originY: f64, originZ: f64) -> DomRoot { - // Steps 1-6. - self.upcast::().scale_self(scaleX, scaleY, scaleZ, originX, originY, originZ); - // Step 7. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-scaleself + fn ScaleSelf(&self, scaleX: f64, scaleY: Option, scaleZ: f64, + originX: f64, originY: f64, originZ: f64) -> DomRoot { + // Steps 1-6. + self.upcast::().scale_self(scaleX, scaleY, scaleZ, originX, originY, originZ); + // Step 7. + DomRoot::from_ref(&self) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-scale3dself - fn Scale3dSelf(&self, scale: f64, originX: f64, originY: f64, originZ: f64) -> DomRoot { - // Steps 1-4. - self.upcast::().scale_3d_self(scale, originX, originY, originZ); - // Step 5. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-scale3dself + fn Scale3dSelf(&self, scale: f64, originX: f64, originY: f64, originZ: f64) -> DomRoot { + // Steps 1-4. + self.upcast::().scale_3d_self(scale, originX, originY, originZ); + // Step 5. + DomRoot::from_ref(&self) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotateself - fn RotateSelf(&self, rotX: f64, rotY: Option, rotZ: Option) -> DomRoot { - // Steps 1-7. - self.upcast::().rotate_self(rotX, rotY, rotZ); - // Step 8. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotateself + fn RotateSelf(&self, rotX: f64, rotY: Option, rotZ: Option) -> DomRoot { + // Steps 1-7. + self.upcast::().rotate_self(rotX, rotY, rotZ); + // Step 8. + DomRoot::from_ref(&self) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotatefromvectorself - fn RotateFromVectorSelf(&self, x: f64, y: f64) -> DomRoot { - // Step 1. - self.upcast::().rotate_from_vector_self(x, y); - // Step 2. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotatefromvectorself + fn RotateFromVectorSelf(&self, x: f64, y: f64) -> DomRoot { + // Step 1. + self.upcast::().rotate_from_vector_self(x, y); + // Step 2. + DomRoot::from_ref(&self) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotateaxisangleself - fn RotateAxisAngleSelf(&self, x: f64, y: f64, z: f64, angle: f64) -> DomRoot { - // Steps 1-2. - self.upcast::().rotate_axis_angle_self(x, y, z, angle); - // Step 3. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-rotateaxisangleself + fn RotateAxisAngleSelf(&self, x: f64, y: f64, z: f64, angle: f64) -> DomRoot { + // Steps 1-2. + self.upcast::().rotate_axis_angle_self(x, y, z, angle); + // Step 3. + DomRoot::from_ref(&self) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-skewxself - fn SkewXSelf(&self, sx: f64) -> DomRoot { - // Step 1. - self.upcast::().skew_x_self(sx); - // Step 2. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-skewxself + fn SkewXSelf(&self, sx: f64) -> DomRoot { + // Step 1. + self.upcast::().skew_x_self(sx); + // Step 2. + DomRoot::from_ref(&self) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-skewyself - fn SkewYSelf(&self, sy: f64) -> DomRoot { - // Step 1. - self.upcast::().skew_y_self(sy); - // Step 2. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-skewyself + fn SkewYSelf(&self, sy: f64) -> DomRoot { + // Step 1. + self.upcast::().skew_y_self(sy); + // Step 2. + DomRoot::from_ref(&self) + } - // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-invertself - fn InvertSelf(&self) -> DomRoot { - // Steps 1-2. - self.upcast::().invert_self(); - // Step 3. - DomRoot::from_ref(&self) - } + // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-invertself + fn InvertSelf(&self) -> DomRoot { + // Steps 1-2. + self.upcast::().invert_self(); + // Step 3. + DomRoot::from_ref(&self) + } } diff --git a/components/script/dom/dommatrixreadonly.rs b/components/script/dom/dommatrixreadonly.rs index 416ea48a19f..232ebb5817e 100644 --- a/components/script/dom/dommatrixreadonly.rs +++ b/components/script/dom/dommatrixreadonly.rs @@ -15,8 +15,14 @@ use dom::dompoint::DOMPoint; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; use euclid::{Transform3D, Angle}; +use js::jsapi::{JSObject, JSContext}; +use js::rust::CustomAutoRooterGuard; +use js::typedarray::{Float32Array, Float64Array}; +use js::typedarray::CreateWith; use std::cell::{Cell, Ref}; use std::f64; +use std::ptr; +use std::ptr::NonNull; #[dom_struct] pub struct DOMMatrixReadOnly { @@ -334,6 +340,27 @@ impl DOMMatrixReadOnly { }) // Step 3 in DOMMatrix.InvertSelf } + + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-fromfloat32array + #[allow(unsafe_code)] + pub fn FromFloat32Array( + global: &GlobalScope, + mut array: CustomAutoRooterGuard) + -> Fallible> { + let vec: Vec = array.to_vec().iter().map(|&x| x as f64).collect(); + DOMMatrixReadOnly::Constructor_(global, vec) + } + + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-fromfloat64array + #[allow(unsafe_code)] + pub fn FromFloat64Array( + global: &GlobalScope, + mut array: CustomAutoRooterGuard) + -> Fallible> { + let vec: Vec = array.to_vec(); + DOMMatrixReadOnly::Constructor_(global, vec) + } + } @@ -553,6 +580,27 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { DOMPoint::new(&self.global(), x, y, z, w) } + + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-tofloat32array + #[allow(unsafe_code)] + unsafe fn ToFloat32Array(&self, cx: *mut JSContext) -> NonNull { + let vec: Vec = self.matrix + .borrow().to_row_major_array().iter().map(|&x| x as f32).collect(); + rooted!(in (cx) let mut array = ptr::null_mut::()); + let _ = Float32Array::create(cx, CreateWith::Slice(&vec), array.handle_mut()) + .unwrap(); + NonNull::new_unchecked(array.get()) + } + + // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-tofloat64array + #[allow(unsafe_code)] + unsafe fn ToFloat64Array(&self, cx: *mut JSContext) -> NonNull { + let arr = self.matrix.borrow().to_row_major_array(); + rooted!(in (cx) let mut array = ptr::null_mut::()); + let _ = Float64Array::create(cx, CreateWith::Slice(&arr), array.handle_mut()) + .unwrap(); + NonNull::new_unchecked(array.get()) + } } diff --git a/components/script/dom/webidls/DOMMatrix.webidl b/components/script/dom/webidls/DOMMatrix.webidl index d1dd65e8a63..b199f204908 100644 --- a/components/script/dom/webidls/DOMMatrix.webidl +++ b/components/script/dom/webidls/DOMMatrix.webidl @@ -17,8 +17,8 @@ interface DOMMatrix : DOMMatrixReadOnly { [NewObject, Throws] static DOMMatrix fromMatrix(optional DOMMatrixInit other); -// [NewObject] static DOMMatrix fromFloat32Array(Float32Array array32); -// [NewObject] static DOMMatrix fromFloat64Array(Float64Array array64); + [NewObject, Throws] static DOMMatrix fromFloat32Array(Float32Array array32); + [NewObject, Throws] static DOMMatrix fromFloat64Array(Float64Array array64); // These attributes are simple aliases for certain elements of the 4x4 matrix inherit attribute unrestricted double a; diff --git a/components/script/dom/webidls/DOMMatrixReadOnly.webidl b/components/script/dom/webidls/DOMMatrixReadOnly.webidl index 9261002e348..f80fd1c9c1d 100644 --- a/components/script/dom/webidls/DOMMatrixReadOnly.webidl +++ b/components/script/dom/webidls/DOMMatrixReadOnly.webidl @@ -17,8 +17,8 @@ interface DOMMatrixReadOnly { [NewObject, Throws] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other); -// [NewObject] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32); -// [NewObject] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64); + [NewObject, Throws] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32); + [NewObject, Throws] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64); // These attributes are simple aliases for certain elements of the 4x4 matrix readonly attribute unrestricted double a; @@ -79,8 +79,8 @@ interface DOMMatrixReadOnly { DOMMatrix inverse(); DOMPoint transformPoint(optional DOMPointInit point); -// Float32Array toFloat32Array(); -// Float64Array toFloat64Array(); + Float32Array toFloat32Array(); + Float64Array toFloat64Array(); // stringifier; // serializer = { attribute }; diff --git a/tests/wpt/metadata/css/geometry/DOMMatrix-newobject.html.ini b/tests/wpt/metadata/css/geometry/DOMMatrix-newobject.html.ini deleted file mode 100644 index 5a419a11a65..00000000000 --- a/tests/wpt/metadata/css/geometry/DOMMatrix-newobject.html.ini +++ /dev/null @@ -1,13 +0,0 @@ -[DOMMatrix-newobject.html] - [DOMMatrix toFloat32Array] - expected: FAIL - - [DOMMatrix toFloat64Array] - expected: FAIL - - [DOMMatrixReadOnly toFloat32Array] - expected: FAIL - - [DOMMatrixReadOnly toFloat64Array] - expected: FAIL - diff --git a/tests/wpt/metadata/css/geometry/interfaces.html.ini b/tests/wpt/metadata/css/geometry/interfaces.html.ini index 52fae13b7fc..930cf46fde8 100644 --- a/tests/wpt/metadata/css/geometry/interfaces.html.ini +++ b/tests/wpt/metadata/css/geometry/interfaces.html.ini @@ -276,102 +276,24 @@ [DOMRectList interface: calling item(unsigned long) on [object DOMRect\] with too few arguments must throw TypeError] expected: FAIL - [DOMMatrixReadOnly interface: operation fromFloat32Array(Float32Array)] - expected: FAIL - - [DOMMatrixReadOnly interface: operation fromFloat64Array(Float64Array)] - expected: FAIL - - [DOMMatrixReadOnly interface: operation toFloat32Array()] - expected: FAIL - - [DOMMatrixReadOnly interface: operation toFloat64Array()] - expected: FAIL - [DOMMatrixReadOnly interface: stringifier] expected: FAIL - [DOMMatrixReadOnly interface: calling fromFloat32Array(Float32Array) on new DOMMatrixReadOnly() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat64Array(Float64Array) on new DOMMatrixReadOnly() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: new DOMMatrixReadOnly() must inherit property "toFloat32Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: new DOMMatrixReadOnly() must inherit property "toFloat64Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat32Array(Float32Array) on DOMMatrixReadOnly.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat64Array(Float64Array) on DOMMatrixReadOnly.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: DOMMatrixReadOnly.fromMatrix({is2D: false}) must inherit property "toFloat32Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: DOMMatrixReadOnly.fromMatrix({is2D: false}) must inherit property "toFloat64Array()" with the proper type] - expected: FAIL - [DOMMatrix interface: legacy window alias] expected: FAIL - [DOMMatrix interface: operation fromFloat32Array(Float32Array)] - expected: FAIL - - [DOMMatrix interface: operation fromFloat64Array(Float64Array)] - expected: FAIL [DOMMatrix interface: operation setMatrixValue(DOMString)] expected: FAIL - [DOMMatrix interface: calling fromFloat32Array(Float32Array) on new DOMMatrix() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrix interface: calling fromFloat64Array(Float64Array) on new DOMMatrix() with too few arguments must throw TypeError] - expected: FAIL - [DOMMatrix interface: new DOMMatrix() must inherit property "setMatrixValue(DOMString)" with the proper type] expected: FAIL [DOMMatrix interface: calling setMatrixValue(DOMString) on new DOMMatrix() with too few arguments must throw TypeError] expected: FAIL - [DOMMatrixReadOnly interface: calling fromFloat32Array(Float32Array) on new DOMMatrix() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat64Array(Float64Array) on new DOMMatrix() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: new DOMMatrix() must inherit property "toFloat32Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: new DOMMatrix() must inherit property "toFloat64Array()" with the proper type] - expected: FAIL - - [DOMMatrix interface: calling fromFloat32Array(Float32Array) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrix interface: calling fromFloat64Array(Float64Array) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - [DOMMatrix interface: DOMMatrix.fromMatrix({is2D: false}) must inherit property "setMatrixValue(DOMString)" with the proper type] expected: FAIL [DOMMatrix interface: calling setMatrixValue(DOMString) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat32Array(Float32Array) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat64Array(Float64Array) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: DOMMatrix.fromMatrix({is2D: false}) must inherit property "toFloat32Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: DOMMatrix.fromMatrix({is2D: false}) must inherit property "toFloat64Array()" with the proper type] - expected: FAIL - diff --git a/tests/wpt/metadata/css/geometry/interfaces.worker.js.ini b/tests/wpt/metadata/css/geometry/interfaces.worker.js.ini index 402169df09b..b17519968ba 100644 --- a/tests/wpt/metadata/css/geometry/interfaces.worker.js.ini +++ b/tests/wpt/metadata/css/geometry/interfaces.worker.js.ini @@ -43,82 +43,3 @@ [DOMRectReadOnly interface: calling fromRect(DOMRectInit) on new DOMRect() with too few arguments must throw TypeError] expected: FAIL - - [DOMMatrixReadOnly interface: operation fromFloat32Array(Float32Array)] - expected: FAIL - - [DOMMatrixReadOnly interface: operation fromFloat64Array(Float64Array)] - expected: FAIL - - [DOMMatrixReadOnly interface: operation toFloat32Array()] - expected: FAIL - - [DOMMatrixReadOnly interface: operation toFloat64Array()] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat32Array(Float32Array) on new DOMMatrixReadOnly() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat64Array(Float64Array) on new DOMMatrixReadOnly() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: new DOMMatrixReadOnly() must inherit property "toFloat32Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: new DOMMatrixReadOnly() must inherit property "toFloat64Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat32Array(Float32Array) on DOMMatrixReadOnly.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat64Array(Float64Array) on DOMMatrixReadOnly.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: DOMMatrixReadOnly.fromMatrix({is2D: false}) must inherit property "toFloat32Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: DOMMatrixReadOnly.fromMatrix({is2D: false}) must inherit property "toFloat64Array()" with the proper type] - expected: FAIL - - [DOMMatrix interface: operation fromFloat32Array(Float32Array)] - expected: FAIL - - [DOMMatrix interface: operation fromFloat64Array(Float64Array)] - expected: FAIL - - [DOMMatrix interface: calling fromFloat32Array(Float32Array) on new DOMMatrix() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrix interface: calling fromFloat64Array(Float64Array) on new DOMMatrix() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat32Array(Float32Array) on new DOMMatrix() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat64Array(Float64Array) on new DOMMatrix() with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: new DOMMatrix() must inherit property "toFloat32Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: new DOMMatrix() must inherit property "toFloat64Array()" with the proper type] - expected: FAIL - - [DOMMatrix interface: calling fromFloat32Array(Float32Array) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrix interface: calling fromFloat64Array(Float64Array) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat32Array(Float32Array) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: calling fromFloat64Array(Float64Array) on DOMMatrix.fromMatrix({is2D: false}) with too few arguments must throw TypeError] - expected: FAIL - - [DOMMatrixReadOnly interface: DOMMatrix.fromMatrix({is2D: false}) must inherit property "toFloat32Array()" with the proper type] - expected: FAIL - - [DOMMatrixReadOnly interface: DOMMatrix.fromMatrix({is2D: false}) must inherit property "toFloat64Array()" with the proper type] - expected: FAIL -