Backed out 5 changesets (bug 1605566) for wpt failures on shared.html . CLOSED TREE

Backed out changeset 622939cef438 (bug 1605566)
Backed out changeset ab98304e6c84 (bug 1605566)
Backed out changeset 7eab8fd2b62e (bug 1605566)
Backed out changeset 99f61f25ed86 (bug 1605566)
Backed out changeset 77bdf4f86052 (bug 1605566)
This commit is contained in:
Narcis Beleuzu 2020-01-22 12:58:13 +02:00
parent 325aed2d1f
commit cb54b0227b
31 changed files with 172 additions and 623 deletions

View File

@ -57,14 +57,11 @@ JSObject* StructuredCloneCallbacksRead(JSContext* aCx,
bool StructuredCloneCallbacksWrite(JSContext* aCx,
JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired,
void* aClosure) {
JS::Handle<JSObject*> aObj, void* aClosure) {
StructuredCloneHolderBase* holder =
static_cast<StructuredCloneHolderBase*>(aClosure);
MOZ_ASSERT(holder);
return holder->CustomWriteHandler(aCx, aWriter, aObj,
aSameProcessScopeRequired);
return holder->CustomWriteHandler(aCx, aWriter, aObj);
}
bool StructuredCloneCallbacksReadTransfer(
@ -103,13 +100,11 @@ void StructuredCloneCallbacksFreeTransfer(uint32_t aTag,
bool StructuredCloneCallbacksCanTransfer(JSContext* aCx,
JS::Handle<JSObject*> aObject,
bool* aSameProcessScopeRequired,
void* aClosure) {
StructuredCloneHolderBase* holder =
static_cast<StructuredCloneHolderBase*>(aClosure);
MOZ_ASSERT(holder);
return holder->CustomCanTransferHandler(aCx, aObject,
aSameProcessScopeRequired);
return holder->CustomCanTransferHandler(aCx, aObject);
}
void StructuredCloneCallbacksError(JSContext* aCx, uint32_t aErrorId) {
@ -234,8 +229,7 @@ void StructuredCloneHolderBase::CustomFreeTransferHandler(
}
bool StructuredCloneHolderBase::CustomCanTransferHandler(
JSContext* aCx, JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) {
JSContext* aCx, JS::Handle<JSObject*> aObj) {
return false;
}
@ -327,9 +321,9 @@ void StructuredCloneHolder::ReadFromBuffer(nsIGlobalObject* aGlobal,
mozilla::AutoRestore<nsIGlobalObject*> guard(mGlobal);
mGlobal = aGlobal;
if (!JS_ReadStructuredClone(aCx, aBuffer, aAlgorithmVersion, CloneScope(),
aValue, JS::CloneDataPolicy(), &sCallbacks,
this)) {
if (!JS_ReadStructuredClone(aCx, aBuffer, aAlgorithmVersion,
mStructuredCloneScope, aValue,
JS::CloneDataPolicy(), &sCallbacks, this)) {
JS_ClearPendingException(aCx);
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
}
@ -890,7 +884,7 @@ JSObject* StructuredCloneHolder::CustomReadHandler(
}
if (aTag == SCTAG_DOM_IMAGEBITMAP &&
CloneScope() == StructuredCloneScope::SameProcess) {
mStructuredCloneScope == StructuredCloneScope::SameProcess) {
// Get the current global object.
// This can be null.
JS::RootedObject result(aCx);
@ -907,7 +901,7 @@ JSObject* StructuredCloneHolder::CustomReadHandler(
}
if (aTag == SCTAG_DOM_WASM &&
CloneScope() == StructuredCloneScope::SameProcess) {
mStructuredCloneScope == StructuredCloneScope::SameProcess) {
return ReadWasmModule(aCx, aIndex, this);
}
@ -926,9 +920,9 @@ JSObject* StructuredCloneHolder::CustomReadHandler(
return ReadFullySerializableObjects(aCx, aReader, aTag);
}
bool StructuredCloneHolder::CustomWriteHandler(
JSContext* aCx, JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj, bool* aSameProcessScopeRequired) {
bool StructuredCloneHolder::CustomWriteHandler(JSContext* aCx,
JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj) {
if (!mSupportsCloning) {
return false;
}
@ -968,16 +962,11 @@ bool StructuredCloneHolder::CustomWriteHandler(
}
// See if this is an ImageBitmap object.
{
if (mStructuredCloneScope == StructuredCloneScope::SameProcess) {
ImageBitmap* imageBitmap = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageBitmap, &obj, imageBitmap))) {
SameProcessScopeRequired(aSameProcessScopeRequired);
if (CloneScope() == StructuredCloneScope::SameProcess) {
return ImageBitmap::WriteStructuredClone(aWriter, GetSurfaces(),
imageBitmap);
}
return false;
return ImageBitmap::WriteStructuredClone(aWriter, GetSurfaces(),
imageBitmap);
}
}
@ -990,7 +979,8 @@ bool StructuredCloneHolder::CustomWriteHandler(
}
// See if this is a BrowsingContext object.
{
if (mStructuredCloneScope == StructuredCloneScope::SameProcess ||
mStructuredCloneScope == StructuredCloneScope::DifferentProcess) {
BrowsingContext* holder = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(BrowsingContext, &obj, holder))) {
return holder->WriteStructuredClone(aCx, aWriter, this);
@ -1006,15 +996,12 @@ bool StructuredCloneHolder::CustomWriteHandler(
}
// See if this is a WasmModule.
if (JS::IsWasmModuleObject(obj)) {
SameProcessScopeRequired(aSameProcessScopeRequired);
if (CloneScope() == StructuredCloneScope::SameProcess) {
RefPtr<JS::WasmModule> module = JS::GetWasmModule(obj);
MOZ_ASSERT(module);
if (mStructuredCloneScope == StructuredCloneScope::SameProcess &&
JS::IsWasmModuleObject(obj)) {
RefPtr<JS::WasmModule> module = JS::GetWasmModule(obj);
MOZ_ASSERT(module);
return WriteWasmModule(aWriter, module, this);
}
return false;
return WriteWasmModule(aWriter, module, this);
}
{
@ -1064,7 +1051,7 @@ bool StructuredCloneHolder::CustomReadTransferHandler(
}
if (aTag == SCTAG_DOM_CANVAS &&
CloneScope() == StructuredCloneScope::SameProcess) {
mStructuredCloneScope == StructuredCloneScope::SameProcess) {
MOZ_ASSERT(aContent);
OffscreenCanvasCloneData* data =
static_cast<OffscreenCanvasCloneData*>(aContent);
@ -1083,7 +1070,7 @@ bool StructuredCloneHolder::CustomReadTransferHandler(
}
if (aTag == SCTAG_DOM_IMAGEBITMAP &&
CloneScope() == StructuredCloneScope::SameProcess) {
mStructuredCloneScope == StructuredCloneScope::SameProcess) {
MOZ_ASSERT(aContent);
ImageBitmapCloneData* data = static_cast<ImageBitmapCloneData*>(aContent);
RefPtr<ImageBitmap> bitmap =
@ -1135,7 +1122,7 @@ bool StructuredCloneHolder::CustomWriteTransferHandler(
return true;
}
if (CloneScope() == StructuredCloneScope::SameProcess) {
if (mStructuredCloneScope == StructuredCloneScope::SameProcess) {
OffscreenCanvas* canvas = nullptr;
rv = UNWRAP_OBJECT(OffscreenCanvas, &obj, canvas);
if (NS_SUCCEEDED(rv)) {
@ -1199,7 +1186,7 @@ void StructuredCloneHolder::CustomFreeTransferHandler(
}
if (aTag == SCTAG_DOM_CANVAS &&
CloneScope() == StructuredCloneScope::SameProcess) {
mStructuredCloneScope == StructuredCloneScope::SameProcess) {
MOZ_ASSERT(aContent);
OffscreenCanvasCloneData* data =
static_cast<OffscreenCanvasCloneData*>(aContent);
@ -1208,7 +1195,7 @@ void StructuredCloneHolder::CustomFreeTransferHandler(
}
if (aTag == SCTAG_DOM_IMAGEBITMAP &&
CloneScope() == StructuredCloneScope::SameProcess) {
mStructuredCloneScope == StructuredCloneScope::SameProcess) {
MOZ_ASSERT(aContent);
ImageBitmapCloneData* data = static_cast<ImageBitmapCloneData*>(aContent);
delete data;
@ -1217,8 +1204,7 @@ void StructuredCloneHolder::CustomFreeTransferHandler(
}
bool StructuredCloneHolder::CustomCanTransferHandler(
JSContext* aCx, JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) {
JSContext* aCx, JS::Handle<JSObject*> aObj) {
if (!mSupportsTransferring) {
return false;
}
@ -1231,23 +1217,19 @@ bool StructuredCloneHolder::CustomCanTransferHandler(
if (NS_SUCCEEDED(rv)) {
return true;
}
}
{
OffscreenCanvas* canvas = nullptr;
nsresult rv = UNWRAP_OBJECT(OffscreenCanvas, &obj, canvas);
if (NS_SUCCEEDED(rv)) {
SameProcessScopeRequired(aSameProcessScopeRequired);
return CloneScope() == StructuredCloneScope::SameProcess;
}
}
if (mStructuredCloneScope == StructuredCloneScope::SameProcess) {
OffscreenCanvas* canvas = nullptr;
rv = UNWRAP_OBJECT(OffscreenCanvas, &obj, canvas);
if (NS_SUCCEEDED(rv)) {
return true;
}
{
ImageBitmap* bitmap = nullptr;
nsresult rv = UNWRAP_OBJECT(ImageBitmap, &obj, bitmap);
if (NS_SUCCEEDED(rv)) {
SameProcessScopeRequired(aSameProcessScopeRequired);
return CloneScope() == StructuredCloneScope::SameProcess;
ImageBitmap* bitmap = nullptr;
rv = UNWRAP_OBJECT(ImageBitmap, &obj, bitmap);
if (NS_SUCCEEDED(rv)) {
return true;
}
}
}
@ -1268,14 +1250,5 @@ bool StructuredCloneHolder::TakeTransferredPortsAsSequence(
return true;
}
void StructuredCloneHolder::SameProcessScopeRequired(
bool* aSameProcessScopeRequired) {
MOZ_ASSERT(aSameProcessScopeRequired);
if (mStructuredCloneScope == StructuredCloneScope::UnknownDestination) {
mStructuredCloneScope = StructuredCloneScope::SameProcess;
*aSameProcessScopeRequired = true;
}
}
} // namespace dom
} // namespace mozilla

View File

@ -57,8 +57,7 @@ class StructuredCloneHolderBase {
virtual bool CustomWriteHandler(JSContext* aCx,
JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) = 0;
JS::Handle<JSObject*> aObj) = 0;
// This method has to be called when this object is not needed anymore.
// It will free memory and the buffer. This has to be called because
@ -88,8 +87,7 @@ class StructuredCloneHolderBase {
void* aContent, uint64_t aExtraData);
virtual bool CustomCanTransferHandler(JSContext* aCx,
JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired);
JS::Handle<JSObject*> aObj);
// These methods are what you should use to read/write data.
@ -200,14 +198,7 @@ class StructuredCloneHolder : public StructuredCloneHolderBase {
return mInputStreamArray;
}
// This method returns the final scope. If the final scope is unknown,
// DifferentProcess is returned because it's the most restrictive one.
StructuredCloneScope CloneScope() const {
if (mStructuredCloneScope == StructuredCloneScope::UnknownDestination) {
return StructuredCloneScope::DifferentProcess;
}
return mStructuredCloneScope;
}
StructuredCloneScope CloneScope() const { return mStructuredCloneScope; }
// The global object is set internally just during the Read(). This method
// can be used by read functions to retrieve it.
@ -244,8 +235,7 @@ class StructuredCloneHolder : public StructuredCloneHolderBase {
virtual bool CustomWriteHandler(JSContext* aCx,
JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) override;
JS::Handle<JSObject*> aObj) override;
virtual bool CustomReadTransferHandler(
JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag,
@ -264,9 +254,8 @@ class StructuredCloneHolder : public StructuredCloneHolderBase {
void* aContent,
uint64_t aExtraData) override;
virtual bool CustomCanTransferHandler(
JSContext* aCx, JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) override;
virtual bool CustomCanTransferHandler(JSContext* aCx,
JS::Handle<JSObject*> aObj) override;
// These 2 static methods are useful to read/write fully serializable objects.
// They can be used by custom StructuredCloneHolderBase classes to
@ -299,8 +288,6 @@ class StructuredCloneHolder : public StructuredCloneHolderBase {
uint32_t aAlgorithmVersion,
JS::MutableHandle<JS::Value> aValue, ErrorResult& aRv);
void SameProcessScopeRequired(bool* aSameProcessScopeRequired);
bool mSupportsCloning;
bool mSupportsTransferring;

View File

@ -549,7 +549,7 @@ function test_messagePort() {
runTests({
clonableObjectsEveryWhere: true,
clonableObjectsSameProcess: true,
clonableObjectsSameProcess: false,
transferableObjects: true,
send(what, ports) {
return new Promise(function(r, rr) {

View File

@ -308,8 +308,7 @@ class ConsoleRunnable : public StructuredCloneHolderBase {
}
bool CustomWriteHandler(JSContext* aCx, JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) override {
JS::Handle<JSObject*> aObj) override {
RefPtr<Blob> blob;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) {
if (NS_WARN_IF(!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_BLOB,

View File

@ -193,8 +193,7 @@ RefPtr<IDBRequest> GenerateRequest(JSContext* aCx,
bool StructuredCloneWriteCallback(JSContext* aCx,
JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessRequired, void* aClosure) {
JS::Handle<JSObject*> aObj, void* aClosure) {
MOZ_ASSERT(aCx);
MOZ_ASSERT(aWriter);
MOZ_ASSERT(aClosure);
@ -353,7 +352,6 @@ bool StructuredCloneWriteCallback(JSContext* aCx,
bool CopyingStructuredCloneWriteCallback(JSContext* aCx,
JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessRequired,
void* aClosure) {
MOZ_ASSERT(aCx);
MOZ_ASSERT(aWriter);

View File

@ -47,19 +47,6 @@ StructuredCloneData::StructuredCloneData(
mExternalData(JS::StructuredCloneScope::DifferentProcess),
mInitialized(false) {}
StructuredCloneData::StructuredCloneData(
StructuredCloneHolder::StructuredCloneScope aScope)
: StructuredCloneHolder(StructuredCloneHolder::CloningSupported,
StructuredCloneHolder::TransferringSupported,
aScope),
mExternalData(JS::StructuredCloneScope::DifferentProcess),
mInitialized(false) {
MOZ_ASSERT(
aScope == StructuredCloneHolder::StructuredCloneScope::DifferentProcess ||
aScope ==
StructuredCloneHolder::StructuredCloneScope::UnknownDestination);
}
StructuredCloneData::~StructuredCloneData() {}
StructuredCloneData& StructuredCloneData::operator=(

View File

@ -67,7 +67,7 @@ class SharedJSAllocatedData final {
return sharedData.forget();
}
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedJSAllocatedData)
NS_INLINE_DECL_REFCOUNTING(SharedJSAllocatedData)
JSStructuredCloneData& Data() { return mData; }
size_t DataLength() const { return mData.Size(); }
@ -149,9 +149,6 @@ class StructuredCloneData : public StructuredCloneHolder {
StructuredCloneData(StructuredCloneData&& aOther);
// Only DifferentProcess and UnknownDestination scopes are supported.
explicit StructuredCloneData(StructuredCloneScope aScope);
~StructuredCloneData();
StructuredCloneData& operator=(const StructuredCloneData& aOther) = delete;

View File

@ -31,7 +31,6 @@
#include "nsGlobalWindow.h"
#include "nsPresContext.h"
#include "SharedMessagePortMessage.h"
#include "RefMessageBodyService.h"
#include "nsIBFCacheEntry.h"
#include "mozilla/dom/Document.h"
@ -123,7 +122,7 @@ class PostMessageRunnable final : public CancelableRunnable {
MarkerTracingType::START);
}
mData->Read(cx, &value, mPort->mRefMessageBodyService, rv);
mData->Read(cx, &value, rv);
if (isTimelineRecording) {
end = MakeUnique<MessagePortTimelineMarker>(
@ -197,7 +196,6 @@ NS_IMPL_RELEASE_INHERITED(MessagePort, DOMEventTargetHelper)
MessagePort::MessagePort(nsIGlobalObject* aGlobal, State aState)
: DOMEventTargetHelper(aGlobal),
mRefMessageBodyService(RefMessageBodyService::GetOrCreate()),
mState(aState),
mMessageQueueEnabled(false),
mIsKeptAlive(false),
@ -342,8 +340,7 @@ void MessagePort::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
MarkerTracingType::START);
}
data->Write(aCx, aMessage, transferable, mIdentifier->uuid(),
mRefMessageBodyService, aRv);
data->Write(aCx, aMessage, transferable, aRv);
if (isTimelineRecording) {
end = MakeUnique<MessagePortTimelineMarker>(
@ -390,7 +387,7 @@ void MessagePort::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
AutoTArray<RefPtr<SharedMessagePortMessage>, 1> array;
array.AppendElement(data);
AutoTArray<MessageData, 1> messages;
AutoTArray<ClonedMessageData, 1> messages;
// note: `messages` will borrow the underlying buffer, but this is okay
// because reverse destruction order means `messages` will be destroyed prior
// to `array`/`data`.
@ -492,10 +489,6 @@ void MessagePort::CloseInternal(bool aSoftly) {
mMessages.Clear();
}
// Let's inform the RefMessageBodyService that any our shared messages are
// now invalid.
mRefMessageBodyService->ForgetPort(mIdentifier->uuid());
if (mState == eStateUnshippedEntangled) {
MOZ_DIAGNOSTIC_ASSERT(mUnshippedEntangledPort);
@ -560,7 +553,7 @@ void MessagePort::SetOnmessage(EventHandlerNonNull* aCallback) {
// another actor. It receives a list of messages to be dispatch. It can be that
// we were waiting for this entangling step in order to disentangle the port or
// to close it.
void MessagePort::Entangled(nsTArray<MessageData>& aMessages) {
void MessagePort::Entangled(nsTArray<ClonedMessageData>& aMessages) {
MOZ_ASSERT(mState == eStateEntangling ||
mState == eStateEntanglingForDisentangle ||
mState == eStateEntanglingForClose);
@ -571,7 +564,7 @@ void MessagePort::Entangled(nsTArray<MessageData>& aMessages) {
// If we have pending messages, these have to be sent.
if (!mMessagesForTheOtherPort.IsEmpty()) {
{
nsTArray<MessageData> messages;
nsTArray<ClonedMessageData> messages;
SharedMessagePortMessage::FromSharedToMessagesChild(
mActor, mMessagesForTheOtherPort, messages);
mActor->SendPostMessages(messages);
@ -621,7 +614,7 @@ void MessagePort::StartDisentangling() {
mActor->SendStopSendingData();
}
void MessagePort::MessagesReceived(nsTArray<MessageData>& aMessages) {
void MessagePort::MessagesReceived(nsTArray<ClonedMessageData>& aMessages) {
MOZ_ASSERT(mState == eStateEntangled || mState == eStateDisentangling ||
// This last step can happen only if Close() has been called
// manually. At this point SendClose() is sent but we can still
@ -659,18 +652,13 @@ void MessagePort::Disentangle() {
mState = eStateDisentangled;
{
nsTArray<MessageData> messages;
nsTArray<ClonedMessageData> messages;
SharedMessagePortMessage::FromSharedToMessagesChild(mActor, mMessages,
messages);
mActor->SendDisentangle(messages);
}
// Let's inform the RefMessageBodyService that any our shared messages are
// now invalid.
mRefMessageBodyService->ForgetPort(mIdentifier->uuid());
// Only clear mMessages after the MessageData instances have gone out of scope
// because they borrow mMessages' underlying JSStructuredCloneDatas.
// Only clear mMessages after the ClonedMessageData instances have gone out of
// scope because they borrow mMessages' underlying JSStructuredCloneDatas.
mMessages.Clear();
mActor->SetPort(nullptr);

View File

@ -22,12 +22,10 @@ class nsIGlobalObject;
namespace mozilla {
namespace dom {
class MessageData;
class MessagePortChild;
struct PostMessageOptions;
class PostMessageRunnable;
class SharedMessagePortMessage;
class RefMessageBodyService;
class StrongWorkerRef;
// A class to hold a MessagePortIdentifier from
@ -120,8 +118,8 @@ class MessagePort final : public DOMEventTargetHelper {
// These methods are useful for MessagePortChild
void Entangled(nsTArray<MessageData>& aMessages);
void MessagesReceived(nsTArray<MessageData>& aMessages);
void Entangled(nsTArray<ClonedMessageData>& aMessages);
void MessagesReceived(nsTArray<ClonedMessageData>& aMessages);
void StopSendingDataConfirmed();
void Closed();
@ -208,8 +206,6 @@ class MessagePort final : public DOMEventTargetHelper {
RefPtr<MessagePort> mUnshippedEntangledPort;
RefPtr<RefMessageBodyService> mRefMessageBodyService;
nsTArray<RefPtr<SharedMessagePortMessage>> mMessages;
nsTArray<RefPtr<SharedMessagePortMessage>> mMessagesForTheOtherPort;

View File

@ -22,7 +22,7 @@ mozilla::ipc::IPCResult MessagePortChild::RecvStopSendingDataConfirmed() {
}
mozilla::ipc::IPCResult MessagePortChild::RecvEntangled(
nsTArray<MessageData>&& aMessages) {
nsTArray<ClonedMessageData>&& aMessages) {
if (mPort) {
mPort->Entangled(aMessages);
}
@ -30,7 +30,7 @@ mozilla::ipc::IPCResult MessagePortChild::RecvEntangled(
}
mozilla::ipc::IPCResult MessagePortChild::RecvReceiveData(
nsTArray<MessageData>&& aMessages) {
nsTArray<ClonedMessageData>&& aMessages) {
if (mPort) {
mPort->MessagesReceived(aMessages);
}

View File

@ -29,9 +29,11 @@ class MessagePortChild final : public PMessagePortChild {
private:
~MessagePortChild() { MOZ_ASSERT(!mPort); }
mozilla::ipc::IPCResult RecvEntangled(nsTArray<MessageData>&& aMessages);
mozilla::ipc::IPCResult RecvEntangled(
nsTArray<ClonedMessageData>&& aMessages);
mozilla::ipc::IPCResult RecvReceiveData(nsTArray<MessageData>&& aMessages);
mozilla::ipc::IPCResult RecvReceiveData(
nsTArray<ClonedMessageData>&& aMessages);
mozilla::ipc::IPCResult RecvStopSendingDataConfirmed();

View File

@ -38,7 +38,7 @@ bool MessagePortParent::Entangle(const nsID& aDestinationUUID,
}
mozilla::ipc::IPCResult MessagePortParent::RecvPostMessages(
nsTArray<MessageData>&& aMessages) {
nsTArray<ClonedMessageData>&& aMessages) {
// This converts the object in a data struct where we have BlobImpls.
FallibleTArray<RefPtr<SharedMessagePortMessage>> messages;
if (NS_WARN_IF(!SharedMessagePortMessage::FromMessagesToSharedParent(
@ -66,7 +66,7 @@ mozilla::ipc::IPCResult MessagePortParent::RecvPostMessages(
}
mozilla::ipc::IPCResult MessagePortParent::RecvDisentangle(
nsTArray<MessageData>&& aMessages) {
nsTArray<ClonedMessageData>&& aMessages) {
// This converts the object in a data struct where we have BlobImpls.
FallibleTArray<RefPtr<SharedMessagePortMessage>> messages;
if (NS_WARN_IF(!SharedMessagePortMessage::FromMessagesToSharedParent(
@ -127,7 +127,8 @@ void MessagePortParent::ActorDestroy(ActorDestroyReason aWhy) {
}
}
bool MessagePortParent::Entangled(const nsTArray<MessageData>& aMessages) {
bool MessagePortParent::Entangled(
const nsTArray<ClonedMessageData>& aMessages) {
MOZ_ASSERT(!mEntangled);
mEntangled = true;
return SendEntangled(aMessages);

View File

@ -26,7 +26,7 @@ class MessagePortParent final
bool Entangle(const nsID& aDestinationUUID, const uint32_t& aSequenceID);
bool Entangled(const nsTArray<MessageData>& aMessages);
bool Entangled(const nsTArray<ClonedMessageData>& aMessages);
void Close();
void CloseAndDelete();
@ -39,9 +39,11 @@ class MessagePortParent final
const uint32_t& aSequenceID);
private:
mozilla::ipc::IPCResult RecvPostMessages(nsTArray<MessageData>&& aMessages);
mozilla::ipc::IPCResult RecvPostMessages(
nsTArray<ClonedMessageData>&& aMessages);
mozilla::ipc::IPCResult RecvDisentangle(nsTArray<MessageData>&& aMessages);
mozilla::ipc::IPCResult RecvDisentangle(
nsTArray<ClonedMessageData>&& aMessages);
mozilla::ipc::IPCResult RecvStopSendingData();

View File

@ -148,7 +148,7 @@ bool MessagePortService::RequestEntangling(MessagePortParent* aParent,
// that reverse destruction order works for us.
FallibleTArray<RefPtr<SharedMessagePortMessage>> messages(
std::move(data->mMessages));
FallibleTArray<MessageData> array;
FallibleTArray<ClonedMessageData> array;
if (!SharedMessagePortMessage::FromSharedToMessagesParent(aParent, messages,
array)) {
CloseAll(aParent->ID());
@ -231,7 +231,7 @@ bool MessagePortService::DisentanglePort(
data->mParent = nextParent;
data->mNextParents.RemoveElementAt(index);
FallibleTArray<MessageData> array;
FallibleTArray<ClonedMessageData> array;
if (!SharedMessagePortMessage::FromSharedToMessagesParent(data->mParent,
aMessages, array)) {
return false;
@ -348,7 +348,7 @@ bool MessagePortService::PostMessages(
// If the parent can send data to the child, let's proceed.
if (data->mParent && data->mParent->CanSendData()) {
{
FallibleTArray<MessageData> messages;
FallibleTArray<ClonedMessageData> messages;
if (!SharedMessagePortMessage::FromSharedToMessagesParent(
data->mParent, data->mMessages, messages)) {
return false;

View File

@ -9,7 +9,6 @@ include protocol PIPCBlobInputStream; // FIXME: bug 792908
include protocol PParentToChildStream; // FIXME: bug 792908
include DOMTypes;
include ProtocolTypes;
using struct mozilla::SerializedStructuredCloneBuffer
from "ipc/IPCMessageUtils.h";
@ -17,15 +16,6 @@ using struct mozilla::SerializedStructuredCloneBuffer
namespace mozilla {
namespace dom {
struct RefMessageData {
nsID uuid;
};
union MessageData {
ClonedMessageData;
RefMessageData;
};
// This protocol is used for the MessageChannel/MessagePort API
protocol PMessagePort
{
@ -45,14 +35,14 @@ protocol PMessagePort
4. Recv__delete__(); */
parent:
async PostMessages(MessageData[] messages);
async Disentangle(MessageData[] messages);
async PostMessages(ClonedMessageData[] messages);
async Disentangle(ClonedMessageData[] messages);
async StopSendingData();
async Close();
child:
async Entangled(MessageData[] messages);
async ReceiveData(MessageData[] messages);
async Entangled(ClonedMessageData[] messages);
async ReceiveData(ClonedMessageData[] messages);
async StopSendingDataConfirmed();
async __delete__();

View File

@ -1,86 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RefMessageBodyService.h"
namespace mozilla {
namespace dom {
StaticMutex sRefMessageBodyServiceMutex;
// Raw pointer because the service is kept alive by MessagePorts.
// See the CTOR and the DTOR of this object.
RefMessageBodyService* sService;
// static
already_AddRefed<RefMessageBodyService> RefMessageBodyService::GetOrCreate() {
StaticMutexAutoLock lock(sRefMessageBodyServiceMutex);
RefPtr<RefMessageBodyService> service = GetOrCreateInternal(lock);
return service.forget();
}
// static
RefMessageBodyService* RefMessageBodyService::GetOrCreateInternal(
const StaticMutexAutoLock& aProofOfLock) {
if (!sService) {
sService = new RefMessageBodyService();
}
return sService;
}
RefMessageBodyService::RefMessageBodyService() {
MOZ_DIAGNOSTIC_ASSERT(sService == nullptr);
}
RefMessageBodyService::~RefMessageBodyService() {
MOZ_DIAGNOSTIC_ASSERT(sService == this);
sService = nullptr;
}
nsID RefMessageBodyService::Register(already_AddRefed<RefMessageBody> aBody,
ErrorResult& aRv) {
RefPtr<RefMessageBody> body = aBody;
MOZ_ASSERT(body);
nsID uuid = {};
aRv = nsContentUtils::GenerateUUIDInPlace(uuid);
if (NS_WARN_IF(aRv.Failed())) {
return nsID();
}
StaticMutexAutoLock lock(sRefMessageBodyServiceMutex);
GetOrCreateInternal(lock)->mMessages.Put(uuid, body);
return uuid;
}
already_AddRefed<RefMessageBody> RefMessageBodyService::Steal(nsID& aID) {
StaticMutexAutoLock lock(sRefMessageBodyServiceMutex);
if (!sService) {
return nullptr;
}
RefPtr<RefMessageBody> body;
sService->mMessages.Remove(aID, getter_AddRefs(body));
return body.forget();
}
void RefMessageBodyService::ForgetPort(nsID& aPortID) {
StaticMutexAutoLock lock(sRefMessageBodyServiceMutex);
if (!sService) {
return;
}
for (auto iter = sService->mMessages.ConstIter(); !iter.Done(); iter.Next()) {
if (iter.UserData()->PortID() == aPortID) {
iter.Remove();
}
}
}
} // namespace dom
} // namespace mozilla

View File

@ -1,62 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_RefMessageBodyService_h
#define mozilla_dom_RefMessageBodyService_h
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/StructuredCloneHolder.h"
#include "mozilla/StaticMutex.h"
#include "nsRefPtrHashtable.h"
namespace mozilla {
namespace dom {
class RefMessageBody final {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RefMessageBody)
RefMessageBody(nsID& aPortID,
UniquePtr<ipc::StructuredCloneData>&& aCloneData)
: mPortID(aPortID), mCloneData(std::move(aCloneData)) {}
const nsID& PortID() const { return mPortID; }
ipc::StructuredCloneData* CloneData() { return mCloneData.get(); }
private:
~RefMessageBody() = default;
nsID mPortID;
UniquePtr<ipc::StructuredCloneData> mCloneData;
};
class RefMessageBodyService final {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RefMessageBodyService)
static already_AddRefed<RefMessageBodyService> GetOrCreate();
void ForgetPort(nsID& aPortID);
nsID Register(already_AddRefed<RefMessageBody> aBody, ErrorResult& aRv);
already_AddRefed<RefMessageBody> Steal(nsID& aID);
private:
RefMessageBodyService();
~RefMessageBodyService();
static RefMessageBodyService* GetOrCreateInternal(
const StaticMutexAutoLock& aProofOfLock);
nsRefPtrHashtable<nsIDHashKey, RefMessageBody> mMessages;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_RefMessageBodyService_h

View File

@ -4,7 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RefMessageBodyService.h"
#include "SharedMessagePortMessage.h"
#include "MessagePort.h"
#include "MessagePortChild.h"
@ -20,67 +19,11 @@ using namespace ipc;
namespace dom {
SharedMessagePortMessage::SharedMessagePortMessage() : mRefDataId({}) {}
void SharedMessagePortMessage::Write(
JSContext* aCx, JS::Handle<JS::Value> aValue,
JS::Handle<JS::Value> aTransfers, nsID& aPortID,
RefMessageBodyService* aRefMessageBodyService, ErrorResult& aRv) {
MOZ_ASSERT(!mCloneData && !mRefData);
MOZ_ASSERT(aRefMessageBodyService);
mCloneData = MakeUnique<ipc::StructuredCloneData>(
JS::StructuredCloneScope::UnknownDestination);
mCloneData->Write(aCx, aValue, aTransfers, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (mCloneData->CloneScope() == JS::StructuredCloneScope::DifferentProcess) {
return;
}
MOZ_ASSERT(mCloneData->CloneScope() == JS::StructuredCloneScope::SameProcess);
RefPtr<RefMessageBody> refData =
new RefMessageBody(aPortID, std::move(mCloneData));
mRefDataId = aRefMessageBodyService->Register(refData.forget(), aRv);
}
void SharedMessagePortMessage::Read(
JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
RefMessageBodyService* aRefMessageBodyService, ErrorResult& aRv) {
MOZ_ASSERT(aRefMessageBodyService);
if (mCloneData) {
return mCloneData->Read(aCx, aValue, aRv);
}
MOZ_ASSERT(!mRefData);
mRefData = aRefMessageBodyService->Steal(mRefDataId);
if (!mRefData) {
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
return;
}
mRefData->CloneData()->Read(aCx, aValue, aRv);
}
bool SharedMessagePortMessage::TakeTransferredPortsAsSequence(
Sequence<OwningNonNull<mozilla::dom::MessagePort>>& aPorts) {
if (mCloneData) {
return mCloneData->TakeTransferredPortsAsSequence(aPorts);
}
MOZ_ASSERT(mRefData);
return mRefData->CloneData()->TakeTransferredPortsAsSequence(aPorts);
}
/* static */
void SharedMessagePortMessage::FromSharedToMessagesChild(
MessagePortChild* aActor,
const nsTArray<RefPtr<SharedMessagePortMessage>>& aData,
nsTArray<MessageData>& aArray) {
nsTArray<ClonedMessageData>& aArray) {
MOZ_ASSERT(aActor);
MOZ_ASSERT(aArray.IsEmpty());
aArray.SetCapacity(aData.Length());
@ -89,23 +32,14 @@ void SharedMessagePortMessage::FromSharedToMessagesChild(
MOZ_ASSERT(backgroundManager);
for (auto& data : aData) {
MessageData* message = aArray.AppendElement();
if (data->mCloneData) {
ClonedMessageData clonedData;
data->mCloneData->BuildClonedMessageDataForBackgroundChild(
backgroundManager, clonedData);
*message = clonedData;
continue;
}
*message = RefMessageData(data->mRefDataId);
ClonedMessageData* message = aArray.AppendElement();
data->BuildClonedMessageDataForBackgroundChild(backgroundManager, *message);
}
}
/* static */
bool SharedMessagePortMessage::FromMessagesToSharedChild(
nsTArray<MessageData>& aArray,
nsTArray<ClonedMessageData>& aArray,
FallibleTArray<RefPtr<SharedMessagePortMessage>>& aData) {
MOZ_ASSERT(aData.IsEmpty());
@ -115,15 +49,7 @@ bool SharedMessagePortMessage::FromMessagesToSharedChild(
for (auto& message : aArray) {
RefPtr<SharedMessagePortMessage> data = new SharedMessagePortMessage();
if (message.type() == MessageData::TClonedMessageData) {
data->mCloneData = MakeUnique<ipc::StructuredCloneData>(
JS::StructuredCloneScope::UnknownDestination);
data->mCloneData->StealFromClonedMessageDataForBackgroundChild(message);
} else {
MOZ_ASSERT(message.type() == MessageData::TRefMessageData);
data->mRefDataId = message.get_RefMessageData().uuid();
}
data->StealFromClonedMessageDataForBackgroundChild(message);
if (!aData.AppendElement(data, mozilla::fallible)) {
return false;
@ -137,7 +63,7 @@ bool SharedMessagePortMessage::FromMessagesToSharedChild(
bool SharedMessagePortMessage::FromSharedToMessagesParent(
MessagePortParent* aActor,
const nsTArray<RefPtr<SharedMessagePortMessage>>& aData,
FallibleTArray<MessageData>& aArray) {
FallibleTArray<ClonedMessageData>& aArray) {
MOZ_ASSERT(aArray.IsEmpty());
if (NS_WARN_IF(!aArray.SetCapacity(aData.Length(), mozilla::fallible))) {
@ -148,17 +74,9 @@ bool SharedMessagePortMessage::FromSharedToMessagesParent(
MOZ_ASSERT(backgroundManager);
for (auto& data : aData) {
MessageData* message = aArray.AppendElement(mozilla::fallible);
if (data->mCloneData) {
ClonedMessageData clonedData;
data->mCloneData->BuildClonedMessageDataForBackgroundParent(
backgroundManager, clonedData);
*message = clonedData;
continue;
}
*message = RefMessageData(data->mRefDataId);
ClonedMessageData* message = aArray.AppendElement(mozilla::fallible);
data->BuildClonedMessageDataForBackgroundParent(backgroundManager,
*message);
}
return true;
@ -166,7 +84,7 @@ bool SharedMessagePortMessage::FromSharedToMessagesParent(
/* static */
bool SharedMessagePortMessage::FromMessagesToSharedParent(
nsTArray<MessageData>& aArray,
nsTArray<ClonedMessageData>& aArray,
FallibleTArray<RefPtr<SharedMessagePortMessage>>& aData) {
MOZ_ASSERT(aData.IsEmpty());
@ -176,15 +94,7 @@ bool SharedMessagePortMessage::FromMessagesToSharedParent(
for (auto& message : aArray) {
RefPtr<SharedMessagePortMessage> data = new SharedMessagePortMessage();
if (message.type() == MessageData::TClonedMessageData) {
data->mCloneData = MakeUnique<ipc::StructuredCloneData>(
JS::StructuredCloneScope::UnknownDestination);
data->mCloneData->StealFromClonedMessageDataForBackgroundParent(message);
} else {
MOZ_ASSERT(message.type() == MessageData::TRefMessageData);
data->mRefDataId = message.get_RefMessageData().uuid();
}
data->StealFromClonedMessageDataForBackgroundParent(message);
if (!aData.AppendElement(data, mozilla::fallible)) {
return false;

View File

@ -15,58 +15,41 @@ namespace dom {
class MessagePortChild;
class MessagePortMessage;
class MessagePortParent;
class RefMessageBody;
class RefMessageBodyService;
class SharedMessagePortMessage final {
class SharedMessagePortMessage final : public ipc::StructuredCloneData {
public:
NS_INLINE_DECL_REFCOUNTING(SharedMessagePortMessage)
SharedMessagePortMessage();
SharedMessagePortMessage() : ipc::StructuredCloneData() {}
// Note that the populated MessageData borrows the underlying
// Note that the populated ClonedMessageData borrows the underlying
// JSStructuredCloneData from the SharedMessagePortMessage, so the caller is
// required to ensure that the MessageData instances are destroyed prior to
// the SharedMessagePortMessage instances.
// required to ensure that the ClonedMessageData instances are destroyed prior
// to the SharedMessagePortMessage instances.
static void FromSharedToMessagesChild(
MessagePortChild* aActor,
const nsTArray<RefPtr<SharedMessagePortMessage>>& aData,
nsTArray<MessageData>& aArray);
nsTArray<ClonedMessageData>& aArray);
static bool FromMessagesToSharedChild(
nsTArray<MessageData>& aArray,
nsTArray<ClonedMessageData>& aArray,
FallibleTArray<RefPtr<SharedMessagePortMessage>>& aData);
// Note that the populated MessageData borrows the underlying
// Note that the populated ClonedMessageData borrows the underlying
// JSStructuredCloneData from the SharedMessagePortMessage, so the caller is
// required to ensure that the MessageData instances are destroyed prior to
// the SharedMessagePortMessage instances.
// required to ensure that the ClonedMessageData instances are destroyed prior
// to the SharedMessagePortMessage instances.
static bool FromSharedToMessagesParent(
MessagePortParent* aActor,
const nsTArray<RefPtr<SharedMessagePortMessage>>& aData,
FallibleTArray<MessageData>& aArray);
FallibleTArray<ClonedMessageData>& aArray);
static bool FromMessagesToSharedParent(
nsTArray<MessageData>& aArray,
nsTArray<ClonedMessageData>& aArray,
FallibleTArray<RefPtr<SharedMessagePortMessage>>& aData);
void Read(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
RefMessageBodyService* aRefMessageBodyService, ErrorResult& aRv);
void Write(JSContext* aCx, JS::Handle<JS::Value> aValue,
JS::Handle<JS::Value> aTransfers, nsID& aPortID,
RefMessageBodyService* aRefMessageBodyService, ErrorResult& aRv);
bool TakeTransferredPortsAsSequence(
Sequence<OwningNonNull<mozilla::dom::MessagePort>>& aPorts);
private:
~SharedMessagePortMessage() = default;
UniquePtr<ipc::StructuredCloneData> mCloneData;
RefPtr<RefMessageBody> mRefData;
nsID mRefDataId;
~SharedMessagePortMessage() {}
};
} // namespace dom

View File

@ -22,7 +22,6 @@ UNIFIED_SOURCES += [
'MessagePortChild.cpp',
'MessagePortParent.cpp',
'MessagePortService.cpp',
'RefMessageBodyService.cpp',
'SharedMessagePortMessage.cpp',
]

View File

@ -30,4 +30,3 @@ skip-if = (os == "win" && processor == "aarch64") #bug 1535784
[test_messageChannel_bug1224825.html]
[test_messageChannel_worker_forceClose.html]
[test_removedWindow.html]
[test_wasm.html]

View File

@ -1,105 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>MessagePort + wasm</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script id='myWorker' type='text/worker'>
self.onmessage = e => {
e.ports[0].onmessage = ee => postMessage(ee.data);
};
</script>
<script type="application/javascript">
let wasmModule;
function create_wasmModule() {
info("Checking if we can play with WebAssembly...");
if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) {
next();
return;
}
ok(WebAssembly, "WebAssembly object should exist");
ok(WebAssembly.compile, "WebAssembly.compile function should exist");
const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary);
const fooModuleCode = wasmTextToBinary(`(module
(func $foo (result i32) (i32.const 42))
(export "foo" $foo)
)`);
WebAssembly.compile(fooModuleCode).then(m => {
ok(m instanceof WebAssembly.Module, "The WasmModule has been compiled.");
wasmModule = m;
next();
}, () => {
ok(false, "The compilation of the wasmModule failed.");
});
}
function test_simple() {
info("MessagePort without disentangling");
if (!wasmModule) {
next();
return;
}
const mc = new MessageChannel();
mc.port1.postMessage({ wasmModule });
mc.port2.onmessage = e => {
ok(e.data.wasmModule instanceof WebAssembly.Module, "WasmModule received");
next();
};
}
function test_worker() {
info("MessagePort sent to a worker");
if (!wasmModule) {
next();
return;
}
const mc = new MessageChannel();
mc.port1.postMessage({ wasmModule });
const blob = new Blob([document.getElementById('myWorker').textContent]);
const w = new Worker(URL.createObjectURL(blob));
w.postMessage(42, [ mc.port2 ]);
w.onmessage = e => {
ok(e.data.wasmModule instanceof WebAssembly.Module, "WasmModule received");
next();
};
}
const tests = [
create_wasmModule,
test_simple,
test_worker,
];
function next() {
if (tests.length === 0) {
SimpleTest.finish();
return;
}
const test = tests.shift();
test();
}
SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>

View File

@ -783,8 +783,7 @@ JSObject* PromiseWorkerProxy::CustomReadHandler(
bool PromiseWorkerProxy::CustomWriteHandler(JSContext* aCx,
JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) {
JS::Handle<JSObject*> aObj) {
if (NS_WARN_IF(!mCallbacks)) {
return false;
}

View File

@ -160,8 +160,7 @@ class PromiseWorkerProxy : public PromiseNativeHandler,
uint32_t aTag, uint32_t aIndex) override;
bool CustomWriteHandler(JSContext* aCx, JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) override;
JS::Handle<JSObject*> aObj) override;
protected:
virtual void ResolvedCallback(JSContext* aCx,

View File

@ -168,14 +168,7 @@ enum class StructuredCloneScope : uint32_t {
* JSStructuredCloneData without knowing the scope, then populate it with
* data (at which point the scope *is* known.)
*/
Unassigned,
/**
* This scope is used when the deserialization context is unknown. When
* writing, DifferentProcess or SameProcess scope is chosen based on the
* nature of the object.
*/
UnknownDestination,
Unassigned
};
enum TransferableOwnership {
@ -255,9 +248,7 @@ typedef JSObject* (*ReadStructuredCloneOp)(JSContext* cx,
*/
typedef bool (*WriteStructuredCloneOp)(JSContext* cx,
JSStructuredCloneWriter* w,
JS::HandleObject obj,
bool* sameProcessScopeRequired,
void* closure);
JS::HandleObject obj, void* closure);
/**
* This is called when JS_WriteStructuredClone is given an invalid transferable.
@ -315,7 +306,6 @@ typedef void (*FreeTransferStructuredCloneOp)(
*/
typedef bool (*CanTransferStructuredCloneOp)(JSContext* cx,
JS::Handle<JSObject*> obj,
bool* sameProcessScopeRequired,
void* closure);
struct JSStructuredCloneCallbacks {
@ -443,26 +433,15 @@ class MOZ_NON_MEMMOVABLE JS_PUBLIC_API JSStructuredCloneData {
return bufList_.Init(0, initialCapacity);
}
JS::StructuredCloneScope scope() const {
if (scope_ == JS::StructuredCloneScope::UnknownDestination) {
return JS::StructuredCloneScope::DifferentProcess;
}
return scope_;
}
JS::StructuredCloneScope scope() const { return scope_; }
void sameProcessScopeRequired() {
if (scope_ == JS::StructuredCloneScope::UnknownDestination) {
scope_ = JS::StructuredCloneScope::SameProcess;
}
}
void initScope(JS::StructuredCloneScope newScope) {
void initScope(JS::StructuredCloneScope scope) {
MOZ_ASSERT(Size() == 0, "initScope() of nonempty JSStructuredCloneData");
if (scope() != JS::StructuredCloneScope::Unassigned) {
MOZ_ASSERT(scope() == newScope,
if (scope_ != JS::StructuredCloneScope::Unassigned) {
MOZ_ASSERT(scope_ == scope,
"Cannot change scope after it has been initialized");
}
scope_ = newScope;
scope_ = scope;
}
size_t Size() const { return bufList_.Size(); }
@ -479,7 +458,7 @@ class MOZ_NON_MEMMOVABLE JS_PUBLIC_API JSStructuredCloneData {
// Append new data to the end of the buffer.
MOZ_MUST_USE bool AppendBytes(const char* data, size_t size) {
MOZ_ASSERT(scope() != JS::StructuredCloneScope::Unassigned);
MOZ_ASSERT(scope_ != JS::StructuredCloneScope::Unassigned);
return bufList_.WriteBytes(data, size);
}
@ -487,7 +466,7 @@ class MOZ_NON_MEMMOVABLE JS_PUBLIC_API JSStructuredCloneData {
// 'size' bytes between the position of 'iter' and the end of the buffer.
MOZ_MUST_USE bool UpdateBytes(Iterator& iter, const char* data,
size_t size) const {
MOZ_ASSERT(scope() != JS::StructuredCloneScope::Unassigned);
MOZ_ASSERT(scope_ != JS::StructuredCloneScope::Unassigned);
while (size > 0) {
size_t remaining = iter.RemainingInSegment();
size_t nbytes = std::min(remaining, size);
@ -514,9 +493,9 @@ class MOZ_NON_MEMMOVABLE JS_PUBLIC_API JSStructuredCloneData {
// clone will do nothing.
JSStructuredCloneData Borrow(Iterator& iter, size_t size,
bool* success) const {
MOZ_ASSERT(scope() == JS::StructuredCloneScope::DifferentProcess);
MOZ_ASSERT(scope_ == JS::StructuredCloneScope::DifferentProcess);
return JSStructuredCloneData(
bufList_.Borrow<js::SystemAllocPolicy>(iter, size, success), scope());
bufList_.Borrow<js::SystemAllocPolicy>(iter, size, success), scope_);
}
// Iterate over all contained data, one BufferList segment's worth at a
@ -537,7 +516,7 @@ class MOZ_NON_MEMMOVABLE JS_PUBLIC_API JSStructuredCloneData {
// Append the entire contents of other's bufList_ to our own.
MOZ_MUST_USE bool Append(const JSStructuredCloneData& other) {
MOZ_ASSERT(scope() == other.scope());
MOZ_ASSERT(scope_ == other.scope());
return other.ForEachDataChunk(
[&](const char* data, size_t size) { return AppendBytes(data, size); });
}
@ -594,6 +573,7 @@ JS_PUBLIC_API bool JS_StructuredClone(
* (serializing and deserializing).
*/
class JS_PUBLIC_API JSAutoStructuredCloneBuffer {
const JS::StructuredCloneScope scope_;
JSStructuredCloneData data_;
uint32_t version_;
@ -601,7 +581,7 @@ class JS_PUBLIC_API JSAutoStructuredCloneBuffer {
JSAutoStructuredCloneBuffer(JS::StructuredCloneScope scope,
const JSStructuredCloneCallbacks* callbacks,
void* closure)
: data_(scope), version_(JS_STRUCTURED_CLONE_VERSION) {
: scope_(scope), data_(scope), version_(JS_STRUCTURED_CLONE_VERSION) {
data_.setCallbacks(callbacks, closure,
OwnTransferablePolicy::NoTransferables);
}
@ -616,7 +596,7 @@ class JS_PUBLIC_API JSAutoStructuredCloneBuffer {
void clear();
JS::StructuredCloneScope scope() const { return data_.scope(); }
JS::StructuredCloneScope scope() const { return scope_; }
/**
* Adopt some memory. It will be automatically freed by the destructor.

View File

@ -309,7 +309,6 @@ struct SCOutput {
JSContext* context() const { return cx; }
JS::StructuredCloneScope scope() const { return buf.scope(); }
void sameProcessScopeRequired() { buf.sameProcessScopeRequired(); }
MOZ_MUST_USE bool write(uint64_t u);
MOZ_MUST_USE bool writePair(uint32_t tag, uint32_t data);
@ -916,7 +915,7 @@ void JSStructuredCloneData::discardTransferables() {
// DifferentProcess clones cannot contain pointers, so nothing needs to be
// released.
if (scope() == JS::StructuredCloneScope::DifferentProcess) {
if (scope_ == JS::StructuredCloneScope::DifferentProcess) {
return;
}
@ -1102,15 +1101,10 @@ bool JSStructuredCloneWriter::parseTransferable() {
}
JSAutoRealm ar(cx, unwrappedObj);
bool sameProcessScopeRequired = false;
if (!out.buf.callbacks_->canTransfer(
cx, unwrappedObj, &sameProcessScopeRequired, out.buf.closure_)) {
if (!out.buf.callbacks_->canTransfer(cx, unwrappedObj,
out.buf.closure_)) {
return false;
}
if (sameProcessScopeRequired) {
output().sameProcessScopeRequired();
}
}
// No duplicates allowed
@ -1269,8 +1263,6 @@ bool JSStructuredCloneWriter::writeSharedArrayBuffer(HandleObject obj) {
return false;
}
output().sameProcessScopeRequired();
// We must not transmit SAB pointers (including for WebAssembly.Memory)
// cross-process. The cloneDataPolicy should have guarded against this;
// since it did not then throw, with a very explicit message.
@ -1750,18 +1742,7 @@ bool JSStructuredCloneWriter::startWrite(HandleValue v) {
}
if (out.buf.callbacks_ && out.buf.callbacks_->write) {
bool sameProcessScopeRequired = false;
if (!out.buf.callbacks_->write(context(), this, obj,
&sameProcessScopeRequired,
out.buf.closure_)) {
return false;
}
if (sameProcessScopeRequired) {
output().sameProcessScopeRequired();
}
return true;
return out.buf.callbacks_->write(context(), this, obj, out.buf.closure_);
}
// else fall through
}
@ -3136,7 +3117,7 @@ JS_PUBLIC_API bool JS_StructuredClone(
JSAutoStructuredCloneBuffer::JSAutoStructuredCloneBuffer(
JSAutoStructuredCloneBuffer&& other)
: data_(other.scope()) {
: scope_(other.scope()), data_(other.scope()) {
data_.ownTransferables_ = other.data_.ownTransferables_;
other.steal(&data_, &version_, &data_.callbacks_, &data_.closure_);
}
@ -3144,7 +3125,7 @@ JSAutoStructuredCloneBuffer::JSAutoStructuredCloneBuffer(
JSAutoStructuredCloneBuffer& JSAutoStructuredCloneBuffer::operator=(
JSAutoStructuredCloneBuffer&& other) {
MOZ_ASSERT(&other != this);
MOZ_ASSERT(scope() == other.scope());
MOZ_ASSERT(scope_ == other.scope_);
clear();
data_.ownTransferables_ = other.data_.ownTransferables_;
other.steal(&data_, &version_, &data_.callbacks_, &data_.closure_);
@ -3191,7 +3172,7 @@ bool JSAutoStructuredCloneBuffer::read(
JSContext* cx, MutableHandleValue vp, JS::CloneDataPolicy cloneDataPolicy,
const JSStructuredCloneCallbacks* optionalCallbacks, void* closure) {
MOZ_ASSERT(cx);
return !!JS_ReadStructuredClone(cx, data_, version_, data_.scope(), vp,
return !!JS_ReadStructuredClone(cx, data_, version_, scope_, vp,
cloneDataPolicy, optionalCallbacks, closure);
}
@ -3208,9 +3189,8 @@ bool JSAutoStructuredCloneBuffer::write(
JS::CloneDataPolicy cloneDataPolicy,
const JSStructuredCloneCallbacks* optionalCallbacks, void* closure) {
clear();
bool ok =
JS_WriteStructuredClone(cx, value, &data_, data_.scope(), cloneDataPolicy,
optionalCallbacks, closure, transferable);
bool ok = JS_WriteStructuredClone(cx, value, &data_, scope_, cloneDataPolicy,
optionalCallbacks, closure, transferable);
if (ok) {
data_.ownTransferables_ = OwnTransferablePolicy::OwnsTransferablesIfAny;

View File

@ -133,8 +133,7 @@ class MOZ_STACK_CLASS StackScopedCloneData : public StructuredCloneHolderBase {
}
bool CustomWriteHandler(JSContext* aCx, JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj,
bool* aSameProcessScopeRequired) override {
JS::Handle<JSObject*> aObj) override {
{
JS::Rooted<JSObject*> obj(aCx, aObj);
Blob* blob = nullptr;

View File

@ -0,0 +1,3 @@
[window-messagechannel-success.html]
[postMessaging to a dedicated worker via MessageChannel allows them to instantiate]
expected: FAIL

View File

@ -1,2 +1,4 @@
[window-sharedworker-failure.html]
disabled: https://bugzilla.mozilla.org/show_bug.cgi?id=1609990
[WebAssembly.Modules cannot cross agent clusters, shared worker edition]
expected: FAIL

View File

@ -0,0 +1,31 @@
[shared.html]
[Array ImageBitmap object, ImageBitmap 1x1 transparent non-black]
expected:
if (os == "win") and (processor == "x86_64") and not debug: ["FAIL", "PASS"]
FAIL
[Array ImageBitmap object, ImageBitmap 1x1 transparent black]
expected:
if (os == "win") and (processor == "x86_64") and not debug: ["FAIL", "PASS"]
FAIL
[ImageBitmap 1x1 non-transparent non-black]
expected:
if (os == "win") and (processor == "x86_64") and not debug: ["FAIL", "PASS"]
FAIL
[Object ImageBitmap object, ImageBitmap 1x1 transparent non-black]
expected:
if (os == "win") and (processor == "x86_64") and not debug: ["FAIL", "PASS"]
FAIL
[ImageBitmap 1x1 transparent black]
expected:
if (os == "win") and (processor == "x86_64") and not debug: ["FAIL", "PASS"]
FAIL
[Object ImageBitmap object, ImageBitmap 1x1 transparent black]
expected:
if (os == "win") and (processor == "x86_64") and not debug: ["FAIL", "PASS"]
FAIL

View File

@ -69,8 +69,7 @@ class StructuredCloneData;
namespace mozilla {
namespace dom {
class ClonedMessageData;
class MessageData;
class RefMessageData;
class MessagePortMessage;
namespace indexedDB {
struct StructuredCloneReadInfo;
class SerializedStructuredCloneReadInfo;
@ -722,8 +721,7 @@ DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::indexedDB::IndexCursorResponse)
DECLARE_USE_COPY_CONSTRUCTORS(
mozilla::dom::indexedDB::SerializedStructuredCloneReadInfo);
DECLARE_USE_COPY_CONSTRUCTORS(JSStructuredCloneData)
DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::MessageData)
DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::RefMessageData)
DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::MessagePortMessage)
DECLARE_USE_COPY_CONSTRUCTORS(mozilla::SourceBufferTask)
//