зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1333990: Part 2a - Allow multiple concurrent parser blockers. r=hsivonen
MozReview-Commit-ID: DYegic0RPWL --HG-- extra : rebase_source : 959fae62e924ee9f27f00378a26f752bb0307bb1
This commit is contained in:
Родитель
aaaea39c13
Коммит
45b222c3b2
|
@ -37,7 +37,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|||
nsHtml5Parser::nsHtml5Parser()
|
||||
: mLastWasCR(false)
|
||||
, mDocWriteSpeculativeLastWasCR(false)
|
||||
, mBlocked(false)
|
||||
, mBlocked(0)
|
||||
, mDocWriteSpeculatorActive(false)
|
||||
, mInsertionPointPushLevel(0)
|
||||
, mDocumentClosed(false)
|
||||
|
@ -146,14 +146,19 @@ nsHtml5Parser::ContinueInterruptedParsing()
|
|||
NS_IMETHODIMP_(void)
|
||||
nsHtml5Parser::BlockParser()
|
||||
{
|
||||
mBlocked = true;
|
||||
mBlocked++;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
nsHtml5Parser::UnblockParser()
|
||||
{
|
||||
mBlocked = false;
|
||||
mExecutor->ContinueInterruptedParsingAsync();
|
||||
MOZ_DIAGNOSTIC_ASSERT(mBlocked > 0);
|
||||
if (MOZ_LIKELY(mBlocked > 0)) {
|
||||
mBlocked--;
|
||||
}
|
||||
if (MOZ_LIKELY(mBlocked == 0)) {
|
||||
mExecutor->ContinueInterruptedParsingAsync();
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
|
|
|
@ -278,9 +278,10 @@ class nsHtml5Parser final : public nsIParser,
|
|||
bool mDocWriteSpeculativeLastWasCR;
|
||||
|
||||
/**
|
||||
* The parser is blocking on a script
|
||||
* The parser is blocking on the load of an external script from a web
|
||||
* page, or any number of extension content scripts.
|
||||
*/
|
||||
bool mBlocked;
|
||||
uint32_t mBlocked;
|
||||
|
||||
/**
|
||||
* Whether the document.write() speculator is already active.
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
using namespace mozilla;
|
||||
using mozilla::dom::EncodingUtils;
|
||||
|
||||
#define NS_PARSER_FLAG_PARSER_ENABLED 0x00000002
|
||||
#define NS_PARSER_FLAG_OBSERVERS_ENABLED 0x00000004
|
||||
#define NS_PARSER_FLAG_PENDING_CONTINUE_EVENT 0x00000008
|
||||
#define NS_PARSER_FLAG_FLUSH_TOKENS 0x00000020
|
||||
|
@ -157,8 +156,8 @@ nsParser::Initialize(bool aConstructor)
|
|||
mInternalState = NS_OK;
|
||||
mStreamStatus = NS_OK;
|
||||
mCommand = eViewNormal;
|
||||
mBlocked = 0;
|
||||
mFlags = NS_PARSER_FLAG_OBSERVERS_ENABLED |
|
||||
NS_PARSER_FLAG_PARSER_ENABLED |
|
||||
NS_PARSER_FLAG_CAN_TOKENIZE;
|
||||
|
||||
mProcessingNetworkData = false;
|
||||
|
@ -631,7 +630,7 @@ nsParser::ContinueInterruptedParsing()
|
|||
nsCOMPtr<nsIContentSink> sinkDeathGrip(mSink);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (!(mFlags & NS_PARSER_FLAG_PARSER_ENABLED)) {
|
||||
if (mBlocked) {
|
||||
NS_WARNING("Don't call ContinueInterruptedParsing on a blocked parser.");
|
||||
}
|
||||
#endif
|
||||
|
@ -654,13 +653,15 @@ nsParser::ContinueInterruptedParsing()
|
|||
}
|
||||
|
||||
/**
|
||||
* Stops parsing temporarily. That's it will prevent the
|
||||
* parser from building up content model.
|
||||
* Stops parsing temporarily. That is, it will prevent the
|
||||
* parser from building up content model while scripts
|
||||
* are being loaded (either an external script from a web
|
||||
* page, or any number of extension content scripts).
|
||||
*/
|
||||
NS_IMETHODIMP_(void)
|
||||
nsParser::BlockParser()
|
||||
{
|
||||
mFlags &= ~NS_PARSER_FLAG_PARSER_ENABLED;
|
||||
mBlocked++;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -672,10 +673,9 @@ nsParser::BlockParser()
|
|||
NS_IMETHODIMP_(void)
|
||||
nsParser::UnblockParser()
|
||||
{
|
||||
if (!(mFlags & NS_PARSER_FLAG_PARSER_ENABLED)) {
|
||||
mFlags |= NS_PARSER_FLAG_PARSER_ENABLED;
|
||||
} else {
|
||||
NS_WARNING("Trying to unblock an unblocked parser.");
|
||||
MOZ_DIAGNOSTIC_ASSERT(mBlocked > 0);
|
||||
if (MOZ_LIKELY(mBlocked > 0)) {
|
||||
mBlocked--;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -691,7 +691,7 @@ nsParser::ContinueInterruptedParsingAsync()
|
|||
NS_IMETHODIMP_(bool)
|
||||
nsParser::IsParserEnabled()
|
||||
{
|
||||
return (mFlags & NS_PARSER_FLAG_PARSER_ENABLED) != 0;
|
||||
return !mBlocked;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1024,8 +1024,7 @@ nsParser::ResumeParse(bool allowIteration, bool aIsFinalChunk,
|
|||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
if ((mFlags & NS_PARSER_FLAG_PARSER_ENABLED) &&
|
||||
mInternalState != NS_ERROR_HTMLPARSER_STOPPARSING) {
|
||||
if (!mBlocked && mInternalState != NS_ERROR_HTMLPARSER_STOPPARSING) {
|
||||
|
||||
result = WillBuildModel(mParserContext->mScanner->GetFilename());
|
||||
if (NS_FAILED(result)) {
|
||||
|
@ -1070,7 +1069,7 @@ nsParser::ResumeParse(bool allowIteration, bool aIsFinalChunk,
|
|||
// (and cache any data coming in) until the parser is re-enabled.
|
||||
if (NS_ERROR_HTMLPARSER_BLOCK == result) {
|
||||
mSink->WillInterrupt();
|
||||
if (mFlags & NS_PARSER_FLAG_PARSER_ENABLED) {
|
||||
if (!mBlocked) {
|
||||
// If we were blocked by a recursive invocation, don't re-block.
|
||||
BlockParser();
|
||||
}
|
||||
|
|
|
@ -385,6 +385,7 @@ protected:
|
|||
int32_t mCharsetSource;
|
||||
|
||||
uint16_t mFlags;
|
||||
uint32_t mBlocked;
|
||||
|
||||
nsString mUnusedInput;
|
||||
nsCString mCharset;
|
||||
|
|
Загрузка…
Ссылка в новой задаче