Bug 1350254 part 4. Switch DOMPoint and DOMPointReadOnly to [Serializable]. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 25 Jun 2019 06:46:20 +0000
changeset 543282 215283c818b4f604c5ca8798a29067c4e8585df5
parent 543281 f8b0c0b1aa91a9d6eca5cf45691664da92d23035
child 543283 c5f545a54a5335dfab487e896598d066d13f1f3d
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1350254
milestone69.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 1350254 part 4. Switch DOMPoint and DOMPointReadOnly to [Serializable]. r=baku Differential Revision: https://phabricator.services.mozilla.com/D35718
dom/base/DOMPoint.cpp
dom/base/DOMPoint.h
dom/base/DOMQuad.cpp
dom/base/StructuredCloneHolder.cpp
dom/base/StructuredCloneTags.h
dom/webidl/DOMPoint.webidl
--- a/dom/base/DOMPoint.cpp
+++ b/dom/base/DOMPoint.cpp
@@ -34,44 +34,55 @@ already_AddRefed<DOMPointReadOnly> DOMPo
 
 JSObject* DOMPointReadOnly::WrapObject(JSContext* aCx,
                                        JS::Handle<JSObject*> aGivenProto) {
   return DOMPointReadOnly_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 // https://drafts.fxtf.org/geometry/#structured-serialization
 bool DOMPointReadOnly::WriteStructuredClone(
-    JSStructuredCloneWriter* aWriter) const {
+    JSContext* aCx, JSStructuredCloneWriter* aWriter) const {
 #define WriteDouble(d)                                                       \
   JS_WriteUint32Pair(aWriter, (BitwiseCast<uint64_t>(d) >> 32) & 0xffffffff, \
                      BitwiseCast<uint64_t>(d) & 0xffffffff)
 
   return WriteDouble(mX) && WriteDouble(mY) && WriteDouble(mZ) &&
          WriteDouble(mW);
 
 #undef WriteDouble
 }
 
+// static
+already_AddRefed<DOMPointReadOnly> DOMPointReadOnly::ReadStructuredClone(
+    JSContext* aCx, nsIGlobalObject* aGlobal,
+    JSStructuredCloneReader* aReader) {
+  RefPtr<DOMPointReadOnly> retval = new DOMPointReadOnly(aGlobal);
+  if (!retval->ReadStructuredClone(aReader)) {
+    return nullptr;
+  }
+  return retval.forget();
+  ;
+}
+
 bool DOMPointReadOnly::ReadStructuredClone(JSStructuredCloneReader* aReader) {
   uint32_t high;
   uint32_t low;
 
 #define ReadDouble(d)                             \
   if (!JS_ReadUint32Pair(aReader, &high, &low)) { \
     return false;                                 \
   }                                               \
   (*(d) = BitwiseCast<double>(static_cast<uint64_t>(high) << 32 | low))
 
   ReadDouble(&mX);
   ReadDouble(&mY);
   ReadDouble(&mZ);
   ReadDouble(&mW);
 
   return true;
-
 #undef ReadDouble
 }
 
 already_AddRefed<DOMPoint> DOMPoint::FromPoint(const GlobalObject& aGlobal,
                                                const DOMPointInit& aParams) {
   RefPtr<DOMPoint> obj = new DOMPoint(aGlobal.GetAsSupports(), aParams.mX,
                                       aParams.mY, aParams.mZ, aParams.mW);
   return obj.forget();
@@ -84,8 +95,20 @@ already_AddRefed<DOMPoint> DOMPoint::Con
   RefPtr<DOMPoint> obj = new DOMPoint(aGlobal.GetAsSupports(), aX, aY, aZ, aW);
   return obj.forget();
 }
 
 JSObject* DOMPoint::WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) {
   return DOMPoint_Binding::Wrap(aCx, this, aGivenProto);
 }
+
+// static
+already_AddRefed<DOMPoint> DOMPoint::ReadStructuredClone(
+    JSContext* aCx, nsIGlobalObject* aGlobal,
+    JSStructuredCloneReader* aReader) {
+  RefPtr<DOMPoint> retval = new DOMPoint(aGlobal);
+  if (!retval->ReadStructuredClone(aReader)) {
+    return nullptr;
+  }
+  return retval.forget();
+  ;
+}
--- a/dom/base/DOMPoint.h
+++ b/dom/base/DOMPoint.h
@@ -11,16 +11,18 @@
 #include "nsWrapperCache.h"
 #include "nsISupports.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/ErrorResult.h"
 #include "nsCOMPtr.h"
 #include "mozilla/dom/BindingDeclarations.h"
 
