From b1a12de924e0ddbca221b6ee2ae37e2c065f488c Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Fri, 29 Sep 2023 09:25:52 -0500 Subject: [PATCH] Issue #1442 - Part 20 - FetchStream should not have an extra JS::Heap. https://bugzilla.mozilla.org/show_bug.cgi?id=1390717 --- dom/fetch/Fetch.h | 9 +++++++++ dom/fetch/FetchStream.cpp | 7 ++----- dom/fetch/FetchStream.h | 2 -- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dom/fetch/Fetch.h b/dom/fetch/Fetch.h index 7b52dfdc62..0dcf1d859c 100644 --- a/dom/fetch/Fetch.h +++ b/dom/fetch/Fetch.h @@ -100,6 +100,8 @@ public: NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0; virtual void NullifyStream() = 0; + + virtual JSObject* ReadableStreamBody() = 0; }; /* @@ -228,6 +230,13 @@ public: mFetchStreamReader = nullptr; } + JSObject* + ReadableStreamBody() override + { + MOZ_ASSERT(mReadableStreamBody); + return mReadableStreamBody; + } + virtual AbortSignal* GetSignal() const = 0; diff --git a/dom/fetch/FetchStream.cpp b/dom/fetch/FetchStream.cpp index ec224e1c8d..63e6f150b9 100644 --- a/dom/fetch/FetchStream.cpp +++ b/dom/fetch/FetchStream.cpp @@ -161,8 +161,6 @@ FetchStream::Create(JSContext* aCx, FetchStreamHolder* aStreamHolder, return; } - stream->mReadableStream = body; - // This will be released in FetchStream::FinalizeCallback(). We are // guaranteed the jsapi will call FinalizeCallback when ReadableStream // js object is finalized. @@ -371,7 +369,6 @@ FetchStream::FetchStream(nsIGlobalObject* aGlobal, , mStreamHolder(aStreamHolder) , mOriginalInputStream(aInputStream) , mOwningEventTarget(nullptr) - , mReadableStream(nullptr) { MOZ_DIAGNOSTIC_ASSERT(aInputStream); MOZ_DIAGNOSTIC_ASSERT(aStreamHolder); @@ -428,7 +425,7 @@ FetchStream::OnInputStreamReady(nsIAsyncInputStream* aStream) } JSContext* cx = jsapi.cx(); - JS::Rooted stream(cx, mReadableStream); + JS::Rooted stream(cx, mStreamHolder->ReadableStreamBody()); uint64_t size = 0; nsresult rv = mInputStream->Available(&size); @@ -494,7 +491,7 @@ FetchStream::Close() } JSContext* cx = jsapi.cx(); - JS::Rooted stream(cx, mReadableStream); + JS::Rooted stream(cx, mStreamHolder->ReadableStreamBody()); CloseAndReleaseObjects(cx, stream); } diff --git a/dom/fetch/FetchStream.h b/dom/fetch/FetchStream.h index 4562b3f351..80d120616d 100644 --- a/dom/fetch/FetchStream.h +++ b/dom/fetch/FetchStream.h @@ -125,8 +125,6 @@ private: nsCOMPtr mInputStream; UniquePtr mWorkerHolder; - - JS::Heap mReadableStream; }; } // dom namespace