зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1803386 - Part 1: Replace ReadableStream::mNativeUnderlyingSource with GetBodyStreamHolder() r=smaug
The underlying source algorithms class already has strong ref, so just use it. Differential Revision: https://phabricator.services.mozilla.com/D166533
This commit is contained in:
Родитель
7b3591fa19
Коммит
ac006ba3c4
|
@ -1194,7 +1194,7 @@ void FetchBody<Derived>::SetBodyUsed(JSContext* aCx, ErrorResult& aRv) {
|
|||
// If we already have a ReadableStreamBody and it has been created by DOM, we
|
||||
// have to lock it now because it can have been shared with other objects.
|
||||
if (mReadableStreamBody) {
|
||||
if (mReadableStreamBody->HasNativeUnderlyingSource()) {
|
||||
if (mReadableStreamBody->GetBodyStreamHolder()) {
|
||||
LockStream(aCx, mReadableStreamBody, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
|
@ -1500,7 +1500,7 @@ void FetchBody<Derived>::MaybeTeeReadableStreamBody(
|
|||
// If this is a ReadableStream with an native source, this has been
|
||||
// generated by a Fetch. In this case, Fetch will be able to recreate it
|
||||
// again when GetBody() is called.
|
||||
if (mReadableStreamBody->HasNativeUnderlyingSource()) {
|
||||
if (mReadableStreamBody->GetBodyStreamHolder()) {
|
||||
*aBodyOut = nullptr;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -293,11 +293,8 @@ already_AddRefed<Response> Response::Constructor(
|
|||
|
||||
// If this is a DOM generated ReadableStream, we can extract the
|
||||
// inputStream directly.
|
||||
if (readableStream.HasNativeUnderlyingSource()) {
|
||||
BodyStreamHolder* underlyingSource =
|
||||
readableStream.GetNativeUnderlyingSource();
|
||||
MOZ_ASSERT(underlyingSource);
|
||||
|
||||
if (BodyStreamHolder* underlyingSource =
|
||||
readableStream.GetBodyStreamHolder()) {
|
||||
aRv = BodyStream::RetrieveInputStream(underlyingSource,
|
||||
getter_AddRefs(bodyStream));
|
||||
|
||||
|
|
|
@ -140,6 +140,8 @@ class BodyStreamUnderlyingSourceAlgorithms final
|
|||
bodyStream->CloseInputAndReleaseObjects();
|
||||
}
|
||||
|
||||
BodyStreamHolder* GetBodyStreamHolder() override { return mUnderlyingSource; }
|
||||
|
||||
protected:
|
||||
~BodyStreamUnderlyingSourceAlgorithms() override = default;
|
||||
|
||||
|
|
|
@ -71,8 +71,7 @@ namespace mozilla::dom {
|
|||
|
||||
// Only needed for refcounted objects.
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS(
|
||||
ReadableStream, (mGlobal, mController, mReader, mNativeUnderlyingSource),
|
||||
(mStoredError))
|
||||
ReadableStream, (mGlobal, mController, mReader), (mStoredError))
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ReadableStream)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(ReadableStream)
|
||||
|
@ -136,14 +135,7 @@ bool ReadableStreamHasDefaultReader(ReadableStream* aStream) {
|
|||
return reader->IsDefault();
|
||||
}
|
||||
|
||||
void ReadableStream::SetNativeUnderlyingSource(
|
||||
BodyStreamHolder* aUnderlyingSource) {
|
||||
mNativeUnderlyingSource = aUnderlyingSource;
|
||||
}
|
||||
|
||||
void ReadableStream::ReleaseObjectsFromBodyStream() {
|
||||
SetNativeUnderlyingSource(nullptr);
|
||||
|
||||
// XXX(krosylight): Hacky way to workaround the ownership issue between
|
||||
// BodyStream and ReadableStream trying to cleanup each other. See bug
|
||||
// 1803386.
|
||||
|
@ -1024,8 +1016,6 @@ already_AddRefed<ReadableStream> ReadableStream::Create(
|
|||
BodyStreamHolder* aUnderlyingSource, ErrorResult& aRv) {
|
||||
RefPtr<ReadableStream> stream = new ReadableStream(aGlobal);
|
||||
|
||||
stream->SetNativeUnderlyingSource(aUnderlyingSource);
|
||||
|
||||
SetUpReadableByteStreamControllerFromBodyStreamUnderlyingSource(
|
||||
aCx, stream, aUnderlyingSource, aRv);
|
||||
|
||||
|
|
|
@ -86,11 +86,13 @@ class ReadableStream : public nsISupports, public nsWrapperCache {
|
|||
mStoredError = aStoredError;
|
||||
}
|
||||
|
||||
void SetNativeUnderlyingSource(BodyStreamHolder* aUnderlyingSource);
|
||||
BodyStreamHolder* GetNativeUnderlyingSource() {
|
||||
return mNativeUnderlyingSource;
|
||||
BodyStreamHolder* GetBodyStreamHolder() {
|
||||
if (UnderlyingSourceAlgorithmsBase* algorithms =
|
||||
Controller()->GetAlgorithms()) {
|
||||
return algorithms->GetBodyStreamHolder();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
bool HasNativeUnderlyingSource() { return mNativeUnderlyingSource; }
|
||||
|
||||
// XXX(krosylight): BodyStream should really be a subclass of ReadableStream
|
||||
// instead of owning ReadableStream this way. See bug 1803386.
|
||||
|
@ -168,23 +170,6 @@ class ReadableStream : public nsISupports, public nsWrapperCache {
|
|||
RefPtr<ReadableStreamGenericReader> mReader;
|
||||
ReaderState mState = ReaderState::Readable;
|
||||
JS::Heap<JS::Value> mStoredError;
|
||||
|
||||
// Optional strong reference to an Underlying Source; This
|
||||
// exists because NativeUnderlyingSource callbacks don't hold
|
||||
// a strong reference to the underlying source: So we need
|
||||
// something else to hold onto that. As well, some of the integration
|
||||
// desires the ability to extract the underlying source from the
|
||||
// ReadableStream.
|
||||
//
|
||||
// While theoretically this ought to be some base class type to support
|
||||
// multiple native underlying source types, I'm not sure what base class
|
||||
// makes any sense for BodyStream, and given there's only body streams
|
||||
// as the underlying source right now, I'm going to punt that problem to
|
||||
// the future where we need to provide other native underlying sources
|
||||
// (i.e. perhaps WebTransport.)
|
||||
//
|
||||
// See bug 1803386.
|
||||
RefPtr<BodyStreamHolder> mNativeUnderlyingSource;
|
||||
};
|
||||
|
||||
bool IsReadableStreamLocked(ReadableStream* aStream);
|
||||
|
|
|
@ -52,6 +52,9 @@ class UnderlyingSourceAlgorithmsBase : public nsISupports {
|
|||
// from closed(canceled)/errored streams, without waiting for GC.
|
||||
virtual void ReleaseObjects() {}
|
||||
|
||||
// Fetch wants to special-case BodyStream-based streams
|
||||
virtual BodyStreamHolder* GetBodyStreamHolder() { return nullptr; }
|
||||
|
||||
protected:
|
||||
virtual ~UnderlyingSourceAlgorithmsBase() = default;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче