Skip to content

Commit

Permalink
Bug 1749935 - Inline nsParser::WillTokenize in the caller. r=hsivonen
Browse files Browse the repository at this point in the history
  • Loading branch information
petervanderbeken committed Feb 14, 2022
1 parent 2e0cd03 commit cd418fa
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 50 deletions.
13 changes: 3 additions & 10 deletions parser/htmlparser/nsExpatDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ nsExpatDriver::nsExpatDriver()
mInExternalDTD(false),
mMadeFinalCallToExpat(false),
mInParser(false),
mIsFinalChunk(false),
mInternalState(NS_OK),
mExpatBuffered(0),
mTagDepth(0),
Expand Down Expand Up @@ -1228,7 +1227,7 @@ void nsExpatDriver::ParseBuffer(const char16_t* aBuffer, uint32_t aLength,
}

NS_IMETHODIMP
nsExpatDriver::ConsumeToken(nsScanner& aScanner) {
nsExpatDriver::ConsumeToken(nsScanner& aScanner, bool aIsFinalChunk) {
// We keep the scanner pointing to the position where Expat will start
// parsing.
nsScannerIterator currentExpatPosition;
Expand All @@ -1250,9 +1249,9 @@ nsExpatDriver::ConsumeToken(nsScanner& aScanner) {
// We want to call Expat if we have more buffers, or if we know there won't
// be more buffers (and so we want to flush the remaining data), or if we're
// currently blocked and there's data in Expat's buffer.
while (start != end || (mIsFinalChunk && !mMadeFinalCallToExpat) ||
while (start != end || (aIsFinalChunk && !mMadeFinalCallToExpat) ||
(BlockedOrInterrupted() && mExpatBuffered > 0)) {
bool noMoreBuffers = start == end && mIsFinalChunk;
bool noMoreBuffers = start == end && aIsFinalChunk;
bool blocked = BlockedOrInterrupted();

const char16_t* buffer;
Expand Down Expand Up @@ -1622,12 +1621,6 @@ void nsExpatDriver::DidBuildModel() {
mSink = nullptr;
}

NS_IMETHODIMP
nsExpatDriver::WillTokenize(bool aIsFinalChunk) {
mIsFinalChunk = aIsFinalChunk;
return NS_OK;
}

NS_IMETHODIMP_(void)
nsExpatDriver::Terminate() {
// XXX - not sure what happens to the unparsed data.
Expand Down
3 changes: 0 additions & 3 deletions parser/htmlparser/nsExpatDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ class nsExpatDriver : public nsIDTD, public nsITokenizer {

// Used to track if we're in the parser.
bool mInParser;
// Whether we're sure that we won't be getting more buffers to parse from
// Necko
bool mIsFinalChunk;

nsresult mInternalState;

Expand Down
5 changes: 2 additions & 3 deletions parser/htmlparser/nsHTMLTokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ nsHTMLTokenizer::nsHTMLTokenizer() {
// TODO Assert about:blank-ness.
}

nsresult nsHTMLTokenizer::WillTokenize(bool aIsFinalChunk) { return NS_OK; }

/**
* This method is repeatedly called by the tokenizer.
* Each time, we determine the kind of token we're about to
Expand All @@ -46,6 +44,7 @@ nsresult nsHTMLTokenizer::WillTokenize(bool aIsFinalChunk) { return NS_OK; }
* reach a <script>).
* @return Success or error
*/
nsresult nsHTMLTokenizer::ConsumeToken(nsScanner& aScanner) {
nsresult nsHTMLTokenizer::ConsumeToken(nsScanner& aScanner,
bool aIsFinalChunk) {
return NS_ERROR_HTMLPARSER_EOF;
}
8 changes: 3 additions & 5 deletions parser/htmlparser/nsITokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ class nsITokenizer : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITOKENIZER_IID)

NS_IMETHOD WillTokenize(bool aIsFinalChunk) = 0;
NS_IMETHOD ConsumeToken(nsScanner& aScanner) = 0;
NS_IMETHOD ConsumeToken(nsScanner& aScanner, bool aIsFinalChunk) = 0;
};

NS_DEFINE_STATIC_IID_ACCESSOR(nsITokenizer, NS_ITOKENIZER_IID)

#define NS_DECL_NSITOKENIZER \
NS_IMETHOD WillTokenize(bool aIsFinalChunk) override; \
NS_IMETHOD ConsumeToken(nsScanner& aScanner) override;
#define NS_DECL_NSITOKENIZER \
NS_IMETHOD ConsumeToken(nsScanner& aScanner, bool aIsFinalChunk) override;

#endif
20 changes: 2 additions & 18 deletions parser/htmlparser/nsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,22 +1102,6 @@ nsresult nsParser::OnStopRequest(nsIRequest* request, nsresult status) {
Here come the tokenization methods...
*******************************************************************/

/**
* Part of the code sandwich, this gets called right before
* the tokenization process begins. The main reason for
* this call is to allow the delegate to do initialization.
*/
bool nsParser::WillTokenize(bool aIsFinalChunk) {
if (!mParserContext) {
return true;
}

nsITokenizer* theTokenizer;
nsresult result = mParserContext->GetTokenizer(mDTD, mSink, theTokenizer);
NS_ENSURE_SUCCESS(result, false);
return NS_SUCCEEDED(theTokenizer->WillTokenize(aIsFinalChunk));
}

/**
* This is the primary control routine to consume tokens.
* It iteratively consumes tokens until an error occurs or
Expand All @@ -1140,10 +1124,10 @@ nsresult nsParser::Tokenize(bool aIsFinalChunk) {
if (NS_SUCCEEDED(result)) {
bool killSink = false;

WillTokenize(aIsFinalChunk);
while (NS_SUCCEEDED(result)) {
mParserContext->mScanner.Mark();
result = theTokenizer->ConsumeToken(mParserContext->mScanner);
result =
theTokenizer->ConsumeToken(mParserContext->mScanner, aIsFinalChunk);
if (NS_FAILED(result)) {
mParserContext->mScanner.RewindToMark();
if (NS_ERROR_HTMLPARSER_EOF == result) {
Expand Down
11 changes: 0 additions & 11 deletions parser/htmlparser/nsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,6 @@ class nsParser final : public nsIParser,
These are the tokenization methods...
*******************************************/

/**
* Part of the code sandwich, this gets called right before
* the tokenization process begins. The main reason for
* this call is to allow the delegate to do initialization.
*
* @update gess 3/25/98
* @param
* @return TRUE if it's ok to proceed
*/
bool WillTokenize(bool aIsFinalChunk = false);

/**
* This is the primary control routine. It iteratively
* consumes tokens until an error occurs or you run out
Expand Down

0 comments on commit cd418fa

Please sign in to comment.