mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1866078 - Add InputToReadableStreamAlgorithms::MaybeGetInputStreamIfUnread r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D194186
This commit is contained in:
parent
2a82c49e13
commit
717e4c791d
@ -169,6 +169,10 @@ void FetchStreamReader::StartConsuming(JSContext* aCx, ReadableStream* aStream,
|
||||
ErrorResult& aRv) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mReader);
|
||||
MOZ_DIAGNOSTIC_ASSERT(aStream);
|
||||
MOZ_ASSERT(!aStream->MaybeGetInputStreamIfUnread(),
|
||||
"FetchStreamReader is for JS streams but we got a stream based on "
|
||||
"nsIInputStream here. Extract nsIInputStream and read it instead "
|
||||
"to reduce overhead.");
|
||||
|
||||
aRv = MaybeGrabStrongWorkerRef(aCx);
|
||||
if (aRv.Failed()) {
|
||||
|
@ -511,6 +511,12 @@ void InputToReadableStreamAlgorithms::ReleaseObjects() {
|
||||
mPullPromise = nullptr;
|
||||
}
|
||||
|
||||
nsIInputStream* InputToReadableStreamAlgorithms::MaybeGetInputStreamIfUnread() {
|
||||
MOZ_ASSERT(!mStream->Disturbed(),
|
||||
"Should be only called on non-disturbed streams");
|
||||
return mInput->GetInputStream();
|
||||
}
|
||||
|
||||
void InputToReadableStreamAlgorithms::ErrorPropagation(JSContext* aCx,
|
||||
ReadableStream* aStream,
|
||||
nsresult aError) {
|
||||
|
@ -59,7 +59,9 @@ class UnderlyingSourceAlgorithmsBase : public nsISupports {
|
||||
// from closed(canceled)/errored streams, without waiting for GC.
|
||||
virtual void ReleaseObjects() {}
|
||||
|
||||
// Fetch wants to special-case nsIInputStream-based streams
|
||||
// Can be used to read chunks directly via nsIInputStream to skip JS-related
|
||||
// overhead, if this readable stream is a wrapper of a native stream.
|
||||
// Currently used by Fetch helper functions e.g. new Response(stream).text()
|
||||
virtual nsIInputStream* MaybeGetInputStreamIfUnread() { return nullptr; }
|
||||
|
||||
// https://streams.spec.whatwg.org/#other-specs-rs-create
|
||||
@ -198,6 +200,8 @@ class InputStreamHolder final : public nsIInputStreamCallback,
|
||||
return mInput->CloseWithStatus(aStatus);
|
||||
}
|
||||
|
||||
nsIAsyncInputStream* GetInputStream() { return mInput; }
|
||||
|
||||
private:
|
||||
~InputStreamHolder();
|
||||
|
||||
@ -241,6 +245,8 @@ class InputToReadableStreamAlgorithms final
|
||||
|
||||
void ReleaseObjects() override;
|
||||
|
||||
nsIInputStream* MaybeGetInputStreamIfUnread() override;
|
||||
|
||||
private:
|
||||
~InputToReadableStreamAlgorithms() {
|
||||
if (mInput) {
|
||||
|
Loading…
Reference in New Issue
Block a user