Bug 1558101: Implement geometry static constructors r=bzbarsky

Includes .fromRect, .fromQuad, and .fromFloat32/64Array.

Differential Revision: https://phabricator.services.mozilla.com/D36464

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-07-03 05:51:30 +00:00
Родитель a100b37a5d
Коммит 11712bd3ce
15 изменённых файлов: 142 добавлений и 175 удалений

Просмотреть файл

@ -160,6 +160,34 @@ already_AddRefed<DOMMatrixReadOnly> DOMMatrixReadOnly::FromMatrix(
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,
const Optional<StringOrUnrestrictedDoubleSequence>& aArg,
@ -593,6 +621,32 @@ already_AddRefed<DOMMatrix> DOMMatrix::FromMatrix(
return matrix.forget();
}
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());
@ -656,27 +710,13 @@ static void SetDataInMatrix(DOMMatrixReadOnly* aMatrix, const T* aData,
already_AddRefed<DOMMatrix> DOMMatrix::Constructor(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();
return FromFloat32Array(aGlobal, aArray32, aRv);
}
already_AddRefed<DOMMatrix> DOMMatrix::Constructor(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();
return FromFloat64Array(aGlobal, aArray64, aRv);
}
already_AddRefed<DOMMatrix> DOMMatrix::Constructor(

Просмотреть файл

@ -60,6 +60,14 @@ class DOMMatrixReadOnly : public nsWrapperCache {
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,
@ -249,6 +257,14 @@ class DOMMatrix : public DOMMatrixReadOnly {
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(

Просмотреть файл

@ -36,6 +36,30 @@ JSObject* DOMQuad::WrapObject(JSContext* aCx,
return DOMQuad_Binding::Wrap(aCx, this, aGivenProto);
}
already_AddRefed<DOMQuad> DOMQuad::FromRect(const GlobalObject& aGlobal,
const DOMRectInit& aInit) {
nsISupports* parent = aGlobal.GetAsSupports();
RefPtr<DOMQuad> obj = new DOMQuad(parent);
obj->mPoints[0] = new DOMPoint(parent, aInit.mX, aInit.mY, 0, 1);
obj->mPoints[1] =
new DOMPoint(parent, aInit.mX + aInit.mWidth, aInit.mY, 0, 1);
obj->mPoints[2] = new DOMPoint(parent, aInit.mX + aInit.mWidth,
aInit.mY + aInit.mHeight, 0, 1);
obj->mPoints[3] =
new DOMPoint(parent, aInit.mX, aInit.mY + aInit.mHeight, 0, 1);
return obj.forget();
}
already_AddRefed<DOMQuad> DOMQuad::FromQuad(const GlobalObject& aGlobal,
const DOMQuadInit& aInit) {
RefPtr<DOMQuad> obj = new DOMQuad(aGlobal.GetAsSupports());
obj->mPoints[0] = DOMPoint::FromPoint(aGlobal, aInit.mP1);
obj->mPoints[1] = DOMPoint::FromPoint(aGlobal, aInit.mP2);
obj->mPoints[2] = DOMPoint::FromPoint(aGlobal, aInit.mP3);
obj->mPoints[3] = DOMPoint::FromPoint(aGlobal, aInit.mP4);
return obj.forget();
}
already_AddRefed<DOMQuad> DOMQuad::Constructor(const GlobalObject& aGlobal,
const DOMPointInit& aP1,
const DOMPointInit& aP2,

Просмотреть файл

@ -25,6 +25,7 @@ namespace dom {
class DOMRectReadOnly;
class DOMPoint;
struct DOMPointInit;
struct DOMQuadInit;
class DOMQuad final : public nsWrapperCache {
~DOMQuad();
@ -40,6 +41,12 @@ class DOMQuad final : public nsWrapperCache {
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
static already_AddRefed<DOMQuad> FromRect(const GlobalObject& aGlobal,
const DOMRectInit& aInit);
static already_AddRefed<DOMQuad> FromQuad(const GlobalObject& aGlobal,
const DOMQuadInit& aInit);
static already_AddRefed<DOMQuad> Constructor(const GlobalObject& aGlobal,
const DOMPointInit& aP1,
const DOMPointInit& aP2,

Просмотреть файл

@ -27,6 +27,13 @@ JSObject* DOMRectReadOnly::WrapObject(JSContext* aCx,
return DOMRectReadOnly_Binding::Wrap(aCx, this, aGivenProto);
}
already_AddRefed<DOMRectReadOnly> DOMRectReadOnly::FromRect(
const GlobalObject& aGlobal, const DOMRectInit& aInit) {
RefPtr<DOMRectReadOnly> obj = new DOMRectReadOnly(
aGlobal.GetAsSupports(), aInit.mX, aInit.mY, aInit.mWidth, aInit.mHeight);
return obj.forget();
}
already_AddRefed<DOMRectReadOnly> DOMRectReadOnly::Constructor(
const GlobalObject& aGlobal, double aX, double aY, double aWidth,
double aHeight, ErrorResult& aRv) {
@ -87,6 +94,13 @@ JSObject* DOMRect::WrapObject(JSContext* aCx,
return DOMRect_Binding::Wrap(aCx, this, aGivenProto);
}
already_AddRefed<DOMRect> DOMRect::FromRect(const GlobalObject& aGlobal,
const DOMRectInit& aInit) {
RefPtr<DOMRect> obj = new DOMRect(aGlobal.GetAsSupports(), aInit.mX, aInit.mY,
aInit.mWidth, aInit.mHeight);
return obj.forget();
}
already_AddRefed<DOMRect> DOMRect::Constructor(const GlobalObject& aGlobal,
double aX, double aY,
double aWidth, double aHeight,

Просмотреть файл

@ -23,6 +23,8 @@ class nsIGlobalObject;
namespace mozilla {
namespace dom {
struct DOMRectInit;
class DOMRectReadOnly : public nsISupports, public nsWrapperCache {
protected:
virtual ~DOMRectReadOnly() {}
@ -43,6 +45,9 @@ class DOMRectReadOnly : public nsISupports, public nsWrapperCache {
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
static already_AddRefed<DOMRectReadOnly> FromRect(const GlobalObject& aGlobal,
const DOMRectInit& aInit);
static already_AddRefed<DOMRectReadOnly> Constructor(
const GlobalObject& aGlobal, double aX, double aY, double aWidth,
double aHeight, ErrorResult& aRv);
@ -93,6 +98,9 @@ class DOMRect final : public DOMRectReadOnly {
NS_INLINE_DECL_REFCOUNTING_INHERITED(DOMRect, DOMRectReadOnly)
static already_AddRefed<DOMRect> FromRect(const GlobalObject& aGlobal,
const DOMRectInit& aInit);
static already_AddRefed<DOMRect> Constructor(const GlobalObject& aGlobal,
double aX, double aY,
double aWidth, double aHeight,

Просмотреть файл

@ -16,6 +16,9 @@
Serializable]
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;
@ -95,6 +98,9 @@ interface DOMMatrixReadOnly {
Serializable]
interface DOMMatrix : DOMMatrixReadOnly {
[NewObject, Throws] static DOMMatrix 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
inherit attribute unrestricted double a;

Просмотреть файл

@ -17,6 +17,9 @@
Exposed=(Window,Worker),
Serializable]
interface DOMQuad {
[NewObject] static DOMQuad fromRect(optional DOMRectInit other);
[NewObject] static DOMQuad fromQuad(optional DOMQuadInit other);
[SameObject] readonly attribute DOMPoint p1;
[SameObject] readonly attribute DOMPoint p2;
[SameObject] readonly attribute DOMPoint p3;
@ -27,8 +30,8 @@ interface DOMQuad {
};
dictionary DOMQuadInit {
DOMPointInit p1;
DOMPointInit p2;
DOMPointInit p3;
DOMPointInit p4;
DOMPointInit p1 = null;
DOMPointInit p2 = null;
DOMPointInit p3 = null;
DOMPointInit p4 = null;
};

Просмотреть файл

@ -15,6 +15,8 @@
Exposed=(Window,Worker),
Serializable]
interface DOMRect : DOMRectReadOnly {
[NewObject] static DOMRect fromRect(optional DOMRectInit other);
inherit attribute unrestricted double x;
inherit attribute unrestricted double y;
inherit attribute unrestricted double width;
@ -27,6 +29,8 @@ interface DOMRect : DOMRectReadOnly {
Exposed=(Window,Worker),
Serializable]
interface DOMRectReadOnly {
[NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other);
readonly attribute unrestricted double x;
readonly attribute unrestricted double y;
readonly attribute unrestricted double width;

Просмотреть файл

@ -1,34 +1,3 @@
[DOMQuad-001.html]
[testConstructor5: bounds]
expected: FAIL
[testConstructor6: bounds]
expected: FAIL
[testConstructor7: bounds]
expected: FAIL
[p1Top4Attributes1: bounds]
expected: FAIL
[boundsAttribute0: bounds]
expected: FAIL
[fromRect() method on DOMQuad: points]
expected: FAIL
[fromRect() method on DOMQuad: bounds]
expected: FAIL
[fromRect() method on DOMQuad with negatives: points]
expected: FAIL
[fromRect() method on DOMQuad with negatives: bounds]
expected: FAIL
[fromRect() method on DOMQuad with Infinity: points]
expected: FAIL
[fromRect() method on DOMQuad with Infinity: bounds]
expected: FAIL

Просмотреть файл

@ -1,13 +0,0 @@
[DOMQuad-002.html]
[test fromRect]
expected: FAIL
[test fromRect with Infinity]
expected: FAIL
[test fromQuad]
expected: FAIL
[test getBounds]
expected: FAIL

Просмотреть файл

@ -1,7 +0,0 @@
[DOMRect-002.html]
[DOMRect.fromRect]
expected: FAIL
[DOMRectReadOnly.fromRect]
expected: FAIL

Просмотреть файл

@ -17,59 +17,9 @@
[DOMPointReadOnly interface: calling matrixTransform(DOMMatrixInit) on new DOMPoint() with too few arguments must throw TypeError]
expected: FAIL
[DOMRectReadOnly interface: operation fromRect(DOMRectInit)]
expected: FAIL
[DOMRectReadOnly interface: calling fromRect(DOMRectInit) on new DOMRectReadOnly() with too few arguments must throw TypeError]
expected: FAIL
[DOMRect interface: legacy window alias]
expected: FAIL
[DOMRect interface: operation fromRect(DOMRectInit)]
expected: FAIL
[DOMRect interface: calling fromRect(DOMRectInit) on new DOMRect() with too few arguments must throw TypeError]
expected: FAIL
[DOMRectReadOnly interface: calling fromRect(DOMRectInit) on new DOMRect() with too few arguments must throw TypeError]
expected: FAIL
[DOMQuad interface: operation fromRect(DOMRectInit)]
expected: FAIL
[DOMQuad interface: operation fromQuad(DOMQuadInit)]
expected: FAIL
[DOMQuad interface: calling fromRect(DOMRectInit) on new DOMQuad() with too few arguments must throw TypeError]
expected: FAIL
[DOMQuad interface: calling fromQuad(DOMQuadInit) on new DOMQuad() 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: 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
[DOMMatrix interface: legacy window alias]
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

Просмотреть файл

@ -13,54 +13,3 @@
[DOMPointReadOnly interface: calling matrixTransform(DOMMatrixInit) on new DOMPoint() with too few arguments must throw TypeError]
expected: FAIL
[DOMRectReadOnly interface: operation fromRect(DOMRectInit)]
expected: FAIL
[DOMRectReadOnly interface: calling fromRect(DOMRectInit) on new DOMRectReadOnly() with too few arguments must throw TypeError]
expected: FAIL
[DOMRect interface: operation fromRect(DOMRectInit)]
expected: FAIL
[DOMRect interface: calling fromRect(DOMRectInit) on new DOMRect() with too few arguments must throw TypeError]
expected: FAIL
[DOMRectReadOnly interface: calling fromRect(DOMRectInit) on new DOMRect() with too few arguments must throw TypeError]
expected: FAIL
[DOMQuad interface: operation fromRect(DOMRectInit)]
expected: FAIL
[DOMQuad interface: operation fromQuad(DOMQuadInit)]
expected: FAIL
[DOMQuad interface: calling fromRect(DOMRectInit) on new DOMQuad() with too few arguments must throw TypeError]
expected: FAIL
[DOMQuad interface: calling fromQuad(DOMQuadInit) on new DOMQuad() 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: 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
[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

Просмотреть файл

@ -2,9 +2,6 @@
[matrixTransform]
expected: FAIL
[DOMQuad]
expected: FAIL
[DOMMatrix NaN]
expected: FAIL