Bug 1746412: Parser cleanup r=hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D134021
This commit is contained in:
Randell Jesup
2021-12-19 16:51:41 +00:00
parent a3af317bcb
commit 31f35e20bc
2 changed files with 9 additions and 4 deletions

View File

@@ -1555,14 +1555,14 @@ nsresult nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest,
uint64_t aSourceOffset,
uint32_t aLength) {
nsresult rv;
if (NS_FAILED(rv = mExecutor->IsBroken())) {
return rv;
}
MOZ_ASSERT(mRequest == aRequest, "Got data on wrong stream.");
uint32_t totalRead;
// Main thread to parser thread dispatch requires copying to buffer first.
if (MOZ_UNLIKELY(NS_IsMainThread())) {
if (NS_FAILED(rv = mExecutor->IsBroken())) {
return rv;
}
Maybe<Buffer<uint8_t>> maybe = Buffer<uint8_t>::Alloc(aLength);
if (maybe.isNothing()) {
return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
@@ -1581,9 +1581,13 @@ nsresult nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest,
}
return rv;
}
MOZ_ASSERT(IsParserThread(), "Wrong thread!");
mozilla::MutexAutoLock autoLock(mTokenizerMutex);
if (NS_FAILED(rv = mTreeBuilder->IsBroken())) {
return rv;
}
if (mBufferingBytes) {
Maybe<Buffer<uint8_t>> maybe = Buffer<uint8_t>::Alloc(aLength);
if (maybe.isNothing()) {
@@ -1605,6 +1609,7 @@ nsresult nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest,
return rv;
}
// Called under lock by function ptr
/* static */
nsresult nsHtml5StreamParser::CopySegmentsToParser(
nsIInputStream* aInStream, void* aClosure, const char* aFromSegment,