Bug 1360475: Use union for DOMMatrix constructor r=bzbarsky
authorKagami Sascha Rosylight <saschanaz@outlook.com>
Tue, 16 Jul 2019 21:12:38 +0000
changeset 483022 3afbbd8902d360c16a3366b4f53c1efc17044daf
parent 483021 b401901b9e7c5692645698dc327f3d3323a7925f
child 483023 1d2a49b5659f7f6b322c3493cf9684c13681a1b1
push id36303
push userdvarga@mozilla.com
push dateWed, 17 Jul 2019 09:36:40 +0000
treeherdermozilla-central@29e9dde37bd2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1360475
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1360475: Use union for DOMMatrix constructor r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D35211
dom/base/DOMMatrix.cpp
dom/base/DOMMatrix.h
dom/webidl/DOMMatrix.webidl
testing/web-platform/meta/css/geometry/DOMMatrix-001.html.ini
--- a/dom/base/DOMMatrix.cpp
+++ b/dom/base/DOMMatrix.cpp
@@ -214,17 +214,17 @@ already_AddRefed<DOMMatrixReadOnly> DOMM
       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,
+    const Optional<StringOrUnrestrictedDoubleSequenceOrDOMMatrixReadOnly>& aArg,
     ErrorResult& aRv) {
   if (!aArg.WasPassed()) {
     RefPtr<DOMMatrixReadOnly> rval =
         new DOMMatrixReadOnly(aGlobal.GetAsSupports());
     return rval.forget();
   }
 
   const auto& arg = aArg.Value();
@@ -235,16 +235,21 @@ already_AddRefed<DOMMatrixReadOnly> DOMM
       aRv.ThrowTypeError<MSG_ILLEGAL_CONSTRUCTOR>();
       return nullptr;
     }
     RefPtr<DOMMatrixReadOnly> rval =
         new DOMMatrixReadOnly(aGlobal.GetAsSupports());
     rval->SetMatrixValue(arg.GetAsString(), aRv);
     return rval.forget();
   }
+  if (arg.IsDOMMatrixReadOnly()) {
+    RefPtr<DOMMatrixReadOnly> obj = new DOMMatrixReadOnly(
+        aGlobal.GetAsSupports(), arg.GetAsDOMMatrixReadOnly());
+    return obj.forget();
+  }
 
   const auto& sequence = arg.GetAsUnrestrictedDoubleSequence();
   const int length = sequence.Length();
   const bool is2D = length == 6;
   RefPtr<DOMMatrixReadOnly> rval =
       new DOMMatrixReadOnly(aGlobal.GetAsSupports(), is2D);
   SetDataInMatrix(rval, sequence.Elements(), length, aRv);
   return rval.forget();
@@ -653,40 +658,49 @@ already_AddRefed<DOMMatrix> DOMMatrix::F
   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());
-  return obj.forget();
-}
-
 already_AddRefed<DOMMatrix> DOMMatrix::Constructor(
-    const GlobalObject& aGlobal, const nsAString& aTransformList,
+    const GlobalObject& aGlobal,
+    const Optional<StringOrUnrestrictedDoubleSequenceOrDOMMatrixReadOnly>& aArg,
     ErrorResult& aRv) {
-  nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
-  if (!win) {
-    aRv.ThrowTypeError<MSG_ILLEGAL_CONSTRUCTOR>();
-    return nullptr;
+  if (!aArg.WasPassed()) {
+    RefPtr<DOMMatrix> rval = new DOMMatrix(aGlobal.GetAsSupports());
+    return rval.forget();
   }
-  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports());
-  obj = obj->SetMatrixValue(aTransformList, aRv);
-  return obj.forget();
-}
 
