Bug 1241727 - Inverting non-invertible WebKitCSSMatrix should throw NotSupportedError. r=baku
authorWilliam Chen <wchen@mozilla.com>
Wed, 27 Jan 2016 12:49:57 -0800
changeset 281944 efbb834ec2fd3da67db1b255f8f671d190e32cfc
parent 281943 bd7fad53ccc7f3492579f14ff68a19a3cf325108
child 281945 abd9ed577c6275cc028cdb574b3efbb9986e385a
push id70985
push userwchen@mozilla.com
push dateWed, 27 Jan 2016 20:50:34 +0000
treeherdermozilla-inbound@efbb834ec2fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1241727
milestone47.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 1241727 - Inverting non-invertible WebKitCSSMatrix should throw NotSupportedError. r=baku
dom/base/WebKitCSSMatrix.cpp
dom/base/WebKitCSSMatrix.h
dom/tests/mochitest/general/test_WebKitCSSMatrix.html
dom/webidl/WebKitCSSMatrix.webidl
--- a/dom/base/WebKitCSSMatrix.cpp
+++ b/dom/base/WebKitCSSMatrix.cpp
@@ -69,24 +69,43 @@ WebKitCSSMatrix::Multiply(const WebKitCS
 {
   RefPtr<WebKitCSSMatrix> retval = new WebKitCSSMatrix(mParent, *this);
   retval->MultiplySelf(other);
 
   return retval.forget();
 }
 
 already_AddRefed<WebKitCSSMatrix>
-WebKitCSSMatrix::Inverse() const
+WebKitCSSMatrix::Inverse(ErrorResult& aRv) const
 {
   RefPtr<WebKitCSSMatrix> retval = new WebKitCSSMatrix(mParent, *this);
-  retval->InvertSelf();
+  retval->InvertSelfThrow(aRv);
+  if (NS_WARN_IF(aRv.Failed())) {
+    return nullptr;
+  }
 
   return retval.forget();
 }
 
+WebKitCSSMatrix*
+WebKitCSSMatrix::InvertSelfThrow(ErrorResult& aRv)
+{
+  if (mMatrix3D) {
+    if (!mMatrix3D->Invert()) {
+      aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
+      return nullptr;
+    }
+  } else if (!mMatrix2D->Invert()) {
+    aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
+    return nullptr;
+  }
+
+  return this;
+}
+
 already_AddRefed<WebKitCSSMatrix>
 WebKitCSSMatrix::Translate(double aTx,
                            double aTy,
                            double aTz) const
 {
   RefPtr<WebKitCSSMatrix> retval = new WebKitCSSMatrix(mParent, *this);
   retval->TranslateSelf(aTx, aTy, aTz);
 
--- a/dom/base/WebKitCSSMatrix.h
+++ b/dom/base/WebKitCSSMatrix.h
@@ -37,17 +37,17 @@ public:
   nsISupports* GetParentObject() const { return mParent; }
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
   WebKitCSSMatrix* SetMatrixValue(const nsAString& aTransformList,
                                   ErrorResult& aRv);
 
   already_AddRefed<WebKitCSSMatrix> Multiply(const WebKitCSSMatrix& aOther) const;
-  already_AddRefed<WebKitCSSMatrix> Inverse() const;
+  already_AddRefed<WebKitCSSMatrix> Inverse(ErrorResult& aRv) const;
   already_AddRefed<WebKitCSSMatrix> Translate(double aTx,
                                               double aTy,
                                               double aTz) const;
   already_AddRefed<WebKitCSSMatrix> Scale(double aScaleX,
                                           const Optional<double>& aScaleY,
                                           double aScaleZ) const;
   already_AddRefed<WebKitCSSMatrix> Rotate(double aRotX,
                                            const Optional<double>& aRotY,
@@ -57,14 +57,16 @@ public:
                                                     double aZ,
                                                     double aAngle) const;
   already_AddRefed<WebKitCSSMatrix> SkewX(double aSx) const;
   already_AddRefed<WebKitCSSMatrix> SkewY(double aSy) const;
 protected:
   WebKitCSSMatrix* Rotate3dSelf(double aRotX,
                                 double aRotY,
                                 double aRotZ);
+
+  WebKitCSSMatrix* InvertSelfThrow(ErrorResult& aRv);
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_webkitcssmatrix_h__ */
--- a/dom/tests/mochitest/general/test_WebKitCSSMatrix.html
+++ b/dom/tests/mochitest/general/test_WebKitCSSMatrix.html
@@ -298,9 +298,14 @@ test(function() {
   var m3 = new WebKitCSSMatrix("matrix(1,2,3,4,5,6)");
 
   var m1r = m1.skewY(2);
   var m2r = m2.skewY(2);
 
   assert_true(RoughCompareMatrix(m1r, m2r), "skewY should return the same result as DOMMatrixReadOnly.");
   assert_true(CompareMatrix(m1, m3), "skewY should not mutate original matrix.");
 }, "Test skewY.");
+
+test(function() {
+  var m = new WebKitCSSMatrix("matrix(1,0,0,0,0,0)");
+  assert_throws("NotSupportedError", function() { m.inverse(); }, "Inverting an invertible matrix should throw.")
+}, "Test that inverting an invertible matrix throws.");
 </script>
--- a/dom/webidl/WebKitCSSMatrix.webidl
+++ b/dom/webidl/WebKitCSSMatrix.webidl
@@ -14,16 +14,17 @@
  Func="mozilla::dom::WebKitCSSMatrix::FeatureEnabled"]
 interface WebKitCSSMatrix : DOMMatrix {
     // Mutable transform methods
     [Throws]
     WebKitCSSMatrix setMatrixValue(DOMString transformList);
 
     // Immutable transform methods
     WebKitCSSMatrix multiply(WebKitCSSMatrix other);
+    [Throws]
     WebKitCSSMatrix inverse();
     WebKitCSSMatrix translate(optional unrestricted double tx = 0,
                               optional unrestricted double ty = 0,
                               optional unrestricted double tz = 0);
     WebKitCSSMatrix scale(optional unrestricted double scaleX = 1,
                           optional unrestricted double scaleY,
                           optional unrestricted double scaleZ = 1);
     WebKitCSSMatrix rotate(optional unrestricted double rotX = 0,