зеркало из https://github.com/mozilla/pjs.git
Bug 63560, XML content sink was not adding script element contents to the content model. Includes also minor optimizations and fixes 2 compiler warnings. r=harishd, a=vidur.
This commit is contained in:
Родитель
8422eb9c8d
Коммит
48c2612011
|
@ -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 <html:script> 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<nsIDOMNode> 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<nsIURI> 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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <html:script> 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<nsIDOMNode> 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<nsIURI> 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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче