diff options
author | Job Bautista <jobbautista9@aol.com> | 2023-05-12 15:59:55 +0800 |
---|---|---|
committer | Job Bautista <jobbautista9@aol.com> | 2023-05-12 16:26:06 +0800 |
commit | c7ca649bd14ddb24ad161c130c372f5979bc7e3c (patch) | |
tree | 1d9a278578eaaa45ca162b107c710297f12e81a0 /dom | |
parent | b2889d844f8c2f826100588b23b741f73e96cbbc (diff) | |
download | uxp-c7ca649bd14ddb24ad161c130c372f5979bc7e3c.tar.gz |
Issue #2241 - Part 7.1: Implement .fromFloat{32/64}Array.
Backported from Mozilla bug 1558101.
Diffstat (limited to 'dom')
-rw-r--r-- | dom/base/DOMMatrix.cpp | 67 | ||||
-rw-r--r-- | dom/base/DOMMatrix.h | 12 | ||||
-rw-r--r-- | dom/webidl/DOMMatrix.webidl | 4 |
3 files changed, 73 insertions, 10 deletions
diff --git a/dom/base/DOMMatrix.cpp b/dom/base/DOMMatrix.cpp index 09c186e77e..f0358125f8 100644 --- a/dom/base/DOMMatrix.cpp +++ b/dom/base/DOMMatrix.cpp @@ -163,6 +163,35 @@ DOMMatrixReadOnly::FromMatrix(const GlobalObject& aGlobal, const DOMMatrixInit& return rval.forget(); } + +already_AddRefed<DOMMatrixReadOnly> +DOMMatrixReadOnly::FromFloat32Array(const GlobalObject& aGlobal, const Float32Array& aArray32, ErrorResult& aRv) +{ + aArray32.ComputeLengthAndData(); + + const int length = aArray32.Length(); + const bool is2D = length == 6; + RefPtr<DOMMatrixReadOnly> obj = + new DOMMatrixReadOnly(aGlobal.GetAsSupports(), is2D); + SetDataInMatrix(obj, aArray32.Data(), length, aRv); + + return obj.forget(); +} + +already_AddRefed<DOMMatrixReadOnly> +DOMMatrixReadOnly::FromFloat64Array(const GlobalObject& aGlobal, const Float64Array& aArray64, ErrorResult& aRv) +{ + aArray64.ComputeLengthAndData(); + + const int length = aArray64.Length(); + const bool is2D = length == 6; + RefPtr<DOMMatrixReadOnly> obj = + new DOMMatrixReadOnly(aGlobal.GetAsSupports(), is2D); + SetDataInMatrix(obj, aArray64.Data(), length, aRv); + + return obj.forget(); +} + already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::Constructor( const GlobalObject& aGlobal, @@ -574,6 +603,32 @@ DOMMatrix::FromMatrix(const GlobalObject& aGlobal, const DOMMatrixInit& aMatrixI } already_AddRefed<DOMMatrix> +DOMMatrix::FromFloat32Array(const GlobalObject& aGlobal, const Float32Array& aArray32, ErrorResult& aRv) +{ + aArray32.ComputeLengthAndData(); + + const int length = aArray32.Length(); + const bool is2D = length == 6; + RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(), is2D); + SetDataInMatrix(obj, aArray32.Data(), length, aRv); + + return obj.forget(); +} + +already_AddRefed<DOMMatrix> +DOMMatrix::FromFloat64Array(const GlobalObject& aGlobal, const Float64Array& aArray64, ErrorResult& aRv) +{ + aArray64.ComputeLengthAndData(); + + const int length = aArray64.Length(); + const bool is2D = length == 6; + RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(), is2D); + SetDataInMatrix(obj, aArray64.Data(), length, aRv); + + return obj.forget(); +} + +already_AddRefed<DOMMatrix> DOMMatrix::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv) { RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports()); @@ -639,21 +694,13 @@ SetDataInMatrix(DOMMatrixReadOnly* aMatrix, const T* aData, int aLength, ErrorRe already_AddRefed<DOMMatrix> DOMMatrix::Constructor(const GlobalObject& aGlobal, const Float32Array& aArray32, ErrorResult& aRv) { - RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports()); - aArray32.ComputeLengthAndData(); - SetDataInMatrix(obj, aArray32.Data(), aArray32.Length(), aRv); - - return obj.forget(); + return FromFloat32Array(aGlobal, aArray32, aRv); } already_AddRefed<DOMMatrix> DOMMatrix::Constructor(const GlobalObject& aGlobal, const Float64Array& aArray64, ErrorResult& aRv) { - RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports()); - aArray64.ComputeLengthAndData(); - SetDataInMatrix(obj, aArray64.Data(), aArray64.Length(), aRv); - - return obj.forget(); + return FromFloat64Array(aGlobal, aArray64, aRv); } already_AddRefed<DOMMatrix> diff --git a/dom/base/DOMMatrix.h b/dom/base/DOMMatrix.h index 9bbdef688f..99e7714add 100644 --- a/dom/base/DOMMatrix.h +++ b/dom/base/DOMMatrix.h @@ -61,6 +61,12 @@ public: FromMatrix(const GlobalObject& aGlobal, const DOMMatrixInit& aMatrixInit, ErrorResult& aRv); static already_AddRefed<DOMMatrixReadOnly> + FromFloat32Array(const GlobalObject& aGlobal, const Float32Array& aArray32, ErrorResult& aRv); + + static already_AddRefed<DOMMatrixReadOnly> + FromFloat64Array(const GlobalObject& aGlobal, const Float64Array& aArray64, ErrorResult& aRv); + + static already_AddRefed<DOMMatrixReadOnly> Constructor(const GlobalObject& aGlobal, const Optional<StringOrUnrestrictedDoubleSequence>& aArg, ErrorResult& aRv); static already_AddRefed<DOMMatrixReadOnly> @@ -254,6 +260,12 @@ public: FromMatrix(const GlobalObject& aGlobal, const DOMMatrixInit& aMatrixInit, ErrorResult& aRv); static already_AddRefed<DOMMatrix> + FromFloat32Array(const GlobalObject& aGlobal, const Float32Array& aArray32, ErrorResult& aRv); + + static already_AddRefed<DOMMatrix> + FromFloat64Array(const GlobalObject& aGlobal, const Float64Array& aArray64, ErrorResult& aRv); + + static already_AddRefed<DOMMatrix> Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); static already_AddRefed<DOMMatrix> Constructor(const GlobalObject& aGlobal, const nsAString& aTransformList, ErrorResult& aRv); diff --git a/dom/webidl/DOMMatrix.webidl b/dom/webidl/DOMMatrix.webidl index bf65da35a9..f5c9f99406 100644 --- a/dom/webidl/DOMMatrix.webidl +++ b/dom/webidl/DOMMatrix.webidl @@ -14,6 +14,8 @@ Exposed=(Window,Worker)] interface DOMMatrixReadOnly { [NewObject, Throws] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other); + [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; @@ -91,6 +93,8 @@ interface DOMMatrixReadOnly { Exposed=(Window,Worker)] interface DOMMatrix : DOMMatrixReadOnly { [NewObject, Throws] static DOMMatrix fromMatrix(optional DOMMatrixInit other); + [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; |