-already_AddRefed<DOMMatrix> DOMMatrix::Constructor(
-    const GlobalObject& aGlobal, const DOMMatrixReadOnly& aOther,
-    ErrorResult& aRv) {
-  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(), aOther);
-  return obj.forget();
+  const auto& arg = aArg.Value();
+  if (arg.IsString()) {
+    nsCOMPtr<nsPIDOMWindowInner> win =
+        do_QueryInterface(aGlobal.GetAsSupports());
+    if (!win) {
+      aRv.ThrowTypeError<MSG_ILLEGAL_CONSTRUCTOR>();
+      return nullptr;
+    }
+    RefPtr<DOMMatrix> rval = new DOMMatrix(aGlobal.GetAsSupports());
+    rval->SetMatrixValue(arg.GetAsString(), aRv);
+    return rval.forget();
+  }
+  if (arg.IsDOMMatrixReadOnly()) {
+    RefPtr<DOMMatrix> obj =
+        new DOMMatrix(aGlobal.GetAsSupports(), arg.GetAsDOMMatrixReadOnly());
+    return obj.forget();
+  }
+
+  const auto& sequence = arg.GetAsUnrestrictedDoubleSequence();
+  const int length = sequence.Length();
+  const bool is2D = length == 6;
+  RefPtr<DOMMatrix> rval = new DOMMatrix(aGlobal.GetAsSupports(), is2D);
+  SetDataInMatrix(rval, sequence.Elements(), length, aRv);
+  return rval.forget();
 }
 
 template <typename T>
 static void SetDataInMatrix(DOMMatrixReadOnly* aMatrix, const T* aData,
                             int aLength, ErrorResult& aRv) {
   if (aLength == 16) {
     aMatrix->SetM11(aData[0]);
     aMatrix->SetM12(aData[1]);
@@ -713,39 +727,16 @@ static void SetDataInMatrix(DOMMatrixRea
     aMatrix->SetF(aData[5]);
   } else {
     nsAutoString lengthStr;
     lengthStr.AppendInt(aLength);
     aRv.ThrowTypeError<MSG_MATRIX_INIT_LENGTH_WRONG>(lengthStr);
   }
 }
 
-already_AddRefed<DOMMatrix> DOMMatrix::Constructor(const GlobalObject& aGlobal,
-                                                   const Float32Array& aArray32,
-                                                   ErrorResult& aRv) {
-  return FromFloat32Array(aGlobal, aArray32, aRv);
-}
-
-already_AddRefed<DOMMatrix> DOMMatrix::Constructor(const GlobalObject& aGlobal,
-                                                   const Float64Array& aArray64,
-                                                   ErrorResult& aRv) {
-  return FromFloat64Array(aGlobal, aArray64, aRv);
-}
-
-already_AddRefed<DOMMatrix> DOMMatrix::Constructor(
-    const GlobalObject& aGlobal, const Sequence<double>& aNumberSequence,
-    ErrorResult& aRv) {
-  const int length = aNumberSequence.Length();
-  const bool is2D = length == 6;
-  RefPtr<DOMMatrix> obj = new DOMMatrix(aGlobal.GetAsSupports(), is2D);
-  SetDataInMatrix(obj, aNumberSequence.Elements(), length, aRv);
-
-  return obj.forget();
-}
-
 already_AddRefed<DOMMatrix> DOMMatrix::ReadStructuredClone(
     JSContext* aCx, nsIGlobalObject* aGlobal,
     JSStructuredCloneReader* aReader) {
   uint8_t is2D;
 
   if (!JS_ReadBytes(aReader, &is2D, 1)) {
     return nullptr;
   }
--- a/dom/base/DOMMatrix.h
+++ b/dom/base/DOMMatrix.h
@@ -21,17 +21,17 @@
 class nsIGlobalObject;
 
 namespace mozilla {
 namespace dom {
 
 class GlobalObject;
 class DOMMatrix;
 class DOMPoint;
-class StringOrUnrestrictedDoubleSequence;
+class StringOrUnrestrictedDoubleSequenceOrDOMMatrixReadOnly;
 struct DOMPointInit;
 struct DOMMatrixInit;
 struct DOMMatrix2DInit;
 
 class DOMMatrixReadOnly : public nsWrapperCache {
  public:
   explicit DOMMatrixReadOnly(nsISupports* aParent)
       : mParent(aParent), mMatrix2D(new gfx::MatrixDouble()) {}
@@ -78,17 +78,18 @@ class DOMMatrixReadOnly : public nsWrapp
       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,
+      const Optional<StringOrUnrestrictedDoubleSequenceOrDOMMatrixReadOnly>&
+          aArg,
       ErrorResult& aRv);
 
   static already_AddRefed<DOMMatrixReadOnly> ReadStructuredClone(
       JSContext* aCx, nsIGlobalObject* aGlobal,
       JSStructuredCloneReader* aReader);
 
   // clang-format off
 #define GetMatrixMember(entry2D, entry3D, default) \
@@ -283,32 +284,20 @@ class DOMMatrix : public DOMMatrixReadOn
   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);
-  static already_AddRefed<DOMMatrix> Constructor(
-      const GlobalObject& aGlobal, const DOMMatrixReadOnly& aOther,
-      ErrorResult& aRv);
-  static already_AddRefed<DOMMatrix> Constructor(const GlobalObject& aGlobal,
-                                                 const Float32Array& aArray32,
-                                                 ErrorResult& aRv);
-  static already_AddRefed<DOMMatrix> Constructor(const GlobalObject& aGlobal,
-                                                 const Float64Array& aArray64,
-                                                 ErrorResult& aRv);
-  static already_AddRefed<DOMMatrix> Constructor(
-      const GlobalObject& aGlobal, const Sequence<double>& aNumberSequence,
+      const GlobalObject& aGlobal,
+      const Optional<StringOrUnrestrictedDoubleSequenceOrDOMMatrixReadOnly>&
+          aArg,
       ErrorResult& aRv);
 
   static already_AddRefed<DOMMatrix> ReadStructuredClone(
       JSContext* aCx, nsIGlobalObject* aGlobal,
       JSStructuredCloneReader* aReader);
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
--- a/dom/webidl/DOMMatrix.webidl
+++ b/dom/webidl/DOMMatrix.webidl
@@ -6,17 +6,17 @@
  * The origin of this IDL file is
  * https://drafts.fxtf.org/geometry/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 [Pref="layout.css.DOMMatrix.enabled",
- Constructor(optional (DOMString or sequence<unrestricted double>) init),
+ Constructor(optional (DOMString or sequence<unrestricted double> or DOMMatrixReadOnly) init),
  Exposed=(Window,Worker),
  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);
 
 
@@ -83,22 +83,17 @@ interface DOMMatrixReadOnly {
     DOMPoint                   transformPoint(optional DOMPointInit point = {});
     [Throws] Float32Array      toFloat32Array();
     [Throws] Float64Array      toFloat64Array();
     [Exposed=Window, Throws]   stringifier;
     [Default] object           toJSON();
 };
 
 [Pref="layout.css.DOMMatrix.enabled",
- Constructor,
- Constructor(DOMString transformList),
- Constructor(DOMMatrixReadOnly other),
- Constructor(Float32Array array32),
- Constructor(Float64Array array64),
- Constructor(sequence<unrestricted double> numberSequence),
+ Constructor(optional (DOMString or sequence<unrestricted double> or DOMMatrixReadOnly) init),
  Exposed=(Window,Worker),
  Serializable,
  LegacyWindowAlias=WebKitCSSMatrix]
 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);
 
deleted file mode 100644
--- a/testing/web-platform/meta/css/geometry/DOMMatrix-001.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[DOMMatrix-001.html]
-  [new DOMMatrix(undefined)]
-    expected: FAIL