+class nsIGlobalObject;
+
 namespace mozilla {
 namespace dom {
 
 class GlobalObject;
 struct DOMPointInit;
 
 class DOMPointReadOnly : public nsWrapperCache {
  public:
@@ -41,23 +43,30 @@ class DOMPointReadOnly : public nsWrappe
   double Y() const { return mY; }
   double Z() const { return mZ; }
   double W() const { return mW; }
 
   nsISupports* GetParentObject() const { return mParent; }
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
-  bool WriteStructuredClone(JSStructuredCloneWriter* aWriter) const;
+  bool WriteStructuredClone(JSContext* aCx,
+                            JSStructuredCloneWriter* aWriter) const;
 
-  bool ReadStructuredClone(JSStructuredCloneReader* aReader);
+  static already_AddRefed<DOMPointReadOnly> ReadStructuredClone(
+      JSContext* aCx, nsIGlobalObject* aGlobal,
+      JSStructuredCloneReader* aReader);
 
  protected:
   virtual ~DOMPointReadOnly() {}
 
+  // Shared implementation of ReadStructuredClone for DOMPoint and
+  // DOMPointReadOnly.
+  bool ReadStructuredClone(JSStructuredCloneReader* aReader);
+
   nsCOMPtr<nsISupports> mParent;
   double mX, mY, mZ, mW;
 };
 
 class DOMPoint final : public DOMPointReadOnly {
  public:
   explicit DOMPoint(nsISupports* aParent, double aX = 0.0, double aY = 0.0,
                     double aZ = 0.0, double aW = 1.0)
@@ -67,16 +76,21 @@ class DOMPoint final : public DOMPointRe
                                               const DOMPointInit& aParams);
   static already_AddRefed<DOMPoint> Constructor(const GlobalObject& aGlobal,
                                                 double aX, double aY, double aZ,
                                                 double aW, ErrorResult& aRV);
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
+  static already_AddRefed<DOMPoint> ReadStructuredClone(
+      JSContext* aCx, nsIGlobalObject* aGlobal,
+      JSStructuredCloneReader* aReader);
+  using DOMPointReadOnly::ReadStructuredClone;
+
   void SetX(double aX) { mX = aX; }
   void SetY(double aY) { mY = aY; }
   void SetZ(double aZ) { mZ = aZ; }
   void SetW(double aW) { mW = aW; }
 };
 
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/base/DOMQuad.cpp
+++ b/dom/base/DOMQuad.cpp
@@ -112,28 +112,28 @@ void DOMQuad::ToJSON(DOMQuadJSON& aInit)
   aInit.mP3.Construct(RefPtr<DOMPoint>(P3()).forget());
   aInit.mP4.Construct(RefPtr<DOMPoint>(P4()).forget());
 }
 
 // https://drafts.fxtf.org/geometry/#structured-serialization
 bool DOMQuad::WriteStructuredClone(JSContext* aCx,
                                    JSStructuredCloneWriter* aWriter) const {
   for (const auto& point : mPoints) {
-    if (!point->WriteStructuredClone(aWriter)) {
+    if (!point->WriteStructuredClone(aCx, aWriter)) {
       return false;
     }
   }
   return true;
 }
 
 // static
 already_AddRefed<DOMQuad> DOMQuad::ReadStructuredClone(
     JSContext* aCx, nsIGlobalObject* aGlobal,
     JSStructuredCloneReader* aReader) {
   RefPtr<DOMQuad> quad = new DOMQuad(aGlobal);
   for (auto& point : quad->mPoints) {
-    point = new DOMPoint(aGlobal);
-    if (!point->ReadStructuredClone(aReader)) {
+    point = DOMPoint::ReadStructuredClone(aCx, aGlobal, aReader);
+    if (!point) {
       return nullptr;
     }
   }
   return quad.forget();
 }
--- a/dom/base/StructuredCloneHolder.cpp
+++ b/dom/base/StructuredCloneHolder.cpp
@@ -11,18 +11,16 @@
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/BlobBinding.h"
 #include "mozilla/dom/CryptoKey.h"
 #include "mozilla/dom/StructuredCloneBlob.h"
 #include "mozilla/dom/Directory.h"
 #include "mozilla/dom/DirectoryBinding.h"
 #include "mozilla/dom/DOMMatrix.h"
 #include "mozilla/dom/DOMMatrixBinding.h"
-#include "mozilla/dom/DOMPoint.h"
-#include "mozilla/dom/DOMPointBinding.h"
 #include "mozilla/dom/DOMRect.h"
 #include "mozilla/dom/DOMRectBinding.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/FileList.h"
 #include "mozilla/dom/FileListBinding.h"
 #include "mozilla/dom/FormData.h"
 #include "mozilla/dom/ImageBitmap.h"
 #include "mozilla/dom/ImageBitmapBinding.h"
@@ -123,17 +121,17 @@ bool StructuredCloneCallbacksCanTransfer
 
 void StructuredCloneCallbacksError(JSContext* aCx, uint32_t aErrorId) {
   NS_WARNING("Failed to clone data.");
 }
 
 void AssertTagValues() {
   static_assert(SCTAG_DOM_IMAGEDATA == 0xffff8007 &&
                     SCTAG_DOM_DOMPOINT == 0xffff8008 &&
-                    SCTAG_DOM_DOMPOINT_READONLY == 0xffff8009 &&
+                    SCTAG_DOM_DOMPOINTREADONLY == 0xffff8009 &&
                     SCTAG_DOM_WEBCRYPTO_KEY == 0xffff800a &&
                     SCTAG_DOM_NULL_PRINCIPAL == 0xffff800b &&
                     SCTAG_DOM_SYSTEM_PRINCIPAL == 0xffff800c &&
                     SCTAG_DOM_CONTENT_PRINCIPAL == 0xffff800d &&
                     SCTAG_DOM_DOMQUAD == 0xffff800e &&
                     SCTAG_DOM_RTC_CERTIFICATE == 0xffff800f &&
                     SCTAG_DOM_DOMRECT == 0xffff8010 &&
                     SCTAG_DOM_DOMRECT_READONLY == 0xffff8011 &&
@@ -353,17 +351,16 @@ JSObject* StructuredCloneHolder::ReadFul
 
   WebIDLDeserializer deserializer =
       LookupDeserializer(StructuredCloneTags(aTag));
   if (deserializer) {
     return deserializer(aCx, global, aReader);
   }
 
   if (aTag == SCTAG_DOM_WEBCRYPTO_KEY || aTag == SCTAG_DOM_URLSEARCHPARAMS ||
-      aTag == SCTAG_DOM_DOMPOINT || aTag == SCTAG_DOM_DOMPOINT_READONLY ||
       aTag == SCTAG_DOM_DOMRECT || aTag == SCTAG_DOM_DOMRECT_READONLY ||
       aTag == SCTAG_DOM_DOMMATRIX || aTag == SCTAG_DOM_DOMMATRIX_READONLY) {
     // Prevent the return value from being trashed by a GC during ~nsRefPtr.
     JS::Rooted<JSObject*> result(aCx);
     {
       if (aTag == SCTAG_DOM_WEBCRYPTO_KEY) {
         RefPtr<CryptoKey> key = new CryptoKey(global);
         if (!key->ReadStructuredClone(aReader)) {
@@ -373,30 +370,16 @@ JSObject* StructuredCloneHolder::ReadFul
         }
       } else if (aTag == SCTAG_DOM_URLSEARCHPARAMS) {
         RefPtr<URLSearchParams> usp = new URLSearchParams(global);
         if (!usp->ReadStructuredClone(aReader)) {
           result = nullptr;
         } else {
           result = usp->WrapObject(aCx, nullptr);
         }
-      } else if (aTag == SCTAG_DOM_DOMPOINT) {
-        RefPtr<DOMPoint> domPoint = new DOMPoint(global);
-        if (!domPoint->ReadStructuredClone(aReader)) {
-          result = nullptr;
-        } else {
-          result = domPoint->WrapObject(aCx, nullptr);
-        }
-      } else if (aTag == SCTAG_DOM_DOMPOINT_READONLY) {
-        RefPtr<DOMPointReadOnly> domPoint = new DOMPointReadOnly(global);
-        if (!domPoint->ReadStructuredClone(aReader)) {
-          result = nullptr;
-        } else {
-          result = domPoint->WrapObject(aCx, nullptr);
-        }
       } else if (aTag == SCTAG_DOM_DOMRECT) {
         RefPtr<DOMRect> domRect = new DOMRect(global);
         if (!domRect->ReadStructuredClone(aReader)) {
           result = nullptr;
         } else {
           result = domRect->WrapObject(aCx, nullptr);
         }
       } else if (aTag == SCTAG_DOM_DOMRECT_READONLY) {
@@ -528,36 +511,16 @@ bool StructuredCloneHolder::WriteFullySe
     if (NS_SUCCEEDED(UNWRAP_OBJECT(RTCCertificate, &obj, cert))) {
       MOZ_ASSERT(NS_IsMainThread());
       return JS_WriteUint32Pair(aWriter, SCTAG_DOM_RTC_CERTIFICATE, 0) &&
              cert->WriteStructuredClone(aWriter);
     }
   }
 #endif
 
-  // Handle DOMPoint cloning
-  // Should be done before DOMPointeReadOnly check
-  // because every DOMPoint is also a DOMPointReadOnly
-  {
-    DOMPoint* domPoint = nullptr;
-    if (NS_SUCCEEDED(UNWRAP_OBJECT(DOMPoint, &obj, domPoint))) {
-      return JS_WriteUint32Pair(aWriter, SCTAG_DOM_DOMPOINT, 0) &&
-             domPoint->WriteStructuredClone(aWriter);
-    }
-  }
-
-  // Handle DOMPointReadOnly cloning
-  {
-    DOMPointReadOnly* domPoint = nullptr;
-    if (NS_SUCCEEDED(UNWRAP_OBJECT(DOMPointReadOnly, &obj, domPoint))) {
-      return JS_WriteUint32Pair(aWriter, SCTAG_DOM_DOMPOINT_READONLY, 0) &&
-             domPoint->WriteStructuredClone(aWriter);
-    }
-  }
-
   // Handle DOMRect cloning
   // Should be done before DOMRecteReadOnly check
   // because every DOMRect is also a DOMRectReadOnly
   {
     DOMRect* domRect = nullptr;
     if (NS_SUCCEEDED(UNWRAP_OBJECT(DOMRect, &obj, domRect))) {
       return JS_WriteUint32Pair(aWriter, SCTAG_DOM_DOMRECT, 0) &&
              domRect->WriteStructuredClone(aWriter);
--- a/dom/base/StructuredCloneTags.h
+++ b/dom/base/StructuredCloneTags.h
@@ -41,17 +41,17 @@ enum StructuredCloneTags {
   // IDB.
   SCTAG_DOM_WASM,
 
   // IMPORTANT: Don't change the order of these enum values. You could break
   // IDB.
   SCTAG_DOM_IMAGEDATA,
 
   SCTAG_DOM_DOMPOINT,
-  SCTAG_DOM_DOMPOINT_READONLY,
+  SCTAG_DOM_DOMPOINTREADONLY,
 
   // IMPORTANT: Don't change the order of these enum values. You could break
   // IDB.
   // This tag is for WebCrypto keys
   SCTAG_DOM_WEBCRYPTO_KEY,
 
   // IMPORTANT: Don't change the order of these enum values. You could break
   // IDB.
--- a/dom/webidl/DOMPoint.webidl
+++ b/dom/webidl/DOMPoint.webidl
@@ -8,32 +8,34 @@
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 [Pref="layout.css.DOMPoint.enabled",
  Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
              optional unrestricted double z = 0, optional unrestricted double w = 1),
- Exposed=(Window,Worker)]
+ Exposed=(Window,Worker),
+ Serializable]
 interface DOMPointReadOnly {
     [NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other);
 
     readonly attribute unrestricted double x;
     readonly attribute unrestricted double y;
     readonly attribute unrestricted double z;
     readonly attribute unrestricted double w; 
 
     [Default] object toJSON();
 };
 
 [Pref="layout.css.DOMPoint.enabled",
  Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
              optional unrestricted double z = 0, optional unrestricted double w = 1),
- Exposed=(Window,Worker)]
+ Exposed=(Window,Worker),
+ Serializable]
 interface DOMPoint : DOMPointReadOnly {
     [NewObject] static DOMPoint fromPoint(optional DOMPointInit other);
 
     inherit attribute unrestricted double x;
     inherit attribute unrestricted double y;
     inherit attribute unrestricted double z;
     inherit attribute unrestricted double w;
 };