mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 15:28:39 +09:00
Issue #1442 - Part 13 - Implement FetchStreamReader. https://bugzilla.mozilla.org/show_bug.cgi?id=1329298
This commit is contained in:
parent
0b450a3def
commit
ef550b2579
10 changed files with 569 additions and 62 deletions
|
|
@ -881,6 +881,7 @@ FetchBody<Derived>::FetchBody(nsIGlobalObject* aOwner)
|
|||
: mWorkerPrivate(nullptr)
|
||||
, mOwner(aOwner)
|
||||
, mReadableStreamBody(nullptr)
|
||||
, mReadableStreamReader(nullptr)
|
||||
, mBodyUsed(false)
|
||||
{
|
||||
MOZ_ASSERT(aOwner);
|
||||
|
|
@ -904,6 +905,12 @@ FetchBody<Derived>::~FetchBody()
|
|||
{
|
||||
}
|
||||
|
||||
template
|
||||
FetchBody<Request>::~FetchBody();
|
||||
|
||||
template
|
||||
FetchBody<Response>::~FetchBody();
|
||||
|
||||
template <class Derived>
|
||||
bool
|
||||
FetchBody<Derived>::BodyUsed() const
|
||||
|
|
@ -958,13 +965,27 @@ FetchBody<Derived>::ConsumeBody(JSContext* aCx, FetchConsumeType aType, ErrorRes
|
|||
|
||||
SetBodyUsed();
|
||||
|
||||
// If we already created a ReadableStreamBody we have to lock it now because
|
||||
// it may have been shared with other objects..
|
||||
// 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) {
|
||||
JS::Rooted<JSObject*> body(aCx, mReadableStreamBody);
|
||||
LockStream(aCx, body, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
JS::Rooted<JSObject*> readableStreamObj(aCx, mReadableStreamBody);
|
||||
if (JS::ReadableStreamGetMode(readableStreamObj) ==
|
||||
JS::ReadableStreamMode::ExternalSource) {
|
||||
LockStream(aCx, readableStreamObj, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
// If this is not a native ReadableStream, let's activate the
|
||||
// FetchStreamReader.
|
||||
MOZ_ASSERT(mFetchStreamReader);
|
||||
JS::Rooted<JSObject*> reader(aCx);
|
||||
mFetchStreamReader->StartConsuming(aCx, readableStreamObj, &reader, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mReadableStreamReader = reader;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1038,6 +1059,11 @@ FetchBody<Derived>::GetBody(JSContext* aCx,
|
|||
JS::MutableHandle<JSObject*> aBodyOut,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (mReadableStreamBody) {
|
||||
aBodyOut.set(mReadableStreamBody);
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
DerivedClass()->GetBody(getter_AddRefs(inputStream));
|
||||
|
||||
|
|
@ -1046,30 +1072,27 @@ FetchBody<Derived>::GetBody(JSContext* aCx,
|
|||
return;
|
||||
}
|
||||
|
||||
if (!mReadableStreamBody) {
|
||||
JS::Rooted<JSObject*> body(aCx,
|
||||
FetchStream::Create(aCx,
|
||||
this,
|
||||
DerivedClass()->GetParentObject(),
|
||||
inputStream,
|
||||
aRv));
|
||||
JS::Rooted<JSObject*> body(aCx,
|
||||
FetchStream::Create(aCx,
|
||||
this,
|
||||
DerivedClass()->GetParentObject(),
|
||||
inputStream,
|
||||
aRv));
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(body);
|
||||
|
||||
// If the body has been already consumed, we lock the stream.
|
||||
if (BodyUsed()) {
|
||||
LockStream(aCx, body, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(body);
|
||||
|
||||
// If the body has been already consumed, we close the stream.
|
||||
if (BodyUsed()) {
|
||||
LockStream(aCx, body, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mReadableStreamBody = body;
|
||||
}
|
||||
|
||||
mReadableStreamBody = body;
|
||||
aBodyOut.set(mReadableStreamBody);
|
||||
}
|
||||
|
||||
|
|
@ -1091,7 +1114,15 @@ FetchBody<Derived>::LockStream(JSContext* aCx,
|
|||
JS::HandleObject aStream,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
// XXXMC: TODO
|
||||
JS::Rooted<JSObject*> reader(aCx,
|
||||
JS::ReadableStreamGetReader(aCx, aStream,
|
||||
JS::ReadableStreamReaderMode::Default));
|
||||
if (!reader) {
|
||||
aRv.StealExceptionFromJSContext(aCx);
|
||||
return;
|
||||
}
|
||||
|
||||
mReadableStreamReader = reader;
|
||||
}
|
||||
|
||||
template
|
||||
|
|
@ -1110,10 +1141,18 @@ template <class Derived>
|
|||
void
|
||||
FetchBody<Derived>::MaybeTeeReadableStreamBody(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aBodyOut,
|
||||
FetchStreamReader** aStreamReader,
|
||||
nsIInputStream** aInputStream,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(aStreamReader);
|
||||
MOZ_DIAGNOSTIC_ASSERT(aInputStream);
|
||||
MOZ_DIAGNOSTIC_ASSERT(!BodyUsed());
|
||||
|
||||
aBodyOut.set(nullptr);
|
||||
*aStreamReader = nullptr;
|
||||
*aInputStream = nullptr;
|
||||
|
||||
if (!mReadableStreamBody) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1138,18 +1177,27 @@ FetchBody<Derived>::MaybeTeeReadableStreamBody(JSContext* aCx,
|
|||
|
||||
mReadableStreamBody = branch1;
|
||||
aBodyOut.set(branch2);
|
||||
|
||||
aRv = FetchStreamReader::Create(aCx, mOwner, aStreamReader, aInputStream);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template
|
||||
void
|
||||
FetchBody<Request>::MaybeTeeReadableStreamBody(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aMessage,
|
||||
FetchStreamReader** aStreamReader,
|
||||
nsIInputStream** aInputStream,
|
||||
ErrorResult& aRv);
|
||||
|
||||
template
|
||||
void
|
||||
FetchBody<Response>::MaybeTeeReadableStreamBody(JSContext* aCx,
|
||||
JS::MutableHandle<JSObject*> aMessage,
|
||||
FetchStreamReader** aStreamReader,
|
||||
nsIInputStream** aInputStream,
|
||||
ErrorResult& aRv);
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue