diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index b30c706909f..b5624070ccb 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -679,9 +679,7 @@ nsXMLContentSink::CloseContainer(const nsIParserNode& aNode) PRInt32 nameSpaceID = GetNameSpaceId(nameSpacePrefix); isHTML = IsHTMLNameSpace(nameSpaceID); - if (!mInScript) { - FlushText(); - } + FlushText(); if (isHTML) { nsIAtom* tagAtom = NS_NewAtom(tag); @@ -730,18 +728,7 @@ nsXMLContentSink::AddLeaf(const nsIParserNode& aNode) break; case eToken_cdatasection: - /* - * If we're inside a tag we add the data as text so that - * the script can be processed. - * - * -- jst@citec.fi - */ - if (mInScript) { - AddText(aNode.GetText()); - } else { - AddCDATASection(aNode); - } - + AddCDATASection(aNode); break; case eToken_entity: @@ -799,17 +786,15 @@ nsXMLContentSink::AddComment(const nsIParserNode& aNode) { FlushText(); - nsAutoString text; nsIContent *comment; nsIDOMComment *domComment; nsresult result = NS_OK; - text.Assign(aNode.GetText()); result = NS_NewCommentNode(&comment); if (NS_OK == result) { result = comment->QueryInterface(NS_GET_IID(nsIDOMComment), (void **)&domComment); if (NS_OK == result) { - domComment->AppendData(text); + domComment->AppendData(aNode.GetText()); NS_RELEASE(domComment); comment->SetDocument(mDocument, PR_FALSE, PR_TRUE); @@ -826,12 +811,14 @@ nsXMLContentSink::AddCDATASection(const nsIParserNode& aNode) { FlushText(); - nsAutoString text; nsIContent *cdata; nsIDOMCDATASection *domCDATA; nsresult result = NS_OK; - text.Assign(aNode.GetText()); + const nsAReadableString& text = aNode.GetText(); + if (mInScript) { + mScriptText.Append(text); + } result = NS_NewXMLCDATASection(&cdata); if (NS_OK == result) { result = cdata->QueryInterface(NS_GET_IID(nsIDOMCDATASection), (void **)&domCDATA); @@ -1262,20 +1249,7 @@ nsXMLContentSink::AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode) nsCOMPtr tmpNode; - doc->GetDoctype(getter_AddRefs(oldDocType)); - if (oldDocType) { - /* - * If we already have a doctype we replace the old one. - */ - rv = doc->ReplaceChild(oldDocType, docType, getter_AddRefs(tmpNode)); - } else { - /* - * If we don't already have one, append it. - */ - rv = doc->AppendChild(docType, getter_AddRefs(tmpNode)); - } - - return NS_OK; + return doc->AppendChild(docType, getter_AddRefs(tmpNode)); } nsresult @@ -1327,6 +1301,10 @@ nsXMLContentSink::AddText(const nsAReadableString& aString) return NS_OK; } + if (mInScript) { + mScriptText.Append(aString); + } + // Create buffer when we first need it if (0 == mTextSize) { mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * NS_ACCUMULATION_BUFFER_SIZE); @@ -1602,19 +1580,15 @@ nsXMLContentSink::ProcessEndSCRIPTTag(const nsIParserNode& aNode) { nsresult result = NS_OK; if (mInScript) { - nsAutoString script; - script.Assign(mText, mTextLength); nsCOMPtr docURI( dont_AddRef( mDocument->GetDocumentURL() ) ); - result = EvaluateScript(script, docURI, mScriptLineNo, mScriptLanguageVersion); - FlushText(PR_FALSE); + result = EvaluateScript(mScriptText, docURI, mScriptLineNo, mScriptLanguageVersion); + mScriptText.Truncate(); mInScript = PR_FALSE; } return result; } -#define SCRIPT_BUF_SIZE 1024 - // XXX Stolen from nsHTMLContentSink. Needs to be shared. // XXXbe share also with nsRDFParserUtils.cpp and nsHTMLContentSink.cpp // Returns PR_TRUE if the language name is a version of JavaScript and diff --git a/content/xml/document/src/nsXMLContentSink.h b/content/xml/document/src/nsXMLContentSink.h index 455df32f030..7774f8293e2 100644 --- a/content/xml/document/src/nsXMLContentSink.h +++ b/content/xml/document/src/nsXMLContentSink.h @@ -173,11 +173,12 @@ protected: PRUnichar* mText; PRInt32 mTextLength; PRInt32 mTextSize; - PRBool mConstrainSize; + PRPackedBool mConstrainSize; // XXX Special processing for HTML SCRIPT tags. We may need // something similar for STYLE. - PRBool mInScript; + PRPackedBool mInScript; + nsString mScriptText; PRUint32 mScriptLineNo; nsString mPreferredStyle; diff --git a/expat/xmlparse/xmlparse.c b/expat/xmlparse/xmlparse.c index 0bf0d18b502..b8454d141e4 100644 --- a/expat/xmlparse/xmlparse.c +++ b/expat/xmlparse/xmlparse.c @@ -1055,7 +1055,7 @@ const XML_LChar *XML_ErrorString(int code) XML_T("error in processing external entity reference"), XML_T("document is not standalone") }; - if (code > 0 && code < sizeof(message)/sizeof(message[0])) + if (code > 0 && (unsigned int)code < sizeof(message)/sizeof(message[0])) return message[code]; return 0; } @@ -2122,14 +2122,14 @@ processXmlDecl(XML_Parser parser, int isGeneralTextEntity, } else if (encodingName) { enum XML_Error result; - const XML_Char *s = poolStoreString(&tempPool, + const XML_Char *s2 = poolStoreString(&tempPool, encoding, encodingName, encodingName + XmlNameLength(encoding, encodingName)); - if (!s) + if (!s2) return XML_ERROR_NO_MEMORY; - result = handleUnknownEncoding(parser, s); + result = handleUnknownEncoding(parser, s2); poolDiscard(&tempPool); if (result == XML_ERROR_UNKNOWN_ENCODING) eventPtr = encodingName; diff --git a/layout/xml/document/src/nsXMLContentSink.cpp b/layout/xml/document/src/nsXMLContentSink.cpp index b30c706909f..b5624070ccb 100644 --- a/layout/xml/document/src/nsXMLContentSink.cpp +++ b/layout/xml/document/src/nsXMLContentSink.cpp @@ -679,9 +679,7 @@ nsXMLContentSink::CloseContainer(const nsIParserNode& aNode) PRInt32 nameSpaceID = GetNameSpaceId(nameSpacePrefix); isHTML = IsHTMLNameSpace(nameSpaceID); - if (!mInScript) { - FlushText(); - } + FlushText(); if (isHTML) { nsIAtom* tagAtom = NS_NewAtom(tag); @@ -730,18 +728,7 @@ nsXMLContentSink::AddLeaf(const nsIParserNode& aNode) break; case eToken_cdatasection: - /* - * If we're inside a tag we add the data as text so that - * the script can be processed. - * - * -- jst@citec.fi - */ - if (mInScript) { - AddText(aNode.GetText()); - } else { - AddCDATASection(aNode); - } - + AddCDATASection(aNode); break; case eToken_entity: @@ -799,17 +786,15 @@ nsXMLContentSink::AddComment(const nsIParserNode& aNode) { FlushText(); - nsAutoString text; nsIContent *comment; nsIDOMComment *domComment; nsresult result = NS_OK; - text.Assign(aNode.GetText()); result = NS_NewCommentNode(&comment); if (NS_OK == result) { result = comment->QueryInterface(NS_GET_IID(nsIDOMComment), (void **)&domComment); if (NS_OK == result) { - domComment->AppendData(text); + domComment->AppendData(aNode.GetText()); NS_RELEASE(domComment); comment->SetDocument(mDocument, PR_FALSE, PR_TRUE); @@ -826,12 +811,14 @@ nsXMLContentSink::AddCDATASection(const nsIParserNode& aNode) { FlushText(); - nsAutoString text; nsIContent *cdata; nsIDOMCDATASection *domCDATA; nsresult result = NS_OK; - text.Assign(aNode.GetText()); + const nsAReadableString& text = aNode.GetText(); + if (mInScript) { + mScriptText.Append(text); + } result = NS_NewXMLCDATASection(&cdata); if (NS_OK == result) { result = cdata->QueryInterface(NS_GET_IID(nsIDOMCDATASection), (void **)&domCDATA); @@ -1262,20 +1249,7 @@ nsXMLContentSink::AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode) nsCOMPtr tmpNode; - doc->GetDoctype(getter_AddRefs(oldDocType)); - if (oldDocType) { - /* - * If we already have a doctype we replace the old one. - */ - rv = doc->ReplaceChild(oldDocType, docType, getter_AddRefs(tmpNode)); - } else { - /* - * If we don't already have one, append it. - */ - rv = doc->AppendChild(docType, getter_AddRefs(tmpNode)); - } - - return NS_OK; + return doc->AppendChild(docType, getter_AddRefs(tmpNode)); } nsresult @@ -1327,6 +1301,10 @@ nsXMLContentSink::AddText(const nsAReadableString& aString) return NS_OK; } + if (mInScript) { + mScriptText.Append(aString); + } + // Create buffer when we first need it if (0 == mTextSize) { mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * NS_ACCUMULATION_BUFFER_SIZE); @@ -1602,19 +1580,15 @@ nsXMLContentSink::ProcessEndSCRIPTTag(const nsIParserNode& aNode) { nsresult result = NS_OK; if (mInScript) { - nsAutoString script; - script.Assign(mText, mTextLength); nsCOMPtr docURI( dont_AddRef( mDocument->GetDocumentURL() ) ); - result = EvaluateScript(script, docURI, mScriptLineNo, mScriptLanguageVersion); - FlushText(PR_FALSE); + result = EvaluateScript(mScriptText, docURI, mScriptLineNo, mScriptLanguageVersion); + mScriptText.Truncate(); mInScript = PR_FALSE; } return result; } -#define SCRIPT_BUF_SIZE 1024 - // XXX Stolen from nsHTMLContentSink. Needs to be shared. // XXXbe share also with nsRDFParserUtils.cpp and nsHTMLContentSink.cpp // Returns PR_TRUE if the language name is a version of JavaScript and diff --git a/layout/xml/document/src/nsXMLContentSink.h b/layout/xml/document/src/nsXMLContentSink.h index 455df32f030..7774f8293e2 100644 --- a/layout/xml/document/src/nsXMLContentSink.h +++ b/layout/xml/document/src/nsXMLContentSink.h @@ -173,11 +173,12 @@ protected: PRUnichar* mText; PRInt32 mTextLength; PRInt32 mTextSize; - PRBool mConstrainSize; + PRPackedBool mConstrainSize; // XXX Special processing for HTML SCRIPT tags. We may need // something similar for STYLE. - PRBool mInScript; + PRPackedBool mInScript; + nsString mScriptText; PRUint32 mScriptLineNo; nsString mPreferredStyle; diff --git a/parser/expat/lib/xmlparse.c b/parser/expat/lib/xmlparse.c index 0bf0d18b502..b8454d141e4 100644 --- a/parser/expat/lib/xmlparse.c +++ b/parser/expat/lib/xmlparse.c @@ -1055,7 +1055,7 @@ const XML_LChar *XML_ErrorString(int code) XML_T("error in processing external entity reference"), XML_T("document is not standalone") }; - if (code > 0 && code < sizeof(message)/sizeof(message[0])) + if (code > 0 && (unsigned int)code < sizeof(message)/sizeof(message[0])) return message[code]; return 0; } @@ -2122,14 +2122,14 @@ processXmlDecl(XML_Parser parser, int isGeneralTextEntity, } else if (encodingName) { enum XML_Error result; - const XML_Char *s = poolStoreString(&tempPool, + const XML_Char *s2 = poolStoreString(&tempPool, encoding, encodingName, encodingName + XmlNameLength(encoding, encodingName)); - if (!s) + if (!s2) return XML_ERROR_NO_MEMORY; - result = handleUnknownEncoding(parser, s); + result = handleUnknownEncoding(parser, s2); poolDiscard(&tempPool); if (result == XML_ERROR_UNKNOWN_ENCODING) eventPtr = encodingName;