diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index 141e7c3043..99e26e8511 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -877,22 +877,27 @@ ExtractByteStreamFromBody(const fetch::ResponseBodyInit& aBodyInit, template -FetchBody::FetchBody() +FetchBody::FetchBody(nsIGlobalObject* aOwner) : mWorkerPrivate(nullptr) + , mOwner(aOwner) , mReadableStreamBody(nullptr) , mBodyUsed(false) { + MOZ_ASSERT(aOwner); + if (!NS_IsMainThread()) { mWorkerPrivate = GetCurrentThreadWorkerPrivate(); MOZ_ASSERT(mWorkerPrivate); + } else { + mWorkerPrivate = nullptr; } } template -FetchBody::FetchBody(); +FetchBody::FetchBody(nsIGlobalObject* aOwner); template -FetchBody::FetchBody(); +FetchBody::FetchBody(nsIGlobalObject* aOwner); template FetchBody::~FetchBody() diff --git a/dom/fetch/Fetch.h b/dom/fetch/Fetch.h index d3a7ac598e..b16dac3bf1 100644 --- a/dom/fetch/Fetch.h +++ b/dom/fetch/Fetch.h @@ -20,6 +20,7 @@ #include "mozilla/dom/RequestBinding.h" class nsIGlobalObject; +class nsIEventTarget; namespace mozilla { namespace dom { @@ -208,7 +209,9 @@ public: GetSignal() const = 0; protected: - FetchBody(); + nsCOMPtr mOwner; + + explicit FetchBody(nsIGlobalObject* aOwner); // Always set whenever the FetchBody is created on the worker thread. workers::WorkerPrivate* mWorkerPrivate; @@ -252,6 +255,9 @@ private: // Only ever set once, always on target thread. bool mBodyUsed; nsCString mMimeType; + + // The main-thread event target for runnable dispatching. + nsCOMPtr mMainThreadEventTarget; }; } // namespace dom diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index 03df3021c5..eec4828131 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -54,8 +54,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Request) NS_INTERFACE_MAP_END Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest, AbortSignal* aSignal) - : FetchBody() - , mOwner(aOwner) + : FetchBody(aOwner) , mRequest(aRequest) , mSignal(aSignal) { diff --git a/dom/fetch/Request.h b/dom/fetch/Request.h index 8a22f1340b..d5fc09fe25 100644 --- a/dom/fetch/Request.h +++ b/dom/fetch/Request.h @@ -164,7 +164,6 @@ public: private: ~Request(); - nsCOMPtr mOwner; RefPtr mRequest; // Lazily created. diff --git a/dom/fetch/Response.cpp b/dom/fetch/Response.cpp index d69a199076..b92e918e7c 100644 --- a/dom/fetch/Response.cpp +++ b/dom/fetch/Response.cpp @@ -57,8 +57,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Response) NS_INTERFACE_MAP_END Response::Response(nsIGlobalObject* aGlobal, InternalResponse* aInternalResponse, AbortSignal* aSignal) - : FetchBody() - , mOwner(aGlobal) + : FetchBody(aGlobal) , mInternalResponse(aInternalResponse) , mSignal(aSignal) { diff --git a/dom/fetch/Response.h b/dom/fetch/Response.h index 9b29dff998..d2f885fbc7 100644 --- a/dom/fetch/Response.h +++ b/dom/fetch/Response.h @@ -144,7 +144,6 @@ public: private: ~Response(); - nsCOMPtr mOwner; RefPtr mInternalResponse; // Lazily created