From ff8619beb3b0e4fd363ced2ed86b0be6ebcbbce7 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Thu, 5 Apr 2001 17:53:18 +0000 Subject: [PATCH] backing out changes to fix 74728 as they are causing assertion death spirals in todays builds. git-svn-id: svn://10.0.0.236/trunk@91471 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/src/CNavDTD.cpp | 8 +- mozilla/htmlparser/src/COtherElements.h | 6 +- mozilla/htmlparser/src/nsExpatDTD.cpp | 2 +- mozilla/htmlparser/src/nsParserNode.cpp | 26 ++----- mozilla/htmlparser/src/nsParserNode.h | 9 +-- mozilla/htmlparser/src/nsToken.h | 2 +- mozilla/htmlparser/src/nsViewSourceHTML.cpp | 77 ++++++++++--------- mozilla/parser/htmlparser/src/CNavDTD.cpp | 8 +- .../parser/htmlparser/src/COtherElements.h | 6 +- mozilla/parser/htmlparser/src/nsExpatDTD.cpp | 2 +- .../parser/htmlparser/src/nsParserNode.cpp | 26 ++----- mozilla/parser/htmlparser/src/nsParserNode.h | 9 +-- mozilla/parser/htmlparser/src/nsToken.h | 2 +- .../htmlparser/src/nsViewSourceHTML.cpp | 77 ++++++++++--------- 14 files changed, 110 insertions(+), 150 deletions(-) diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index 503d952d01d..b40c3c913a5 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -952,7 +952,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){ const nsString& theString=aNode.GetSkippedContent(); if(0CreateTokenOfType(eToken_text,eHTMLTag_text,theString)); - nsCParserNode theNode(theToken,0,mTokenAllocator); + nsCParserNode theNode(theToken,0); result=mSink->AddLeaf(theNode); //when the node get's destructed, so does the new token } MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::DidHandleStartTag(), this=%p\n", this)); @@ -971,7 +971,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){ CTextToken theToken(theNumber); PRInt32 theLineNumber=0; - nsCParserNode theNode(&theToken,theLineNumber,mTokenAllocator); + nsCParserNode theNode(&theToken,theLineNumber); result=mSink->AddLeaf(theNode); } break; @@ -1420,7 +1420,7 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsIParserNode //because this code calls CloseHead() directly, stack-based token/nodes are ok. CEndToken theToken(eHTMLTag_head); - nsCParserNode theNode(&theToken,mLineNumber,mTokenAllocator); + nsCParserNode theNode(&theToken,mLineNumber); result=CloseHead(&theNode); } } @@ -1903,7 +1903,7 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) { case eHTMLTag_form: { //this is safe because we call close container directly. This node/token is not cached. - nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenAllocator); + nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber); result=CloseContainer(&theNode,theChildTag,PR_FALSE); } break; diff --git a/mozilla/htmlparser/src/COtherElements.h b/mozilla/htmlparser/src/COtherElements.h index 9ce33da19c7..f6ee803ffac 100644 --- a/mozilla/htmlparser/src/COtherElements.h +++ b/mozilla/htmlparser/src/COtherElements.h @@ -250,14 +250,14 @@ public: nsresult result=NS_OK; CStartToken theToken(*aTagList); - nsCParserNode theNode(&theToken,theLineNumber,aContext->mTokenAllocator); + nsCParserNode theNode(&theToken,theLineNumber); result=OpenContainer(&theNode,*aTagList,aContext,aSink); if(eHTMLTag_unknown!=*(aTagList+1)) { AutoGenerateStructure(++aTagList,aContext,aSink); } CEndToken theEndToken(*aTagList--); - nsCParserNode theEndNode(&theEndToken,theLineNumber,aContext->mTokenAllocator); + nsCParserNode theEndNode(&theEndToken,theLineNumber); result=CloseContainer(&theEndNode,*aTagList,aContext,aSink); return result; @@ -1005,7 +1005,7 @@ public: CTextToken theToken(theNumber); PRInt32 theLineNumber=0; - nsCParserNode theNewNode(&theToken,theLineNumber,aContext->mTokenAllocator); + nsCParserNode theNewNode(&theToken,theLineNumber); result=aSink->AddLeaf(theNewNode); return result; } diff --git a/mozilla/htmlparser/src/nsExpatDTD.cpp b/mozilla/htmlparser/src/nsExpatDTD.cpp index 5e68d2d62f0..98afb6b2131 100644 --- a/mozilla/htmlparser/src/nsExpatDTD.cpp +++ b/mozilla/htmlparser/src/nsExpatDTD.cpp @@ -455,7 +455,7 @@ NS_IMETHODIMP nsExpatDTD::HandleToken(CToken* aToken,nsIParser* aParser) { mParser=(nsParser*)aParser; mSink=aParser->GetContentSink(); - nsCParserNode theNode(theToken,mLineNumber,mTokenizer->GetTokenAllocator()); + nsCParserNode theNode(theToken,mLineNumber); switch(theType) { case eToken_newline: diff --git a/mozilla/htmlparser/src/nsParserNode.cpp b/mozilla/htmlparser/src/nsParserNode.cpp index 623c222c2f5..0f4a03cf113 100644 --- a/mozilla/htmlparser/src/nsParserNode.cpp +++ b/mozilla/htmlparser/src/nsParserNode.cpp @@ -40,25 +40,7 @@ const nsString& GetEmptyString() { /** - * Default Constructor - */ -nsCParserNode::nsCParserNode() - : mLineNumber(1), - mToken(nsnull), - mAttributes(nsnull), - mSkippedContent(nsnull), - mUseCount(0), - mGenericState(PR_FALSE), - mTokenAllocator(nsnull) -{ - MOZ_COUNT_CTOR(nsCParserNode); -#ifdef HEAP_ALLOCATED_NODES - mNodeAllocator=nsnull; -#endif -} - -/** - * Constructor + * Default constructor * * @update gess 3/25/98 * @param aToken -- token to init internal token @@ -361,11 +343,13 @@ void nsCParserNode::GetSource(nsString& aString) { * @return void */ nsresult nsCParserNode::ReleaseAll() { - NS_ASSERTION(mTokenAllocator != nsnull, "aiee! no token allocator!"); if(mAttributes) { CToken* theAttrToken=0; while((theAttrToken=NS_STATIC_CAST(CToken*,mAttributes->Pop()))) { - IF_FREE(theAttrToken, mTokenAllocator); + // nsViewSourceHTML.cpp:513 creates nsCParserNodes with a NULL token allocator + // need to check to see if mTokenAllocator is non-null + if(mTokenAllocator) + IF_FREE(theAttrToken, mTokenAllocator); } delete mAttributes; mAttributes=0; diff --git a/mozilla/htmlparser/src/nsParserNode.h b/mozilla/htmlparser/src/nsParserNode.h index 3f07a9d13ba..14270a073be 100644 --- a/mozilla/htmlparser/src/nsParserNode.h +++ b/mozilla/htmlparser/src/nsParserNode.h @@ -108,15 +108,10 @@ class nsCParserNode : public nsIParserNode { /** * Default constructor - */ - nsCParserNode(); - - /** - * Constructor * @update gess5/11/98 * @param aToken is the token this node "refers" to */ - nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsTokenAllocator* aTokenAllocator,nsNodeAllocator* aNodeAllocator=0); + nsCParserNode(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0,nsNodeAllocator* aNodeAllocator=0); /** * Destructor @@ -128,7 +123,7 @@ class nsCParserNode : public nsIParserNode { * Init * @update gess5/11/98 */ - virtual nsresult Init(CToken* aToken,PRInt32 aLineNumber,nsTokenAllocator* aTokenAllocator,nsNodeAllocator* aNodeAllocator=0); + virtual nsresult Init(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0,nsNodeAllocator* aNodeAllocator=0); /** * Retrieve the name of the node diff --git a/mozilla/htmlparser/src/nsToken.h b/mozilla/htmlparser/src/nsToken.h index eb834f983be..8cbe2bb652e 100644 --- a/mozilla/htmlparser/src/nsToken.h +++ b/mozilla/htmlparser/src/nsToken.h @@ -141,7 +141,7 @@ class CToken { * @update harishd 08/02/00 */ void Release(nsFixedSizeAllocator& aArenaPool) { - if(--mUseCount==0) + if(--mUseCount==0) Destroy(this, aArenaPool); } diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/htmlparser/src/nsViewSourceHTML.cpp index 9b912a4533a..fa6f83b085f 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/htmlparser/src/nsViewSourceHTML.cpp @@ -188,12 +188,15 @@ class CSharedVSContext { public: CSharedVSContext() : - mEndNode(), + mEndNode(), mStartNode(), mTokenNode(), mErrorNode(), mITextToken(), - mErrorToken(NS_ConvertASCIItoUCS2("error")) { + mITextNode(&mITextToken), + mTextToken(), + mErrorToken(NS_ConvertASCIItoUCS2("error")), + mTextNode(&mTextToken){ } ~CSharedVSContext() { @@ -209,7 +212,10 @@ public: nsCParserNode mTokenNode; nsCParserNode mErrorNode; CIndirectTextToken mITextToken; + nsCParserNode mITextNode; + CTextToken mTextToken; CTextToken mErrorToken; + nsCParserNode mTextNode; }; #ifdef VIEW_SOURCE_HTML @@ -443,6 +449,24 @@ nsresult CViewSourceHTML::WillBuildModel( const CParserContext& aParserContext, mErrorCount=0; mTagCount=0; +#ifdef VIEW_SOURCE_HTML + nsAutoString tag; + + tag.AssignWithConversion("HTML"); + CStartToken htmlToken(tag, eHTMLTag_html); + nsCParserNode htmlNode(&htmlToken,0); + mSink->OpenHTML(htmlNode); + + tag.AssignWithConversion("BODY"); + CStartToken bodyToken(tag, eHTMLTag_body); + nsCParserNode bodyNode(&bodyToken,0); + mSink->OpenBody(bodyNode); +#else + CCommentToken ssToken(NS_LITERAL_STRING("")); + nsCParserNode ssNode(&ssToken); + result= mSink->AddCharacterData(ssNode); +#endif // VIEW_SOURCE_HTML + #ifdef rickgdebug (*gDumpFile) << theHeader << endl; (*gDumpFile) << "" << endl; @@ -479,37 +503,17 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke if(!mHasOpenRoot) { #ifdef VIEW_SOURCE_HTML - // For the stack-allocated tokens below, it's safe to pass a null - // token allocator, because there are no attributes on the tokens. nsAutoString tag; - - tag.AssignWithConversion("HTML"); - CStartToken htmlToken(tag, eHTMLTag_html); - nsCParserNode htmlNode(&htmlToken,0,mTokenizer->GetTokenAllocator()); - mSink->OpenHTML(htmlNode); - - tag.AssignWithConversion("BODY"); - CStartToken bodyToken(tag, eHTMLTag_body); - nsCParserNode bodyNode(&bodyToken,0,mTokenizer->GetTokenAllocator()); - mSink->OpenBody(bodyNode); -#else - CCommentToken ssToken(NS_LITERAL_STRING("")); - nsCParserNode ssNode(&ssToken,0,nsnull); - result= mSink->AddCharacterData(ssNode,0,mTokenizer->GetTokenAllocator()); -#endif // VIEW_SOURCE_HTML - -#ifdef VIEW_SOURCE_HTML tag.AssignWithConversion("PRE"); CStartToken theToken(tag, eHTMLTag_pre); #else //now let's automatically open the root container... CStartToken theToken(NS_LITERAL_STRING("viewsource")); #endif // VIEW_SOURCE_HTML + nsCParserNode theNode(&theToken,0); + CAttributeToken *theAttr=nsnull; nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); - - nsCParserNode theNode(&theToken,0,theAllocator); - if(theAllocator) { #ifdef VIEW_SOURCE_HTML theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreStyle)); @@ -603,15 +607,15 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,PRBool aNotify if(ePlainText!=mDocType) { #ifdef VIEW_SOURCE_HTML CEndToken theToken(eHTMLTag_pre); - nsCParserNode preNode(&theToken,0,mTokenizer->GetTokenAllocator()); + nsCParserNode preNode(&theToken,0); mSink->CloseContainer(preNode); CEndToken bodyToken(eHTMLTag_body); - nsCParserNode bodyNode(&bodyToken,0,mTokenizer->GetTokenAllocator()); + nsCParserNode bodyNode(&bodyToken,0); mSink->CloseBody(bodyNode); CEndToken htmlToken(eHTMLTag_html); - nsCParserNode htmlNode(&htmlToken,0,mTokenizer->GetTokenAllocator()); + nsCParserNode htmlNode(&htmlToken,0); mSink->CloseHTML(htmlNode); #else //now let's automatically close the root container... @@ -882,8 +886,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri nsAutoString beforeText; beforeText.AssignWithConversion(kBeforeText[aTagType]); theContext.mITextToken.SetIndirectString(beforeText); - nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator()); - mSink->AddLeaf(theNode); + mSink->AddLeaf(theContext.mITextNode); } #ifdef VIEW_SOURCE_COLORING @@ -897,7 +900,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri #ifdef VIEW_SOURCE_COLORING if (syntaxHighlight) { - theContext.mStartNode.Init(&theTagToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mStartNode.Init(&theTagToken,mLineNumber); #ifdef VIEW_SOURCE_HTML nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); if(theAllocator) { @@ -928,8 +931,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri theContext.mITextToken.SetIndirectString(aText); //now emit the tag name... - nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator()); - mSink->AddLeaf(theNode); + mSink->AddLeaf(theContext.mITextNode); if(attrCount){ result=WriteAttributes(attrCount); @@ -941,7 +943,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri { theContext.mStartNode.ReleaseAll(); CEndToken theEndToken(eHTMLTag_span); - theContext.mEndNode.Init(&theEndToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mEndNode.Init(&theEndToken,mLineNumber); mSink->CloseContainer(theContext.mEndNode); //emit ... } #endif // VIEW_SOURCE_COLORING @@ -949,8 +951,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri nsAutoString afterText; afterText.AssignWithConversion(kAfterText[aTagType]); theContext.mITextToken.SetIndirectString(afterText); - nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator()); - mSink->AddLeaf(theNode); + mSink->AddLeaf(theContext.mITextNode); } #else theContext.mEndNode.Init(&theTagToken,mLineNumber); @@ -989,7 +990,7 @@ nsresult CViewSourceHTML::WriteTagWithError(nsString &theXMLTagName,const nsARea //first write the error tag itself... - theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber); result=mSink->OpenContainer(theContext.mErrorNode); //emit ... } @@ -1004,7 +1005,7 @@ nsresult CViewSourceHTML::WriteTagWithError(nsString &theXMLTagName,const nsARea //now close the error tag... STOP_TIMER(); - theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber); mSink->CloseContainer(theContext.mErrorNode); START_TIMER(); } @@ -1056,7 +1057,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) { #endif // VIEW_SOURCE_HTML CSharedVSContext& theContext=CSharedVSContext::GetSharedContext(); - theContext.mTokenNode.Init(theToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mTokenNode.Init(theToken,mLineNumber); eHTMLTags theParent=(mTags.Length()) ? (eHTMLTags)mTags.Last() : eHTMLTag_unknown; eHTMLTags theChild=(eHTMLTags)aToken->GetTypeID(); diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index 503d952d01d..b40c3c913a5 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -952,7 +952,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){ const nsString& theString=aNode.GetSkippedContent(); if(0CreateTokenOfType(eToken_text,eHTMLTag_text,theString)); - nsCParserNode theNode(theToken,0,mTokenAllocator); + nsCParserNode theNode(theToken,0); result=mSink->AddLeaf(theNode); //when the node get's destructed, so does the new token } MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::DidHandleStartTag(), this=%p\n", this)); @@ -971,7 +971,7 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){ CTextToken theToken(theNumber); PRInt32 theLineNumber=0; - nsCParserNode theNode(&theToken,theLineNumber,mTokenAllocator); + nsCParserNode theNode(&theToken,theLineNumber); result=mSink->AddLeaf(theNode); } break; @@ -1420,7 +1420,7 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsIParserNode //because this code calls CloseHead() directly, stack-based token/nodes are ok. CEndToken theToken(eHTMLTag_head); - nsCParserNode theNode(&theToken,mLineNumber,mTokenAllocator); + nsCParserNode theNode(&theToken,mLineNumber); result=CloseHead(&theNode); } } @@ -1903,7 +1903,7 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) { case eHTMLTag_form: { //this is safe because we call close container directly. This node/token is not cached. - nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber,mTokenAllocator); + nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber); result=CloseContainer(&theNode,theChildTag,PR_FALSE); } break; diff --git a/mozilla/parser/htmlparser/src/COtherElements.h b/mozilla/parser/htmlparser/src/COtherElements.h index 9ce33da19c7..f6ee803ffac 100644 --- a/mozilla/parser/htmlparser/src/COtherElements.h +++ b/mozilla/parser/htmlparser/src/COtherElements.h @@ -250,14 +250,14 @@ public: nsresult result=NS_OK; CStartToken theToken(*aTagList); - nsCParserNode theNode(&theToken,theLineNumber,aContext->mTokenAllocator); + nsCParserNode theNode(&theToken,theLineNumber); result=OpenContainer(&theNode,*aTagList,aContext,aSink); if(eHTMLTag_unknown!=*(aTagList+1)) { AutoGenerateStructure(++aTagList,aContext,aSink); } CEndToken theEndToken(*aTagList--); - nsCParserNode theEndNode(&theEndToken,theLineNumber,aContext->mTokenAllocator); + nsCParserNode theEndNode(&theEndToken,theLineNumber); result=CloseContainer(&theEndNode,*aTagList,aContext,aSink); return result; @@ -1005,7 +1005,7 @@ public: CTextToken theToken(theNumber); PRInt32 theLineNumber=0; - nsCParserNode theNewNode(&theToken,theLineNumber,aContext->mTokenAllocator); + nsCParserNode theNewNode(&theToken,theLineNumber); result=aSink->AddLeaf(theNewNode); return result; } diff --git a/mozilla/parser/htmlparser/src/nsExpatDTD.cpp b/mozilla/parser/htmlparser/src/nsExpatDTD.cpp index 5e68d2d62f0..98afb6b2131 100644 --- a/mozilla/parser/htmlparser/src/nsExpatDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsExpatDTD.cpp @@ -455,7 +455,7 @@ NS_IMETHODIMP nsExpatDTD::HandleToken(CToken* aToken,nsIParser* aParser) { mParser=(nsParser*)aParser; mSink=aParser->GetContentSink(); - nsCParserNode theNode(theToken,mLineNumber,mTokenizer->GetTokenAllocator()); + nsCParserNode theNode(theToken,mLineNumber); switch(theType) { case eToken_newline: diff --git a/mozilla/parser/htmlparser/src/nsParserNode.cpp b/mozilla/parser/htmlparser/src/nsParserNode.cpp index 623c222c2f5..0f4a03cf113 100644 --- a/mozilla/parser/htmlparser/src/nsParserNode.cpp +++ b/mozilla/parser/htmlparser/src/nsParserNode.cpp @@ -40,25 +40,7 @@ const nsString& GetEmptyString() { /** - * Default Constructor - */ -nsCParserNode::nsCParserNode() - : mLineNumber(1), - mToken(nsnull), - mAttributes(nsnull), - mSkippedContent(nsnull), - mUseCount(0), - mGenericState(PR_FALSE), - mTokenAllocator(nsnull) -{ - MOZ_COUNT_CTOR(nsCParserNode); -#ifdef HEAP_ALLOCATED_NODES - mNodeAllocator=nsnull; -#endif -} - -/** - * Constructor + * Default constructor * * @update gess 3/25/98 * @param aToken -- token to init internal token @@ -361,11 +343,13 @@ void nsCParserNode::GetSource(nsString& aString) { * @return void */ nsresult nsCParserNode::ReleaseAll() { - NS_ASSERTION(mTokenAllocator != nsnull, "aiee! no token allocator!"); if(mAttributes) { CToken* theAttrToken=0; while((theAttrToken=NS_STATIC_CAST(CToken*,mAttributes->Pop()))) { - IF_FREE(theAttrToken, mTokenAllocator); + // nsViewSourceHTML.cpp:513 creates nsCParserNodes with a NULL token allocator + // need to check to see if mTokenAllocator is non-null + if(mTokenAllocator) + IF_FREE(theAttrToken, mTokenAllocator); } delete mAttributes; mAttributes=0; diff --git a/mozilla/parser/htmlparser/src/nsParserNode.h b/mozilla/parser/htmlparser/src/nsParserNode.h index 3f07a9d13ba..14270a073be 100644 --- a/mozilla/parser/htmlparser/src/nsParserNode.h +++ b/mozilla/parser/htmlparser/src/nsParserNode.h @@ -108,15 +108,10 @@ class nsCParserNode : public nsIParserNode { /** * Default constructor - */ - nsCParserNode(); - - /** - * Constructor * @update gess5/11/98 * @param aToken is the token this node "refers" to */ - nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsTokenAllocator* aTokenAllocator,nsNodeAllocator* aNodeAllocator=0); + nsCParserNode(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0,nsNodeAllocator* aNodeAllocator=0); /** * Destructor @@ -128,7 +123,7 @@ class nsCParserNode : public nsIParserNode { * Init * @update gess5/11/98 */ - virtual nsresult Init(CToken* aToken,PRInt32 aLineNumber,nsTokenAllocator* aTokenAllocator,nsNodeAllocator* aNodeAllocator=0); + virtual nsresult Init(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsTokenAllocator* aTokenAllocator=0,nsNodeAllocator* aNodeAllocator=0); /** * Retrieve the name of the node diff --git a/mozilla/parser/htmlparser/src/nsToken.h b/mozilla/parser/htmlparser/src/nsToken.h index eb834f983be..8cbe2bb652e 100644 --- a/mozilla/parser/htmlparser/src/nsToken.h +++ b/mozilla/parser/htmlparser/src/nsToken.h @@ -141,7 +141,7 @@ class CToken { * @update harishd 08/02/00 */ void Release(nsFixedSizeAllocator& aArenaPool) { - if(--mUseCount==0) + if(--mUseCount==0) Destroy(this, aArenaPool); } diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp index 9b912a4533a..fa6f83b085f 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -188,12 +188,15 @@ class CSharedVSContext { public: CSharedVSContext() : - mEndNode(), + mEndNode(), mStartNode(), mTokenNode(), mErrorNode(), mITextToken(), - mErrorToken(NS_ConvertASCIItoUCS2("error")) { + mITextNode(&mITextToken), + mTextToken(), + mErrorToken(NS_ConvertASCIItoUCS2("error")), + mTextNode(&mTextToken){ } ~CSharedVSContext() { @@ -209,7 +212,10 @@ public: nsCParserNode mTokenNode; nsCParserNode mErrorNode; CIndirectTextToken mITextToken; + nsCParserNode mITextNode; + CTextToken mTextToken; CTextToken mErrorToken; + nsCParserNode mTextNode; }; #ifdef VIEW_SOURCE_HTML @@ -443,6 +449,24 @@ nsresult CViewSourceHTML::WillBuildModel( const CParserContext& aParserContext, mErrorCount=0; mTagCount=0; +#ifdef VIEW_SOURCE_HTML + nsAutoString tag; + + tag.AssignWithConversion("HTML"); + CStartToken htmlToken(tag, eHTMLTag_html); + nsCParserNode htmlNode(&htmlToken,0); + mSink->OpenHTML(htmlNode); + + tag.AssignWithConversion("BODY"); + CStartToken bodyToken(tag, eHTMLTag_body); + nsCParserNode bodyNode(&bodyToken,0); + mSink->OpenBody(bodyNode); +#else + CCommentToken ssToken(NS_LITERAL_STRING("")); + nsCParserNode ssNode(&ssToken); + result= mSink->AddCharacterData(ssNode); +#endif // VIEW_SOURCE_HTML + #ifdef rickgdebug (*gDumpFile) << theHeader << endl; (*gDumpFile) << "" << endl; @@ -479,37 +503,17 @@ NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aToke if(!mHasOpenRoot) { #ifdef VIEW_SOURCE_HTML - // For the stack-allocated tokens below, it's safe to pass a null - // token allocator, because there are no attributes on the tokens. nsAutoString tag; - - tag.AssignWithConversion("HTML"); - CStartToken htmlToken(tag, eHTMLTag_html); - nsCParserNode htmlNode(&htmlToken,0,mTokenizer->GetTokenAllocator()); - mSink->OpenHTML(htmlNode); - - tag.AssignWithConversion("BODY"); - CStartToken bodyToken(tag, eHTMLTag_body); - nsCParserNode bodyNode(&bodyToken,0,mTokenizer->GetTokenAllocator()); - mSink->OpenBody(bodyNode); -#else - CCommentToken ssToken(NS_LITERAL_STRING("")); - nsCParserNode ssNode(&ssToken,0,nsnull); - result= mSink->AddCharacterData(ssNode,0,mTokenizer->GetTokenAllocator()); -#endif // VIEW_SOURCE_HTML - -#ifdef VIEW_SOURCE_HTML tag.AssignWithConversion("PRE"); CStartToken theToken(tag, eHTMLTag_pre); #else //now let's automatically open the root container... CStartToken theToken(NS_LITERAL_STRING("viewsource")); #endif // VIEW_SOURCE_HTML + nsCParserNode theNode(&theToken,0); + CAttributeToken *theAttr=nsnull; nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); - - nsCParserNode theNode(&theToken,0,theAllocator); - if(theAllocator) { #ifdef VIEW_SOURCE_HTML theAttr=(CAttributeToken*)theAllocator->CreateTokenOfType(eToken_attribute,eHTMLTag_unknown,NS_ConvertASCIItoUCS2(kPreStyle)); @@ -603,15 +607,15 @@ NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,PRBool aNotify if(ePlainText!=mDocType) { #ifdef VIEW_SOURCE_HTML CEndToken theToken(eHTMLTag_pre); - nsCParserNode preNode(&theToken,0,mTokenizer->GetTokenAllocator()); + nsCParserNode preNode(&theToken,0); mSink->CloseContainer(preNode); CEndToken bodyToken(eHTMLTag_body); - nsCParserNode bodyNode(&bodyToken,0,mTokenizer->GetTokenAllocator()); + nsCParserNode bodyNode(&bodyToken,0); mSink->CloseBody(bodyNode); CEndToken htmlToken(eHTMLTag_html); - nsCParserNode htmlNode(&htmlToken,0,mTokenizer->GetTokenAllocator()); + nsCParserNode htmlNode(&htmlToken,0); mSink->CloseHTML(htmlNode); #else //now let's automatically close the root container... @@ -882,8 +886,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri nsAutoString beforeText; beforeText.AssignWithConversion(kBeforeText[aTagType]); theContext.mITextToken.SetIndirectString(beforeText); - nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator()); - mSink->AddLeaf(theNode); + mSink->AddLeaf(theContext.mITextNode); } #ifdef VIEW_SOURCE_COLORING @@ -897,7 +900,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri #ifdef VIEW_SOURCE_COLORING if (syntaxHighlight) { - theContext.mStartNode.Init(&theTagToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mStartNode.Init(&theTagToken,mLineNumber); #ifdef VIEW_SOURCE_HTML nsTokenAllocator* theAllocator=mTokenizer->GetTokenAllocator(); if(theAllocator) { @@ -928,8 +931,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri theContext.mITextToken.SetIndirectString(aText); //now emit the tag name... - nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator()); - mSink->AddLeaf(theNode); + mSink->AddLeaf(theContext.mITextNode); if(attrCount){ result=WriteAttributes(attrCount); @@ -941,7 +943,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri { theContext.mStartNode.ReleaseAll(); CEndToken theEndToken(eHTMLTag_span); - theContext.mEndNode.Init(&theEndToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mEndNode.Init(&theEndToken,mLineNumber); mSink->CloseContainer(theContext.mEndNode); //emit ... } #endif // VIEW_SOURCE_COLORING @@ -949,8 +951,7 @@ nsresult CViewSourceHTML::WriteTag(nsString &theXMLTagName,const nsAReadableStri nsAutoString afterText; afterText.AssignWithConversion(kAfterText[aTagType]); theContext.mITextToken.SetIndirectString(afterText); - nsCParserNode theNode(&theContext.mITextToken,0,mTokenizer->GetTokenAllocator()); - mSink->AddLeaf(theNode); + mSink->AddLeaf(theContext.mITextNode); } #else theContext.mEndNode.Init(&theTagToken,mLineNumber); @@ -989,7 +990,7 @@ nsresult CViewSourceHTML::WriteTagWithError(nsString &theXMLTagName,const nsARea //first write the error tag itself... - theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber); result=mSink->OpenContainer(theContext.mErrorNode); //emit ... } @@ -1004,7 +1005,7 @@ nsresult CViewSourceHTML::WriteTagWithError(nsString &theXMLTagName,const nsARea //now close the error tag... STOP_TIMER(); - theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mErrorNode.Init(&theContext.mErrorToken,mLineNumber); mSink->CloseContainer(theContext.mErrorNode); START_TIMER(); } @@ -1056,7 +1057,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) { #endif // VIEW_SOURCE_HTML CSharedVSContext& theContext=CSharedVSContext::GetSharedContext(); - theContext.mTokenNode.Init(theToken,mLineNumber,mTokenizer->GetTokenAllocator()); + theContext.mTokenNode.Init(theToken,mLineNumber); eHTMLTags theParent=(mTags.Length()) ? (eHTMLTags)mTags.Last() : eHTMLTag_unknown; eHTMLTags theChild=(eHTMLTags)aToken->GetTypeID();