Bug 1563032 - BodyStream must check the return value of BodyStreamHolder::GetReadableStreamBody(), r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D36717

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-07-03 16:08:30 +00:00
Родитель 5f5804e41b
Коммит a6803fce1e
4 изменённых файлов: 18 добавлений и 12 удалений

Просмотреть файл

@ -345,7 +345,8 @@ BodyStream::OnInputStreamReady(nsIAsyncInputStream* aStream) {
}
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> stream(cx, mStreamHolder->ReadableStreamBody());
MOZ_DIAGNOSTIC_ASSERT(mStreamHolder->GetReadableStreamBody());
JS::Rooted<JSObject*> stream(cx, mStreamHolder->GetReadableStreamBody());
uint64_t size = 0;
nsresult rv = mInputStream->Available(&size);
@ -418,9 +419,14 @@ void BodyStream::Close() {
return;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> stream(cx, mStreamHolder->ReadableStreamBody());
CloseAndReleaseObjects(cx, lock, stream);
JSObject* streamObj = mStreamHolder->GetReadableStreamBody();
if (streamObj) {
JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> stream(cx, streamObj);
CloseAndReleaseObjects(cx, lock, stream);
} else {
ReleaseObjects(lock);
}
}
void BodyStream::CloseAndReleaseObjects(JSContext* aCx,
@ -485,8 +491,11 @@ void BodyStream::ReleaseObjects(const MutexAutoLock& aProofOfLock) {
}
}
// Let's inform the JSEngine that we are going to be released.
JS::ReadableStreamReleaseCCObject(mStreamHolder->ReadableStreamBody());
JSObject* streamObj = mStreamHolder->GetReadableStreamBody();
if (streamObj) {
// Let's inform the JSEngine that we are going to be released.
JS::ReadableStreamReleaseCCObject(streamObj);
}
mWorkerRef = nullptr;
mGlobal = nullptr;

Просмотреть файл

@ -32,7 +32,7 @@ class BodyStreamHolder : public nsISupports {
virtual void MarkAsRead() = 0;
virtual JSObject* ReadableStreamBody() = 0;
virtual JSObject* GetReadableStreamBody() = 0;
protected:
virtual ~BodyStreamHolder() = default;

Просмотреть файл

@ -199,10 +199,7 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
mFetchStreamReader = nullptr;
}
JSObject* ReadableStreamBody() override {
MOZ_ASSERT(mReadableStreamBody);
return mReadableStreamBody;
}
JSObject* GetReadableStreamBody() override { return mReadableStreamBody; }
void MarkAsRead() override { mBodyUsed = true; }

Просмотреть файл

@ -298,7 +298,7 @@ class BlobBodyStreamHolder final : public BodyStreamHolder {
void MarkAsRead() override {}
JSObject* ReadableStreamBody() override { return mStream; }
JSObject* GetReadableStreamBody() override { return mStream; }
void SetStream(JSObject* aObject) {
MOZ_ASSERT(aObject);