From 0e3826d472a45471c395c1118e34d6eba9b466f6 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Tue, 24 Jan 2023 11:32:21 +0000 Subject: [PATCH] Bug 1811868 - Move Stream() to ReadableStreamController r=evilpie Differential Revision: https://phabricator.services.mozilla.com/D167572 --- dom/base/BodyStream.cpp | 4 +- dom/streams/ReadableByteStreamController.cpp | 4 +- dom/streams/ReadableByteStreamController.h | 5 --- dom/streams/ReadableStreamController.h | 10 ++++- .../ReadableStreamDefaultController.cpp | 37 +++++++++++-------- dom/streams/ReadableStreamDefaultController.h | 4 -- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/dom/base/BodyStream.cpp b/dom/base/BodyStream.cpp index c0eb76cadf39..338b48b90d7d 100644 --- a/dom/base/BodyStream.cpp +++ b/dom/base/BodyStream.cpp @@ -205,12 +205,10 @@ void BodyStream::Create(JSContext* aCx, BodyStreamHolder* aStreamHolder, already_AddRefed BodyStream::PullCallback( JSContext* aCx, ReadableStreamController& aController, ErrorResult& aRv) { MOZ_ASSERT(aController.IsByte()); - ReadableStream* stream = aController.AsByte()->Stream(); + ReadableStream* stream = aController.Stream(); MOZ_ASSERT(stream); -#if MOZ_DIAGNOSTIC_ASSERT_ENABLED MOZ_DIAGNOSTIC_ASSERT(stream->Disturbed()); -#endif AssertIsOnOwningThread(); diff --git a/dom/streams/ReadableByteStreamController.cpp b/dom/streams/ReadableByteStreamController.cpp index 88bfecf744ba..4645293dc7e7 100644 --- a/dom/streams/ReadableByteStreamController.cpp +++ b/dom/streams/ReadableByteStreamController.cpp @@ -44,7 +44,7 @@ namespace mozilla::dom { NS_IMPL_CYCLE_COLLECTION_CLASS(ReadableByteStreamController) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ReadableByteStreamController, ReadableStreamController) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mByobRequest, mStream) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mByobRequest) tmp->ClearPendingPullIntos(); tmp->ClearQueue(); NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER @@ -52,7 +52,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ReadableByteStreamController, ReadableStreamController) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mByobRequest, mStream) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mByobRequest) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(ReadableByteStreamController, diff --git a/dom/streams/ReadableByteStreamController.h b/dom/streams/ReadableByteStreamController.h index 9b62dc547ec0..bfba2e34871d 100644 --- a/dom/streams/ReadableByteStreamController.h +++ b/dom/streams/ReadableByteStreamController.h @@ -95,9 +95,6 @@ class ReadableByteStreamController final : public ReadableStreamController, } void ClearPendingPullIntos(); - ReadableStream* Stream() const { return mStream; } - void SetStream(ReadableStream* aStream) { mStream = aStream; } - double QueueTotalSize() const { return mQueueTotalSize; } void SetQueueTotalSize(double aQueueTotalSize) { mQueueTotalSize = aQueueTotalSize; @@ -172,8 +169,6 @@ class ReadableByteStreamController final : public ReadableStreamController, // strategy, indicating the point at which the stream will apply backpressure // to its underlying byte source double mStrategyHWM = 0.0; - - RefPtr mStream; }; // https://streams.spec.whatwg.org/#readable-byte-stream-queue-entry diff --git a/dom/streams/ReadableStreamController.h b/dom/streams/ReadableStreamController.h index 013147d56aad..766c93301766 100644 --- a/dom/streams/ReadableStreamController.h +++ b/dom/streams/ReadableStreamController.h @@ -15,6 +15,7 @@ namespace mozilla::dom { struct ReadRequest; +class ReadableStream; class ReadableStreamDefaultController; class ReadableByteStreamController; @@ -23,7 +24,7 @@ class ReadableStreamController : public nsISupports { NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_CLASS(ReadableStreamController) - ReadableStreamController(nsIGlobalObject* aGlobal) : mGlobal(aGlobal) {} + ReadableStreamController(nsIGlobalObject* aGlobal); nsIGlobalObject* GetParentObject() const { return mGlobal; } @@ -43,7 +44,7 @@ class ReadableStreamController : public nsISupports { // No JS implementable UnderlyingSource callback exists for this. virtual void ReleaseSteps() = 0; - UnderlyingSourceAlgorithmsBase* GetAlgorithms() { return mAlgorithms; } + UnderlyingSourceAlgorithmsBase* GetAlgorithms() const { return mAlgorithms; } void SetAlgorithms(UnderlyingSourceAlgorithmsBase& aAlgorithms) { mAlgorithms = &aAlgorithms; } @@ -53,12 +54,17 @@ class ReadableStreamController : public nsISupports { mAlgorithms = nullptr; } + ReadableStream* Stream() const { return mStream; } + void SetStream(ReadableStream* aStream); + protected: nsCOMPtr mGlobal; // The algorithms for the underlying source RefPtr mAlgorithms; + RefPtr mStream; + virtual ~ReadableStreamController() = default; }; diff --git a/dom/streams/ReadableStreamDefaultController.cpp b/dom/streams/ReadableStreamDefaultController.cpp index 7c106e076c2c..dda3ec75fc21 100644 --- a/dom/streams/ReadableStreamDefaultController.cpp +++ b/dom/streams/ReadableStreamDefaultController.cpp @@ -24,7 +24,8 @@ namespace mozilla::dom { -NS_IMPL_CYCLE_COLLECTION(ReadableStreamController, mGlobal, mAlgorithms) +NS_IMPL_CYCLE_COLLECTION(ReadableStreamController, mGlobal, mAlgorithms, + mStream) NS_IMPL_CYCLE_COLLECTING_ADDREF(ReadableStreamController) NS_IMPL_CYCLE_COLLECTING_RELEASE(ReadableStreamController) @@ -32,20 +33,28 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ReadableStreamController) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END +ReadableStreamController::ReadableStreamController(nsIGlobalObject* aGlobal) + : mGlobal(aGlobal) {} + +void ReadableStreamController::SetStream(ReadableStream* aStream) { + mStream = aStream; +} + // Note: Using the individual macros vs NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE -// because I need to specificy a manual implementation of +// because I need to specify a manual implementation of // NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN. NS_IMPL_CYCLE_COLLECTION_CLASS(ReadableStreamDefaultController) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ReadableStreamDefaultController) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mStrategySizeAlgorithm, mStream) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ReadableStreamDefaultController, + ReadableStreamController) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mStrategySizeAlgorithm) tmp->mQueue.clear(); NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED( ReadableStreamDefaultController, ReadableStreamController) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStrategySizeAlgorithm, mStream) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStrategySizeAlgorithm) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(ReadableStreamDefaultController, @@ -87,15 +96,11 @@ JSObject* ReadableStreamDefaultController::WrapObject( return ReadableStreamDefaultController_Binding::Wrap(aCx, this, aGivenProto); } -void ReadableStreamDefaultController::SetStream(ReadableStream* aStream) { - mStream = aStream; -} - // https://streams.spec.whatwg.org/#readable-stream-default-controller-can-close-or-enqueue static bool ReadableStreamDefaultControllerCanCloseOrEnqueue( ReadableStreamDefaultController* aController) { // Step 1. Let state be controller.[[stream]].[[state]]. - ReadableStream::ReaderState state = aController->GetStream()->State(); + ReadableStream::ReaderState state = aController->Stream()->State(); // Step 2. If controller.[[closeRequested]] is false and state is "readable", // return true. @@ -112,7 +117,7 @@ bool ReadableStreamDefaultControllerCanCloseOrEnqueueAndThrow( ReadableStreamDefaultController* aController, CloseOrEnqueue aCloseOrEnqueue, ErrorResult& aRv) { // Step 1. Let state be controller.[[stream]].[[state]]. - ReadableStream::ReaderState state = aController->GetStream()->State(); + ReadableStream::ReaderState state = aController->Stream()->State(); nsCString prefix; if (aCloseOrEnqueue == CloseOrEnqueue::Close) { @@ -152,7 +157,7 @@ bool ReadableStreamDefaultControllerCanCloseOrEnqueueAndThrow( Nullable ReadableStreamDefaultControllerGetDesiredSize( ReadableStreamDefaultController* aController) { - ReadableStream::ReaderState state = aController->GetStream()->State(); + ReadableStream::ReaderState state = aController->Stream()->State(); if (state == ReadableStream::ReaderState::Errored) { return nullptr; } @@ -201,7 +206,7 @@ void ReadableStreamDefaultControllerClose( } // Step 2. - RefPtr stream = aController->GetStream(); + RefPtr stream = aController->Stream(); // Step 3. aController->SetCloseRequested(true); @@ -242,7 +247,7 @@ void ReadableStreamDefaultControllerEnqueue( } // Step 2. - RefPtr stream = aController->GetStream(); + RefPtr stream = aController->Stream(); // Step 3. if (IsReadableStreamLocked(stream) && @@ -347,7 +352,7 @@ void ReadableStreamDefaultController::Error(JSContext* aCx, bool ReadableStreamDefaultControllerShouldCallPull( ReadableStreamDefaultController* aController) { // Step 1. - ReadableStream* stream = aController->GetStream(); + ReadableStream* stream = aController->Stream(); // Step 2. if (!ReadableStreamDefaultControllerCanCloseOrEnqueue(aController)) { @@ -381,7 +386,7 @@ void ReadableStreamDefaultControllerError( JSContext* aCx, ReadableStreamDefaultController* aController, JS::Handle aValue, ErrorResult& aRv) { // Step 1. - ReadableStream* stream = aController->GetStream(); + ReadableStream* stream = aController->Stream(); // Step 2. if (stream->State() != ReadableStream::ReaderState::Readable) { diff --git a/dom/streams/ReadableStreamDefaultController.h b/dom/streams/ReadableStreamDefaultController.h index aff44662041e..b19c9478ea74 100644 --- a/dom/streams/ReadableStreamDefaultController.h +++ b/dom/streams/ReadableStreamDefaultController.h @@ -101,9 +101,6 @@ class ReadableStreamDefaultController final : public ReadableStreamController, mStrategySizeAlgorithm = aStrategySizeAlgorithm; } - ReadableStream* GetStream() { return mStream; } - void SetStream(ReadableStream* aStream); - private: // Internal Slots: bool mCloseRequested = false; @@ -114,7 +111,6 @@ class ReadableStreamDefaultController final : public ReadableStreamController, bool mStarted = false; double mStrategyHWM = false; RefPtr mStrategySizeAlgorithm; - RefPtr mStream; }; MOZ_CAN_RUN_SCRIPT void SetUpReadableStreamDefaultController(