Bug 1811868 - Move Stream() to ReadableStreamController r=evilpie

Differential Revision: https://phabricator.services.mozilla.com/D167572
This commit is contained in:
Kagami Sascha Rosylight 2023-01-24 11:32:21 +00:00
parent 4fa60b3b58
commit 0e3826d472
6 changed files with 32 additions and 32 deletions

View File

@ -205,12 +205,10 @@ void BodyStream::Create(JSContext* aCx, BodyStreamHolder* aStreamHolder,
already_AddRefed<Promise> 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();

View File

@ -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,

View File

@ -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<ReadableStream> mStream;
};
// https://streams.spec.whatwg.org/#readable-byte-stream-queue-entry

View File

@ -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<nsIGlobalObject> mGlobal;
// The algorithms for the underlying source
RefPtr<UnderlyingSourceAlgorithmsBase> mAlgorithms;
RefPtr<ReadableStream> mStream;
virtual ~ReadableStreamController() = default;
};

View File

@ -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<double> 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<ReadableStream> stream = aController->GetStream();
RefPtr<ReadableStream> stream = aController->Stream();
// Step 3.
aController->SetCloseRequested(true);
@ -242,7 +247,7 @@ void ReadableStreamDefaultControllerEnqueue(
}
// Step 2.
RefPtr<ReadableStream> stream = aController->GetStream();
RefPtr<ReadableStream> 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<JS::Value> aValue, ErrorResult& aRv) {
// Step 1.
ReadableStream* stream = aController->GetStream();
ReadableStream* stream = aController->Stream();
// Step 2.
if (stream->State() != ReadableStream::ReaderState::Readable) {

View File

@ -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<QueuingStrategySize> mStrategySizeAlgorithm;
RefPtr<ReadableStream> mStream;
};
MOZ_CAN_RUN_SCRIPT void SetUpReadableStreamDefaultController(