From b4cf4bec615b51deacbf3260c8b7a1bdf1a8bc3d Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Wed, 10 Aug 2016 14:18:29 +0800 Subject: [PATCH] Bug 1264642 - Part 6. Mark JSStructuredCloneData as MOZ_NON_MEMMOVABLE and add specializations in nsTArray.h. r=froydnj MozReview-Commit-ID: HltgzBnxMsn --- dom/base/StructuredCloneHolder.h | 4 ++ dom/indexedDB/IndexedDatabase.h | 4 ++ dom/indexedDB/IndexedDatabaseInlines.h | 14 ++++++ dom/ipc/PBrowser.ipdl | 3 +- dom/ipc/PContent.ipdl | 3 +- dom/ipc/PContentBridge.ipdl | 3 +- dom/ipc/StructuredCloneData.h | 5 +++ dom/network/TCPSocketChild.h | 1 + js/public/StructuredClone.h | 3 +- media/mtransport/nr_socket_prsock.cpp | 6 --- xpcom/glue/nsTArray.h | 62 +++++++++++++++++++------- 11 files changed, 81 insertions(+), 27 deletions(-) diff --git a/dom/base/StructuredCloneHolder.h b/dom/base/StructuredCloneHolder.h index 99806bd796bb..848a08ca0c56 100644 --- a/dom/base/StructuredCloneHolder.h +++ b/dom/base/StructuredCloneHolder.h @@ -36,6 +36,8 @@ public: StructuredCloneHolderBase(StructuredCloneScope aScope = StructuredCloneScope::SameProcessSameThread); virtual ~StructuredCloneHolderBase(); + StructuredCloneHolderBase(StructuredCloneHolderBase&& aOther) = default; + // These methods should be implemented in order to clone data. // Read more documentation in js/public/StructuredClone.h. @@ -150,6 +152,8 @@ public: StructuredCloneScope aStructuredCloneScope); virtual ~StructuredCloneHolder(); + StructuredCloneHolder(StructuredCloneHolder&& aOther) = default; + // Normally you should just use Write() and Read(). void Write(JSContext* aCx, diff --git a/dom/indexedDB/IndexedDatabase.h b/dom/indexedDB/IndexedDatabase.h index fcc3e325260f..fc0914bedb12 100644 --- a/dom/indexedDB/IndexedDatabase.h +++ b/dom/indexedDB/IndexedDatabase.h @@ -57,6 +57,10 @@ struct StructuredCloneReadInfo inline ~StructuredCloneReadInfo(); + // In IndexedDatabaseInlines.h + inline + StructuredCloneReadInfo(StructuredCloneReadInfo&& aOther); + // In IndexedDatabaseInlines.h inline StructuredCloneReadInfo& operator=(StructuredCloneReadInfo&& aOther); diff --git a/dom/indexedDB/IndexedDatabaseInlines.h b/dom/indexedDB/IndexedDatabaseInlines.h index c33bff89b9bd..36c90395488b 100644 --- a/dom/indexedDB/IndexedDatabaseInlines.h +++ b/dom/indexedDB/IndexedDatabaseInlines.h @@ -51,6 +51,20 @@ StructuredCloneReadInfo::StructuredCloneReadInfo() MOZ_COUNT_CTOR(StructuredCloneReadInfo); } +inline +StructuredCloneReadInfo::StructuredCloneReadInfo( + StructuredCloneReadInfo&& aCloneReadInfo) + : mData(Move(aCloneReadInfo.mData)) +{ + MOZ_ASSERT(&aCloneReadInfo != this); + MOZ_COUNT_CTOR(StructuredCloneReadInfo); + + mFiles.Clear(); + mFiles.SwapElements(aCloneReadInfo.mFiles); + mDatabase = aCloneReadInfo.mDatabase; + aCloneReadInfo.mDatabase = nullptr; +} + inline StructuredCloneReadInfo::StructuredCloneReadInfo( SerializedStructuredCloneReadInfo&& aCloneReadInfo) diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 1670982c2723..7f8aca5a82a0 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -65,7 +65,8 @@ using mozilla::WritingMode from "mozilla/WritingModes.h"; using mozilla::layers::TouchBehaviorFlags from "mozilla/layers/APZUtils.h"; using nsIWidget::TouchPointerState from "nsIWidget.h"; using struct LookAndFeelInt from "mozilla/widget/WidgetMessageUtils.h"; -using class mozilla::dom::ipc::StructuredCloneData from "ipc/IPCMessageUtils.h"; +using class mozilla::dom::MessagePort from "mozilla/dom/MessagePort.h"; +using class mozilla::dom::ipc::StructuredCloneData from "mozilla/dom/ipc/StructuredCloneData.h"; using mozilla::EventMessage from "mozilla/EventForwards.h"; using nsEventStatus from "mozilla/EventForwards.h"; using nsSizeMode from "nsIWidgetListener.h"; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 700c9e3d5f4a..597c062414bb 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -95,7 +95,8 @@ using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h"; using mozilla::dom::ContentParentId from "mozilla/dom/ipc/IdType.h"; using mozilla::LayoutDeviceIntPoint from "Units.h"; using struct LookAndFeelInt from "mozilla/widget/WidgetMessageUtils.h"; -using class mozilla::dom::ipc::StructuredCloneData from "ipc/IPCMessageUtils.h"; +using class mozilla::dom::MessagePort from "mozilla/dom/MessagePort.h"; +using class mozilla::dom::ipc::StructuredCloneData from "mozilla/dom/ipc/StructuredCloneData.h"; using mozilla::DataStorageType from "ipc/DataStorageIPCUtils.h"; using mozilla::DocShellOriginAttributes from "mozilla/ipc/BackgroundUtils.h"; using struct mozilla::layers::TextureFactoryIdentifier from "mozilla/layers/CompositorTypes.h"; diff --git a/dom/ipc/PContentBridge.ipdl b/dom/ipc/PContentBridge.ipdl index 77833f94d948..0bda94a30f75 100644 --- a/dom/ipc/PContentBridge.ipdl +++ b/dom/ipc/PContentBridge.ipdl @@ -16,7 +16,8 @@ include PTabContext; using class IPC::Principal from "mozilla/dom/PermissionMessageUtils.h"; using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h"; using mozilla::dom::ContentParentId from "mozilla/dom/ipc/IdType.h"; -using class mozilla::dom::ipc::StructuredCloneData from "ipc/IPCMessageUtils.h"; +using class mozilla::dom::MessagePort from "mozilla/dom/MessagePort.h"; +using class mozilla::dom::ipc::StructuredCloneData from "mozilla/dom/ipc/StructuredCloneData.h"; namespace mozilla { namespace dom { diff --git a/dom/ipc/StructuredCloneData.h b/dom/ipc/StructuredCloneData.h index d0b0f5da52f9..9e427e938c20 100644 --- a/dom/ipc/StructuredCloneData.h +++ b/dom/ipc/StructuredCloneData.h @@ -75,12 +75,17 @@ public: StructuredCloneData(const StructuredCloneData&) = delete; + StructuredCloneData(StructuredCloneData&& aOther) = default; + ~StructuredCloneData() {} StructuredCloneData& operator=(const StructuredCloneData& aOther) = delete; + StructuredCloneData& + operator=(StructuredCloneData&& aOther) = default; + const nsTArray>& BlobImpls() const { return mBlobImplArray; diff --git a/dom/network/TCPSocketChild.h b/dom/network/TCPSocketChild.h index b36a193dead9..af233d311410 100644 --- a/dom/network/TCPSocketChild.h +++ b/dom/network/TCPSocketChild.h @@ -7,6 +7,7 @@ #ifndef mozilla_dom_TCPSocketChild_h #define mozilla_dom_TCPSocketChild_h +#include "mozilla/dom/TypedArray.h" #include "mozilla/net/PTCPSocketChild.h" #include "nsCycleCollectionParticipant.h" #include "nsCOMPtr.h" diff --git a/js/public/StructuredClone.h b/js/public/StructuredClone.h index dbce34a84bc8..804902078ffd 100644 --- a/js/public/StructuredClone.h +++ b/js/public/StructuredClone.h @@ -7,6 +7,7 @@ #ifndef js_StructuredClone_h #define js_StructuredClone_h +#include "mozilla/Attributes.h" #include "mozilla/BufferList.h" #include @@ -160,7 +161,7 @@ enum OwnTransferablePolicy { NoTransferables }; -class JSStructuredCloneData : public mozilla::BufferList +class MOZ_NON_MEMMOVABLE JSStructuredCloneData : public mozilla::BufferList { typedef js::SystemAllocPolicy AllocPolicy; typedef mozilla::BufferList BufferList; diff --git a/media/mtransport/nr_socket_prsock.cpp b/media/mtransport/nr_socket_prsock.cpp index eaae28755908..8317534d757d 100644 --- a/media/mtransport/nr_socket_prsock.cpp +++ b/media/mtransport/nr_socket_prsock.cpp @@ -135,12 +135,6 @@ nrappkit copyright: #endif #undef strlcpy -// TCPSocketChild.h doesn't include TypedArray.h -namespace mozilla { -namespace dom { -class ArrayBuffer; -} -} #include "mozilla/dom/network/TCPSocketChild.h" #ifdef LOG_TEMP_INFO diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 2054b731abf3..4022cb243fa6 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -43,6 +43,33 @@ namespace layers { struct TileClient; } // namespace layers } // namespace mozilla + +namespace mozilla { +struct SerializedStructuredCloneBuffer; +} // namespace mozilla + +namespace mozilla { +namespace dom { +namespace ipc { +class StructuredCloneData; +} // namespace ipc +} // namespace dom +} // namespace mozilla + +namespace mozilla { +namespace dom { +class ClonedMessageData; +class MessagePortMessage; +namespace indexedDB { +struct StructuredCloneReadInfo; +class SerializedStructuredCloneReadInfo; +class ObjectStoreCursorResponse; +} // namespace indexedDB +} // namespace dom +} // namespace mozilla + +class JSStructuredCloneData; + // // nsTArray is a resizable array class, like std::vector. // @@ -685,29 +712,30 @@ struct MOZ_NEEDS_MEMMOVABLE_TYPE nsTArray_CopyChooser // Some classes require constructors/destructors to be called, so they are // specialized here. // +#define DECLARE_USE_COPY_CONSTRUCTORS(T) \ + template<> \ + struct nsTArray_CopyChooser \ + { \ + typedef nsTArray_CopyWithConstructors Type; \ + }; + template struct nsTArray_CopyChooser> { typedef nsTArray_CopyWithConstructors> Type; }; -template<> -struct nsTArray_CopyChooser -{ - typedef nsTArray_CopyWithConstructors Type; -}; - -template<> -struct nsTArray_CopyChooser -{ - typedef nsTArray_CopyWithConstructors Type; -}; - -template<> -struct nsTArray_CopyChooser -{ - typedef nsTArray_CopyWithConstructors Type; -}; +DECLARE_USE_COPY_CONSTRUCTORS(nsRegion) +DECLARE_USE_COPY_CONSTRUCTORS(nsIntRegion) +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::layers::TileClient) +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::SerializedStructuredCloneBuffer) +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::ipc::StructuredCloneData) +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::ClonedMessageData) +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::indexedDB::StructuredCloneReadInfo); +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::indexedDB::ObjectStoreCursorResponse) +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo); +DECLARE_USE_COPY_CONSTRUCTORS(JSStructuredCloneData) +DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::MessagePortMessage) //