Bug 1350254 part 4. Switch DOMPoint and DOMPointReadOnly to [Serializable]. r=baku

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-06-25 06:46:20 +00:00
Родитель 3bd779034c
Коммит a408716f68
6 изменённых файлов: 50 добавлений и 48 удалений

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

@ -39,7 +39,7 @@ JSObject* DOMPointReadOnly::WrapObject(JSContext* aCx,
// 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)
@ -50,6 +50,18 @@ bool DOMPointReadOnly::WriteStructuredClone(
#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;
@ -66,7 +78,6 @@ bool DOMPointReadOnly::ReadStructuredClone(JSStructuredCloneReader* aReader) {
ReadDouble(&mW);
return true;
#undef ReadDouble
}
@ -89,3 +100,15 @@ 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();
;
}

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

@ -16,6 +16,8 @@
#include "nsCOMPtr.h"
#include "mozilla/dom/BindingDeclarations.h"
class nsIGlobalObject;
namespace mozilla {
namespace dom {
@ -46,13 +48,20 @@ class DOMPointReadOnly : public nsWrapperCache {
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;
};
@ -72,6 +81,11 @@ class DOMPoint final : public DOMPointReadOnly {
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; }

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

@ -117,7 +117,7 @@ void DOMQuad::ToJSON(DOMQuadJSON& aInit) {
bool DOMQuad::WriteStructuredClone(JSContext* aCx,
JSStructuredCloneWriter* aWriter) const {
for (const auto& point : mPoints) {
if (!point->WriteStructuredClone(aWriter)) {
if (!point->WriteStructuredClone(aCx, aWriter)) {
return false;
}
}
@ -130,8 +130,8 @@ already_AddRefed<DOMQuad> DOMQuad::ReadStructuredClone(
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;
}
}

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

@ -16,8 +16,6 @@
#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"
@ -128,7 +126,7 @@ void StructuredCloneCallbacksError(JSContext* aCx, uint32_t aErrorId) {
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 &&
@ -358,7 +356,6 @@ JSObject* StructuredCloneHolder::ReadFullySerializableObjects(
}
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.
@ -378,20 +375,6 @@ JSObject* StructuredCloneHolder::ReadFullySerializableObjects(
} 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)) {
@ -533,26 +516,6 @@ bool StructuredCloneHolder::WriteFullySerializableObjects(
}
#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

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

@ -46,7 +46,7 @@ enum StructuredCloneTags {
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.

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

@ -13,7 +13,8 @@
[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);
@ -28,7 +29,8 @@ interface DOMPointReadOnly {
[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);