From b2047d9636d246bd4aae7e436744d1cd231d3782 Mon Sep 17 00:00:00 2001 From: Michael Layzell Date: Mon, 18 Jul 2016 12:42:35 -0400 Subject: [PATCH] Bug 1018486 - Part 6: Changes in parser/, r=peterv, r=hsivonen MozReview-Commit-ID: EN2yZUn8xj --- parser/html/nsHtml5Parser.cpp | 45 ++++++++++++++------------- parser/html/nsHtml5TreeOpExecutor.cpp | 6 ++-- parser/htmlparser/nsParser.cpp | 8 ++--- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/parser/html/nsHtml5Parser.cpp b/parser/html/nsHtml5Parser.cpp index 8d3a6e6648bb..e8ca12f89b99 100644 --- a/parser/html/nsHtml5Parser.cpp +++ b/parser/html/nsHtml5Parser.cpp @@ -210,14 +210,15 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, // Gripping the other objects just in case, since the other old grip // required grips to these, too. RefPtr streamKungFuDeathGrip(GetStreamParser()); - RefPtr treeOpKungFuDeathGrip(mExecutor); + mozilla::Unused << streamKungFuDeathGrip; // Not used within function + RefPtr executor(mExecutor); - if (!mExecutor->HasStarted()) { + if (!executor->HasStarted()) { NS_ASSERTION(!GetStreamParser(), "Had stream parser but document.write started life cycle."); // This is the first document.write() on a document.open()ed document - mExecutor->SetParser(this); - mTreeBuilder->setScriptingEnabled(mExecutor->IsScriptEnabled()); + executor->SetParser(this); + mTreeBuilder->setScriptingEnabled(executor->IsScriptEnabled()); bool isSrcdoc = false; nsCOMPtr channel; @@ -228,7 +229,7 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, mTreeBuilder->setIsSrcdocDocument(isSrcdoc); mTokenizer->start(); - mExecutor->Start(); + executor->Start(); if (!aContentType.EqualsLiteral("text/html")) { mTreeBuilder->StartPlainText(); mTokenizer->StartPlainText(); @@ -238,12 +239,12 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, * WillBuildModel to be called before the document has had its * script global object set. */ - rv = mExecutor->WillBuildModel(eDTDMode_unknown); + rv = executor->WillBuildModel(eDTDMode_unknown); NS_ENSURE_SUCCESS(rv, rv); } // Return early if the parser has processed EOF - if (mExecutor->IsComplete()) { + if (executor->IsComplete()) { return NS_OK; } @@ -371,11 +372,11 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, } if (!mTokenizer->EnsureBufferSpace(stackBuffer.getLength())) { - return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY); + return executor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY); } mLastWasCR = mTokenizer->tokenizeBuffer(&stackBuffer); if (NS_FAILED((rv = mTreeBuilder->IsBroken()))) { - return mExecutor->MarkAsBroken(rv); + return executor->MarkAsBroken(rv); } if (inRootContext) { @@ -386,11 +387,11 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, if (mTreeBuilder->HasScript()) { mTreeBuilder->Flush(); // Move ops to the executor - rv = mExecutor->FlushDocumentWrite(); // run the ops + rv = executor->FlushDocumentWrite(); // run the ops NS_ENSURE_SUCCESS(rv, rv); // Flushing tree ops can cause all sorts of things. // Return early if the parser got terminated. - if (mExecutor->IsComplete()) { + if (executor->IsComplete()) { return NS_OK; } } @@ -405,7 +406,7 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, heapBuffer = stackBuffer.FalliblyCopyAsOwningBuffer(); if (!heapBuffer) { // Allocation failed. The parser is now broken. - return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY); + return executor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY); } } @@ -446,7 +447,7 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, "Buffer wasn't tokenized to completion?"); // Scripting semantics require a forced tree builder flush here mTreeBuilder->Flush(); // Move ops to the executor - rv = mExecutor->FlushDocumentWrite(); // run the ops + rv = executor->FlushDocumentWrite(); // run the ops NS_ENSURE_SUCCESS(rv, rv); } else if (stackBuffer.hasMore()) { // The buffer wasn't tokenized to completion. Tokenize the untokenized @@ -457,7 +458,7 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, if (!mDocWriteSpeculativeTreeBuilder) { // Lazily initialize if uninitialized mDocWriteSpeculativeTreeBuilder = - new nsHtml5TreeBuilder(nullptr, mExecutor->GetStage()); + new nsHtml5TreeBuilder(nullptr, executor->GetStage()); mDocWriteSpeculativeTreeBuilder->setScriptingEnabled( mTreeBuilder->isScriptingEnabled()); mDocWriteSpeculativeTokenizer = @@ -484,20 +485,20 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer, if (stackBuffer.hasMore()) { if (!mDocWriteSpeculativeTokenizer->EnsureBufferSpace( stackBuffer.getLength())) { - return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY); + return executor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY); } mDocWriteSpeculativeLastWasCR = mDocWriteSpeculativeTokenizer->tokenizeBuffer(&stackBuffer); nsresult rv; if (NS_FAILED((rv = mDocWriteSpeculativeTreeBuilder->IsBroken()))) { - return mExecutor->MarkAsBroken(rv); + return executor->MarkAsBroken(rv); } } } mDocWriteSpeculativeTreeBuilder->Flush(); mDocWriteSpeculativeTreeBuilder->DropHandles(); - mExecutor->FlushSpeculativeLoads(); + executor->FlushSpeculativeLoads(); } return NS_OK; @@ -514,12 +515,12 @@ nsHtml5Parser::Terminate() // XXX - [ until we figure out a way to break parser-sink circularity ] // Hack - Hold a reference until we are completely done... nsCOMPtr kungFuDeathGrip(this); - RefPtr streamKungFuDeathGrip(GetStreamParser()); - RefPtr treeOpKungFuDeathGrip(mExecutor); - if (GetStreamParser()) { - GetStreamParser()->Terminate(); + RefPtr streamParser(GetStreamParser()); + RefPtr executor(mExecutor); + if (streamParser) { + streamParser->Terminate(); } - return mExecutor->DidBuildModel(true); + return executor->DidBuildModel(true); } NS_IMETHODIMP diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp index 815823b168a6..a79802007ae9 100644 --- a/parser/html/nsHtml5TreeOpExecutor.cpp +++ b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -350,7 +350,7 @@ nsHtml5TreeOpExecutor::RunFlushLoop() nsHtml5FlushLoopGuard guard(this); // this is also the self-kungfu! - nsCOMPtr parserKungFuDeathGrip(mParser); + RefPtr parserKungFuDeathGrip(mParser); // Remember the entry time (void) nsContentSink::WillParseImpl(); @@ -366,7 +366,7 @@ nsHtml5TreeOpExecutor::RunFlushLoop() return; } - if (!mParser->IsParserEnabled()) { + if (!parserKungFuDeathGrip->IsParserEnabled()) { // The parser is blocked. return; } @@ -413,6 +413,7 @@ nsHtml5TreeOpExecutor::RunFlushLoop() // gripped before calling ParseUntilBlocked(); RefPtr streamKungFuDeathGrip = GetParser()->GetStreamParser(); + mozilla::Unused << streamKungFuDeathGrip; // Not used within function // Now parse content left in the document.write() buffer queue if any. // This may generate tree ops on its own or dequeue a speculation. nsresult rv = GetParser()->ParseUntilBlocked(); @@ -527,6 +528,7 @@ nsHtml5TreeOpExecutor::FlushDocumentWrite() // avoid crashing near EOF RefPtr kungFuDeathGrip(this); RefPtr parserKungFuDeathGrip(mParser); + mozilla::Unused << parserKungFuDeathGrip; // Intentionally not used within function NS_ASSERTION(!mReadingFromStage, "Got doc write flush when reading from stage"); diff --git a/parser/htmlparser/nsParser.cpp b/parser/htmlparser/nsParser.cpp index 4b86b236e637..1d10a336c305 100644 --- a/parser/htmlparser/nsParser.cpp +++ b/parser/htmlparser/nsParser.cpp @@ -1050,8 +1050,8 @@ nsParser::ContinueInterruptedParsing() mParserContext->mStreamListenerState == eOnStop; mProcessingNetworkData = true; - if (mSink) { - mSink->WillParse(); + if (sinkDeathGrip) { + sinkDeathGrip->WillParse(); } result = ResumeParse(true, isFinalChunk); // Ref. bug 57999 mProcessingNetworkData = false; @@ -1836,8 +1836,8 @@ nsParser::OnDataAvailable(nsIRequest *request, nsISupports* aContext, nsCOMPtr kungFuDeathGrip(this); nsCOMPtr sinkDeathGrip(mSink); mProcessingNetworkData = true; - if (mSink) { - mSink->WillParse(); + if (sinkDeathGrip) { + sinkDeathGrip->WillParse(); } rv = ResumeParse(); mProcessingNetworkData = false;