From 0e550f2fb90ada0b608bc1e1982b100291651806 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Wed, 2 May 2018 11:07:35 -0700 Subject: Refactor structured clone JSAPI to prevent mismatched scopes. Roll-up of bugs 1442722, 1455071, 1433642, 1456604 and 1458320. --- dom/ipc/StructuredCloneData.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'dom/ipc/StructuredCloneData.h') diff --git a/dom/ipc/StructuredCloneData.h b/dom/ipc/StructuredCloneData.h index 9e427e938..64cfd1935 100644 --- a/dom/ipc/StructuredCloneData.h +++ b/dom/ipc/StructuredCloneData.h @@ -31,8 +31,8 @@ public: static already_AddRefed CreateFromExternalData(const char* aData, size_t aDataLength) { - JSStructuredCloneData buf; - buf.WriteBytes(aData, aDataLength); + JSStructuredCloneData buf(JS::StructuredCloneScope::DifferentProcess); + buf.AppendBytes(aData, aDataLength); RefPtr sharedData = new SharedJSAllocatedData(Move(buf)); return sharedData.forget(); @@ -41,12 +41,8 @@ public: static already_AddRefed CreateFromExternalData(const JSStructuredCloneData& aData) { - JSStructuredCloneData buf; - auto iter = aData.Iter(); - while (!iter.Done()) { - buf.WriteBytes(iter.Data(), iter.RemainingInSegment()); - iter.Advance(aData, iter.RemainingInSegment()); - } + JSStructuredCloneData buf(aData.scope()); + buf.Append(aData); RefPtr sharedData = new SharedJSAllocatedData(Move(buf)); return sharedData.forget(); @@ -70,6 +66,7 @@ public: : StructuredCloneHolder(StructuredCloneHolder::CloningSupported, StructuredCloneHolder::TransferringSupported, StructuredCloneHolder::StructuredCloneScope::DifferentProcess) + , mExternalData(StructuredCloneHolder::StructuredCloneScope::DifferentProcess) , mInitialized(false) {} @@ -113,10 +110,9 @@ public: bool UseExternalData(const JSStructuredCloneData& aData) { - auto iter = aData.Iter(); + auto iter = aData.Start(); bool success = false; - mExternalData = - aData.Borrow(iter, aData.Size(), &success); + mExternalData = aData.Borrow(iter, aData.Size(), &success); mInitialized = true; return success; } @@ -133,6 +129,11 @@ public: return mSharedData ? mSharedData->Data() : mExternalData; } + void InitScope(JS::StructuredCloneScope aScope) + { + Data().initScope(aScope); + } + size_t DataLength() const { return mSharedData ? mSharedData->DataLength() : mExternalData.Size(); -- cgit v1.2.3