diff --git a/parser/html/nsHtml5AttributeName.cpp b/parser/html/nsHtml5AttributeName.cpp
index a2c4295275f0..a7d40b4adc59 100644
--- a/parser/html/nsHtml5AttributeName.cpp
+++ b/parser/html/nsHtml5AttributeName.cpp
@@ -29,6 +29,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -96,17 +97,17 @@ nsHtml5AttributeName::SAME_LOCAL(nsIAtom* name)
}
nsHtml5AttributeName*
-nsHtml5AttributeName::nameByBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length)
+nsHtml5AttributeName::nameByBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length, nsHtml5AtomTable* interner)
{
PRInt32 hash = nsHtml5AttributeName::bufToHash(buf, length);
PRInt32 index = nsHtml5AttributeName::ATTRIBUTE_HASHES.binarySearch(hash);
if (index < 0) {
- return nsHtml5AttributeName::createAttributeName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length));
+ return nsHtml5AttributeName::createAttributeName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length, interner));
} else {
nsHtml5AttributeName* attributeName = nsHtml5AttributeName::ATTRIBUTE_NAMES[index];
nsIAtom* name = attributeName->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML);
if (!nsHtml5Portability::localEqualsBuffer(name, buf, offset, length)) {
- return nsHtml5AttributeName::createAttributeName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length));
+ return nsHtml5AttributeName::createAttributeName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length, interner));
}
return attributeName;
}
diff --git a/parser/html/nsHtml5AttributeName.h b/parser/html/nsHtml5AttributeName.h
index 2ce00319dd83..ca6e538ad8a5 100644
--- a/parser/html/nsHtml5AttributeName.h
+++ b/parser/html/nsHtml5AttributeName.h
@@ -30,6 +30,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -74,7 +75,7 @@ class nsHtml5AttributeName
static nsIAtom** COLONIFIED_LOCAL(nsIAtom* name, nsIAtom* suffix);
public:
static nsIAtom** SAME_LOCAL(nsIAtom* name);
- static nsHtml5AttributeName* nameByBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length);
+ static nsHtml5AttributeName* nameByBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length, nsHtml5AtomTable* interner);
private:
static PRInt32 bufToHash(PRUnichar* buf, PRInt32 len);
PRInt32* uri;
diff --git a/parser/html/nsHtml5ElementName.cpp b/parser/html/nsHtml5ElementName.cpp
index 95457b2b960e..d9cff19209a0 100644
--- a/parser/html/nsHtml5ElementName.cpp
+++ b/parser/html/nsHtml5ElementName.cpp
@@ -29,6 +29,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -56,17 +57,17 @@
#include "nsHtml5ReleasableElementName.h"
nsHtml5ElementName*
-nsHtml5ElementName::elementNameByBuffer(jArray buf, PRInt32 offset, PRInt32 length)
+nsHtml5ElementName::elementNameByBuffer(jArray buf, PRInt32 offset, PRInt32 length, nsHtml5AtomTable* interner)
{
PRInt32 hash = nsHtml5ElementName::bufToHash(buf, length);
PRInt32 index = nsHtml5ElementName::ELEMENT_HASHES.binarySearch(hash);
if (index < 0) {
- return new nsHtml5ReleasableElementName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length));
+ return new nsHtml5ReleasableElementName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length, interner));
} else {
nsHtml5ElementName* elementName = nsHtml5ElementName::ELEMENT_NAMES[index];
nsIAtom* name = elementName->name;
if (!nsHtml5Portability::localEqualsBuffer(name, buf, offset, length)) {
- return new nsHtml5ReleasableElementName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length));
+ return new nsHtml5ReleasableElementName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length, interner));
}
return elementName;
}
diff --git a/parser/html/nsHtml5ElementName.h b/parser/html/nsHtml5ElementName.h
index 33d6bb70a01b..74fba554b619 100644
--- a/parser/html/nsHtml5ElementName.h
+++ b/parser/html/nsHtml5ElementName.h
@@ -30,6 +30,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -65,7 +66,7 @@ class nsHtml5ElementName
PRBool special;
PRBool scoping;
PRBool fosterParenting;
- static nsHtml5ElementName* elementNameByBuffer(jArray buf, PRInt32 offset, PRInt32 length);
+ static nsHtml5ElementName* elementNameByBuffer(jArray buf, PRInt32 offset, PRInt32 length, nsHtml5AtomTable* interner);
private:
static PRInt32 bufToHash(jArray buf, PRInt32 len);
nsHtml5ElementName(nsIAtom* name, nsIAtom* camelCaseName, PRInt32 group, PRBool special, PRBool scoping, PRBool fosterParenting);
diff --git a/parser/html/nsHtml5HtmlAttributes.cpp b/parser/html/nsHtml5HtmlAttributes.cpp
index 58a38aaef659..45800c6c91ef 100644
--- a/parser/html/nsHtml5HtmlAttributes.cpp
+++ b/parser/html/nsHtml5HtmlAttributes.cpp
@@ -30,6 +30,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
diff --git a/parser/html/nsHtml5HtmlAttributes.h b/parser/html/nsHtml5HtmlAttributes.h
index 8af1dcf5570f..9ab6b0f441c8 100644
--- a/parser/html/nsHtml5HtmlAttributes.h
+++ b/parser/html/nsHtml5HtmlAttributes.h
@@ -31,6 +31,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
diff --git a/parser/html/nsHtml5MetaScanner.cpp b/parser/html/nsHtml5MetaScanner.cpp
index 4fcc795bceaf..3ef50c396e6c 100644
--- a/parser/html/nsHtml5MetaScanner.cpp
+++ b/parser/html/nsHtml5MetaScanner.cpp
@@ -30,6 +30,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
diff --git a/parser/html/nsHtml5MetaScanner.h b/parser/html/nsHtml5MetaScanner.h
index 3ca27c5831d0..765e34b3be5b 100644
--- a/parser/html/nsHtml5MetaScanner.h
+++ b/parser/html/nsHtml5MetaScanner.h
@@ -31,6 +31,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
diff --git a/parser/html/nsHtml5Parser.cpp b/parser/html/nsHtml5Parser.cpp
index 107f6f7fefa1..9bff4e12ed8d 100644
--- a/parser/html/nsHtml5Parser.cpp
+++ b/parser/html/nsHtml5Parser.cpp
@@ -59,6 +59,7 @@
#include "nsHtml5UTF16Buffer.h"
#include "nsHtml5TreeBuilder.h"
#include "nsHtml5Parser.h"
+#include "nsHtml5AtomTable.h"
//-------------- Begin ParseContinue Event Definition ------------------------
/*
@@ -96,13 +97,11 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsHtml5Parser)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsHtml5Parser)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mExecutor, nsIContentSink)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mStreamParser, nsIStreamListener)
- tmp->mTreeBuilder->DoTraverse(cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsHtml5Parser)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mExecutor)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mStreamParser)
- tmp->mTreeBuilder->DoUnlink();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
nsHtml5Parser::nsHtml5Parser()
@@ -111,8 +110,11 @@ nsHtml5Parser::nsHtml5Parser()
, mExecutor(new nsHtml5TreeOpExecutor())
, mTreeBuilder(new nsHtml5TreeBuilder(mExecutor))
, mTokenizer(new nsHtml5Tokenizer(mTreeBuilder))
+ , mAtomTable(new nsHtml5AtomTable())
{
mExecutor->SetTreeBuilder(mTreeBuilder);
+ mAtomTable->Init(); // we aren't checking for OOM anyway...
+ mTokenizer->setInterner(mAtomTable);
// There's a zeroing operator new for everything else
}
@@ -455,7 +457,10 @@ nsHtml5Parser::ParseFragment(const nsAString& aSourceBuffer,
nsIURI* uri = doc->GetDocumentURI();
NS_ENSURE_TRUE(uri, NS_ERROR_NOT_AVAILABLE);
- Initialize(doc, uri, nsnull, nsnull);
+ nsCOMPtr container = doc->GetContainer();
+ NS_ENSURE_TRUE(container, NS_ERROR_NOT_AVAILABLE);
+
+ Initialize(doc, uri, container, nsnull);
// Initialize() doesn't deal with base URI
mExecutor->SetBaseUriFromDocument();
@@ -463,7 +468,8 @@ nsHtml5Parser::ParseFragment(const nsAString& aSourceBuffer,
mExecutor->SetParser(this);
mExecutor->SetNodeInfoManager(target->GetOwnerDoc()->NodeInfoManager());
- mTreeBuilder->setFragmentContext(aContextLocalName, aContextNamespace, target, aQuirks);
+ nsIContent* weakTarget = target;
+ mTreeBuilder->setFragmentContext(aContextLocalName, aContextNamespace, &weakTarget, aQuirks);
mFragmentMode = PR_TRUE;
NS_PRECONDITION(mExecutor->GetLifeCycle() == NOT_STARTED, "Tried to start parse without initializing the parser properly.");
@@ -489,6 +495,7 @@ nsHtml5Parser::ParseFragment(const nsAString& aSourceBuffer,
mExecutor->Flush();
mTokenizer->end();
mExecutor->DropParserAndPerfHint();
+ mAtomTable->Clear();
return NS_OK;
}
@@ -518,6 +525,7 @@ nsHtml5Parser::Reset()
mStreamParser = nsnull;
mRootContextKey = nsnull;
mContinueEvent = nsnull; // weak ref
+ mAtomTable->Clear(); // should be already cleared in the fragment case anyway
// Portable parser objects
while (mFirstBuffer->next) {
nsHtml5UTF16Buffer* oldBuf = mFirstBuffer;
diff --git a/parser/html/nsHtml5Parser.h b/parser/html/nsHtml5Parser.h
index baf58fbbf4a7..5a7fb4220d4e 100644
--- a/parser/html/nsHtml5Parser.h
+++ b/parser/html/nsHtml5Parser.h
@@ -60,6 +60,7 @@
#include "nsHtml5UTF16Buffer.h"
#include "nsHtml5TreeOpExecutor.h"
#include "nsHtml5StreamParser.h"
+#include "nsHtml5AtomTable.h"
class nsHtml5Parser : public nsIParser {
public:
@@ -338,7 +339,7 @@ class nsHtml5Parser : public nsIParser {
/**
* The tree operation executor
*/
- nsRefPtr mExecutor;
+ nsRefPtr mExecutor;
/**
* The HTML5 tree builder
@@ -353,7 +354,12 @@ class nsHtml5Parser : public nsIParser {
/**
* The stream parser.
*/
- nsRefPtr mStreamParser;
+ nsRefPtr mStreamParser;
+
+ /**
+ * The scoped atom service
+ */
+ const nsAutoPtr mAtomTable;
};
#endif
diff --git a/parser/html/nsHtml5Portability.cpp b/parser/html/nsHtml5Portability.cpp
index 0e9792274089..dfb85bb1afaf 100644
--- a/parser/html/nsHtml5Portability.cpp
+++ b/parser/html/nsHtml5Portability.cpp
@@ -42,10 +42,11 @@
#include "nsHtml5Portability.h"
nsIAtom*
-nsHtml5Portability::newLocalNameFromBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length)
+nsHtml5Portability::newLocalNameFromBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length, nsHtml5AtomTable* interner)
{
NS_ASSERTION(!offset, "The offset should always be zero here.");
- return NS_NewAtom(nsDependentSubstring(buf, buf + length));
+ NS_ASSERTION(interner, "Didn't get an atom service.");
+ return interner->GetAtom(nsDependentSubstring(buf, buf + length));
}
nsString*
@@ -101,28 +102,28 @@ nsHtml5Portability::releaseString(nsString* str)
delete str;
}
+// XXX useless code
void
nsHtml5Portability::retainLocal(nsIAtom* local)
{
- NS_IF_ADDREF(local);
}
+// XXX useless code
void
nsHtml5Portability::releaseLocal(nsIAtom* local)
{
- NS_IF_RELEASE(local);
}
+// XXX Useless code
void
-nsHtml5Portability::retainElement(nsIContent* element)
+nsHtml5Portability::retainElement(nsIContent** element)
{
- NS_IF_ADDREF(element);
}
+// XXX Useless code
void
-nsHtml5Portability::releaseElement(nsIContent* element)
+nsHtml5Portability::releaseElement(nsIContent** element)
{
- NS_IF_RELEASE(element);
}
PRBool
diff --git a/parser/html/nsHtml5Portability.h b/parser/html/nsHtml5Portability.h
index 671e61ba8854..09424087056d 100644
--- a/parser/html/nsHtml5Portability.h
+++ b/parser/html/nsHtml5Portability.h
@@ -30,6 +30,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -58,7 +59,7 @@ class nsHtml5StateSnapshot;
class nsHtml5Portability
{
public:
- static nsIAtom* newLocalNameFromBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length);
+ static nsIAtom* newLocalNameFromBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length, nsHtml5AtomTable* interner);
static nsString* newStringFromBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length);
static nsString* newEmptyString();
static nsString* newStringFromLiteral(const char* literal);
@@ -68,8 +69,8 @@ class nsHtml5Portability
static void releaseString(nsString* str);
static void retainLocal(nsIAtom* local);
static void releaseLocal(nsIAtom* local);
- static void retainElement(nsIContent* elt);
- static void releaseElement(nsIContent* elt);
+ static void retainElement(nsIContent** elt);
+ static void releaseElement(nsIContent** elt);
static PRBool localEqualsBuffer(nsIAtom* local, PRUnichar* buf, PRInt32 offset, PRInt32 length);
static PRBool lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(const char* lowerCaseLiteral, nsString* string);
static PRBool lowerCaseLiteralEqualsIgnoreAsciiCaseString(const char* lowerCaseLiteral, nsString* string);
diff --git a/parser/html/nsHtml5StackNode.cpp b/parser/html/nsHtml5StackNode.cpp
index cc566021a9d4..6c29c78e58d8 100644
--- a/parser/html/nsHtml5StackNode.cpp
+++ b/parser/html/nsHtml5StackNode.cpp
@@ -30,6 +30,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -56,7 +57,7 @@
#include "nsHtml5StackNode.h"
-nsHtml5StackNode::nsHtml5StackNode(PRInt32 group, PRInt32 ns, nsIAtom* name, nsIContent* node, PRBool scoping, PRBool special, PRBool fosterParenting, nsIAtom* popName, nsHtml5HtmlAttributes* attributes)
+nsHtml5StackNode::nsHtml5StackNode(PRInt32 group, PRInt32 ns, nsIAtom* name, nsIContent** node, PRBool scoping, PRBool special, PRBool fosterParenting, nsIAtom* popName, nsHtml5HtmlAttributes* attributes)
: group(group),
name(name),
popName(popName),
@@ -75,7 +76,7 @@ nsHtml5StackNode::nsHtml5StackNode(PRInt32 group, PRInt32 ns, nsIAtom* name, nsI
}
-nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent* node)
+nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent** node)
: group(elementName->group),
name(elementName->name),
popName(elementName->name),
@@ -94,7 +95,7 @@ nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName,
}
-nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent* node, nsHtml5HtmlAttributes* attributes)
+nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent** node, nsHtml5HtmlAttributes* attributes)
: group(elementName->group),
name(elementName->name),
popName(elementName->name),
@@ -113,7 +114,7 @@ nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName,
}
-nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent* node, nsIAtom* popName)
+nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent** node, nsIAtom* popName)
: group(elementName->group),
name(elementName->name),
popName(popName),
@@ -132,7 +133,7 @@ nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName,
}
-nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent* node, nsIAtom* popName, PRBool scoping)
+nsHtml5StackNode::nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent** node, nsIAtom* popName, PRBool scoping)
: group(elementName->group),
name(elementName->name),
popName(popName),
@@ -192,5 +193,3 @@ nsHtml5StackNode::releaseStatics()
}
-#include "nsHtml5StackNodeCppSupplement.h"
-
diff --git a/parser/html/nsHtml5StackNode.h b/parser/html/nsHtml5StackNode.h
index 31d517b1bc21..9be20fd9b13b 100644
--- a/parser/html/nsHtml5StackNode.h
+++ b/parser/html/nsHtml5StackNode.h
@@ -31,6 +31,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -64,7 +65,7 @@ class nsHtml5StackNode
nsIAtom* name;
nsIAtom* popName;
PRInt32 ns;
- nsIContent* node;
+ nsIContent** node;
PRBool scoping;
PRBool special;
PRBool fosterParenting;
@@ -72,19 +73,17 @@ class nsHtml5StackNode
private:
PRInt32 refcount;
public:
- nsHtml5StackNode(PRInt32 group, PRInt32 ns, nsIAtom* name, nsIContent* node, PRBool scoping, PRBool special, PRBool fosterParenting, nsIAtom* popName, nsHtml5HtmlAttributes* attributes);
- nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent* node);
- nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent* node, nsHtml5HtmlAttributes* attributes);
- nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent* node, nsIAtom* popName);
- nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent* node, nsIAtom* popName, PRBool scoping);
+ nsHtml5StackNode(PRInt32 group, PRInt32 ns, nsIAtom* name, nsIContent** node, PRBool scoping, PRBool special, PRBool fosterParenting, nsIAtom* popName, nsHtml5HtmlAttributes* attributes);
+ nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent** node);
+ nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent** node, nsHtml5HtmlAttributes* attributes);
+ nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent** node, nsIAtom* popName);
+ nsHtml5StackNode(PRInt32 ns, nsHtml5ElementName* elementName, nsIContent** node, nsIAtom* popName, PRBool scoping);
~nsHtml5StackNode();
void dropAttributes();
void retain();
void release();
static void initializeStatics();
static void releaseStatics();
-
-#include "nsHtml5StackNodeHSupplement.h"
};
#ifdef nsHtml5StackNode_cpp__
diff --git a/parser/html/nsHtml5StackNodeCppSupplement.h b/parser/html/nsHtml5StackNodeCppSupplement.h
deleted file mode 100644
index cd003de68480..000000000000
--- a/parser/html/nsHtml5StackNodeCppSupplement.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is HTML Parser C++ Translator code.
- *
- * The Initial Developer of the Original Code is
- * Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Henri Sivonen
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsHtml5StackNode)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsHtml5StackNode)
- NS_IF_RELEASE(tmp->node);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMETHODIMP
-nsHtml5StackNode::NS_CYCLE_COLLECTION_INNERCLASS::Traverse
- (void *p, nsCycleCollectionTraversalCallback &cb)
-{
- nsHtml5StackNode *tmp = static_cast(p);
- NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsHtml5StackNode, tmp->refcount)
- NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(node);
- return NS_OK;
-}
-
-NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsHtml5StackNode, retain)
-
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsHtml5StackNode, release)
diff --git a/parser/html/nsHtml5StackNodeHSupplement.h b/parser/html/nsHtml5StackNodeHSupplement.h
deleted file mode 100644
index a39ed7e09fdd..000000000000
--- a/parser/html/nsHtml5StackNodeHSupplement.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is HTML Parser C++ Translator code.
- *
- * The Initial Developer of the Original Code is
- * Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Henri Sivonen
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsHtml5StackNode)
diff --git a/parser/html/nsHtml5StateSnapshot.cpp b/parser/html/nsHtml5StateSnapshot.cpp
index 639a69bbe51e..4701738ee340 100644
--- a/parser/html/nsHtml5StateSnapshot.cpp
+++ b/parser/html/nsHtml5StateSnapshot.cpp
@@ -29,6 +29,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -55,7 +56,7 @@
#include "nsHtml5StateSnapshot.h"
-nsHtml5StateSnapshot::nsHtml5StateSnapshot(jArray stack, jArray listOfActiveFormattingElements, nsIContent* formPointer)
+nsHtml5StateSnapshot::nsHtml5StateSnapshot(jArray stack, jArray listOfActiveFormattingElements, nsIContent** formPointer)
: stack(stack),
listOfActiveFormattingElements(listOfActiveFormattingElements),
formPointer(formPointer)
diff --git a/parser/html/nsHtml5StateSnapshot.h b/parser/html/nsHtml5StateSnapshot.h
index 2a6322defddd..1f56487a1cc7 100644
--- a/parser/html/nsHtml5StateSnapshot.h
+++ b/parser/html/nsHtml5StateSnapshot.h
@@ -30,6 +30,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -58,10 +59,10 @@ class nsHtml5Portability;
class nsHtml5StateSnapshot
{
public:
- nsHtml5StateSnapshot(jArray stack, jArray listOfActiveFormattingElements, nsIContent* formPointer);
+ nsHtml5StateSnapshot(jArray stack, jArray listOfActiveFormattingElements, nsIContent** formPointer);
jArray stack;
jArray listOfActiveFormattingElements;
- nsIContent* formPointer;
+ nsIContent** formPointer;
~nsHtml5StateSnapshot();
static void initializeStatics();
static void releaseStatics();
diff --git a/parser/html/nsHtml5StreamParser.cpp b/parser/html/nsHtml5StreamParser.cpp
index 37a1e37ae3c4..156e669917d0 100644
--- a/parser/html/nsHtml5StreamParser.cpp
+++ b/parser/html/nsHtml5StreamParser.cpp
@@ -581,7 +581,10 @@ nsHtml5StreamParser::ParseUntilSuspend()
return; // no more data for now but expecting more
case STREAM_ENDING:
mDone = PR_TRUE;
- mExecutor->DidBuildModel(PR_FALSE);
+ {
+ nsRefPtr kungFuDeathGrip(this);
+ mExecutor->DidBuildModel(PR_FALSE);
+ }
return; // no more data and not expecting more
default:
NS_NOTREACHED("It should be impossible to reach this.");
diff --git a/parser/html/nsHtml5Tokenizer.cpp b/parser/html/nsHtml5Tokenizer.cpp
index 2f3db47aed46..96a655d193da 100644
--- a/parser/html/nsHtml5Tokenizer.cpp
+++ b/parser/html/nsHtml5Tokenizer.cpp
@@ -32,6 +32,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -72,11 +73,20 @@ nsHtml5Tokenizer::nsHtml5Tokenizer(nsHtml5TreeBuilder* tokenHandler)
: tokenHandler(tokenHandler),
encodingDeclarationHandler(nsnull),
bmpChar(jArray(1)),
- astralChar(jArray(2))
+ astralChar(jArray(2)),
+ attributes(nsnull),
+ tagName(nsnull),
+ attributeName(nsnull)
{
MOZ_COUNT_CTOR(nsHtml5Tokenizer);
}
+void
+nsHtml5Tokenizer::setInterner(nsHtml5AtomTable* interner)
+{
+ this->interner = interner;
+}
+
void
nsHtml5Tokenizer::initLocation(nsString* newPublicId, nsString* newSystemId)
{
@@ -100,7 +110,7 @@ nsHtml5Tokenizer::setContentModelFlag(PRInt32 contentModelFlag, nsIAtom* content
return;
}
jArray asArray = nsHtml5Portability::newCharArrayFromLocal(contentModelElement);
- this->contentModelElement = nsHtml5ElementName::elementNameByBuffer(asArray, 0, asArray.length);
+ this->contentModelElement = nsHtml5ElementName::elementNameByBuffer(asArray, 0, asArray.length, interner);
asArray.release();
contentModelElementToArray();
}
@@ -229,7 +239,7 @@ nsHtml5Tokenizer::strBufToString()
void
nsHtml5Tokenizer::strBufToDoctypeName()
{
- doctypeName = nsHtml5Portability::newLocalNameFromBuffer(strBuf, 0, strBufLen);
+ doctypeName = nsHtml5Portability::newLocalNameFromBuffer(strBuf, 0, strBufLen, interner);
}
void
@@ -342,13 +352,13 @@ nsHtml5Tokenizer::flushChars(PRUnichar* buf, PRInt32 pos)
void
nsHtml5Tokenizer::resetAttributes()
{
- attributes->clear(0);
+ attributes = nsnull;
}
void
nsHtml5Tokenizer::strBufToElementNameString()
{
- tagName = nsHtml5ElementName::elementNameByBuffer(strBuf, 0, strBufLen);
+ tagName = nsHtml5ElementName::elementNameByBuffer(strBuf, 0, strBufLen, interner);
}
PRInt32
@@ -364,6 +374,8 @@ nsHtml5Tokenizer::emitCurrentTagToken(PRBool selfClosing, PRInt32 pos)
} else {
tokenHandler->startTag(tagName, attrs, selfClosing);
}
+ tagName->release();
+ tagName = nsnull;
resetAttributes();
return stateSave;
}
@@ -371,7 +383,10 @@ nsHtml5Tokenizer::emitCurrentTagToken(PRBool selfClosing, PRInt32 pos)
void
nsHtml5Tokenizer::attributeNameComplete()
{
- attributeName = nsHtml5AttributeName::nameByBuffer(strBuf, 0, strBufLen);
+ attributeName = nsHtml5AttributeName::nameByBuffer(strBuf, 0, strBufLen, interner);
+ if (!attributes) {
+ attributes = new nsHtml5HtmlAttributes(0);
+ }
if (attributes->contains(attributeName)) {
attributeName->release();
@@ -426,7 +441,18 @@ nsHtml5Tokenizer::start()
value = 0;
seenDigits = PR_FALSE;
shouldSuspend = PR_FALSE;
- attributes = new nsHtml5HtmlAttributes(0);
+ if (!!tagName) {
+ tagName->release();
+ tagName = nsnull;
+ }
+ if (!!attributeName) {
+ attributeName->release();
+ attributeName = nsnull;
+ }
+ if (!!attributes) {
+ delete attributes;
+ attributes = nsnull;
+ }
}
PRBool
@@ -3282,8 +3308,14 @@ nsHtml5Tokenizer::end()
systemIdentifier = nsnull;
publicIdentifier = nsnull;
doctypeName = nsnull;
- tagName = nsnull;
- attributeName = nsnull;
+ if (!!tagName) {
+ tagName->release();
+ tagName = nsnull;
+ }
+ if (!!attributeName) {
+ attributeName->release();
+ attributeName = nsnull;
+ }
tokenHandler->endTokenization();
if (!!attributes) {
attributes->clear(0);
diff --git a/parser/html/nsHtml5Tokenizer.h b/parser/html/nsHtml5Tokenizer.h
index 32b566f8710d..2bacfb2c7d0a 100644
--- a/parser/html/nsHtml5Tokenizer.h
+++ b/parser/html/nsHtml5Tokenizer.h
@@ -33,6 +33,7 @@
#include "prtypes.h"
#include "nsIAtom.h"
+#include "nsHtml5AtomTable.h"
#include "nsString.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
@@ -134,8 +135,10 @@ class nsHtml5Tokenizer
PRBool confident;
private:
PRInt32 line;
+ nsHtml5AtomTable* interner;
public:
nsHtml5Tokenizer(nsHtml5TreeBuilder* tokenHandler);
+ void setInterner(nsHtml5AtomTable* interner);
void initLocation(nsString* newPublicId, nsString* newSystemId);
~nsHtml5Tokenizer();
void setContentModelFlag(PRInt32 contentModelFlag, nsIAtom* contentModelElement);
diff --git a/parser/html/nsHtml5TreeBuilder.cpp b/parser/html/nsHtml5TreeBuilder.cpp
index 9c0c82c63d8e..eeeae554603d 100644
--- a/parser/html/nsHtml5TreeBuilder.cpp
+++ b/parser/html/nsHtml5TreeBuilder.cpp
@@ -82,7 +82,7 @@ nsHtml5TreeBuilder::startTokenization(nsHtml5Tokenizer* self)
charBufferLen = 0;
charBuffer = jArray(1024);
if (fragment) {
- nsIContent* elt;
+ nsIContent** elt;
if (!!contextNode) {
elt = contextNode;
nsHtml5Portability::retainElement(elt);
@@ -618,6 +618,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
} else {
appendToCurrentNodeAndPushElementMayFosterCamelCase(currNs, elementName, attributes);
}
+ attributes = nsnull;
goto starttagloop_end;
} else {
attributes->adjustForMath();
@@ -627,6 +628,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
} else {
appendToCurrentNodeAndPushElementMayFosterNoScoping(currNs, elementName, attributes);
}
+ attributes = nsnull;
goto starttagloop_end;
}
}
@@ -641,6 +643,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
clearStackBackTo(findLastInTableScopeOrRootTbodyTheadTfoot());
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_ROW;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_TD_OR_TH: {
@@ -676,6 +679,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_CELL;
insertMarker();
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_CAPTION:
@@ -706,12 +710,14 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
insertMarker();
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_CAPTION;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_COLGROUP: {
clearStackBackTo(findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE));
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_COL: {
@@ -724,6 +730,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
clearStackBackTo(findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE));
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_TR:
@@ -756,6 +763,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_INPUT: {
@@ -764,6 +772,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
}
appendVoidElementToCurrent(kNameSpaceID_XHTML, name, attributes, formPointer);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -839,6 +848,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
}
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_FRAMESET;
+ attributes = nsnull;
goto starttagloop_end;
}
} else {
@@ -877,6 +887,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_BASE:
@@ -891,6 +902,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_BODY: {
addAttributesToBody(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_P:
@@ -899,6 +911,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_ADDRESS_OR_DIR_OR_ARTICLE_OR_ASIDE_OR_DATAGRID_OR_DETAILS_OR_DIALOG_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_NAV_OR_SECTION: {
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6: {
@@ -908,17 +921,20 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
pop();
}
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_FIELDSET: {
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes, formPointer);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_PRE_OR_LISTING: {
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
needToDropLF = PR_TRUE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_FORM: {
@@ -928,6 +944,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
} else {
implicitlyCloseP();
appendToCurrentNodeAndPushFormElementMayFoster(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
}
@@ -952,12 +969,14 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
}
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_PLAINTEXT: {
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_PLAINTEXT, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_A: {
@@ -976,12 +995,14 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
}
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushFormattingElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
case NS_HTML5TREE_BUILDER_FONT: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushFormattingElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_NOBR: {
@@ -991,6 +1012,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
adoptionAgencyEndTag(nsHtml5Atoms::nobr);
}
appendToCurrentNodeAndPushFormattingElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_BUTTON: {
@@ -1010,6 +1032,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes, formPointer);
insertMarker();
+ attributes = nsnull;
goto starttagloop_end;
}
}
@@ -1017,12 +1040,14 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes, formPointer);
insertMarker();
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
insertMarker();
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_XMP: {
@@ -1031,6 +1056,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_TABLE: {
@@ -1039,6 +1065,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
}
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_TABLE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_BR:
@@ -1049,12 +1076,14 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE: {
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_HR: {
implicitlyCloseP();
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_IMAGE: {
@@ -1067,6 +1096,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
reconstructTheActiveFormattingElements();
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, name, attributes, formPointer);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_ISINDEX: {
@@ -1111,6 +1141,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
selfClosing = PR_FALSE;
delete formAttrs;
delete inputAttributes;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_TEXTAREA: {
@@ -1119,12 +1150,14 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
needToDropLF = PR_TRUE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_NOSCRIPT: {
if (!scriptingEnabled) {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
} else {
}
@@ -1136,6 +1169,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_SELECT: {
@@ -1156,6 +1190,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
break;
}
}
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_OPTGROUP:
@@ -1185,6 +1220,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
}
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_RT_OR_RP: {
@@ -1199,6 +1235,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
}
}
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_MATH: {
@@ -1211,6 +1248,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_MathML, elementName, attributes);
foreignFlag = NS_HTML5TREE_BUILDER_IN_FOREIGN;
}
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_SVG: {
@@ -1223,6 +1261,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_SVG, elementName, attributes);
foreignFlag = NS_HTML5TREE_BUILDER_IN_FOREIGN;
}
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_CAPTION:
@@ -1240,11 +1279,13 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_OUTPUT_OR_LABEL: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes, formPointer);
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
}
@@ -1257,12 +1298,14 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_BASE:
case NS_HTML5TREE_BUILDER_COMMAND_OR_EVENT_SOURCE: {
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_META:
@@ -1274,6 +1317,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_RCDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_NOSCRIPT: {
@@ -1286,6 +1330,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendToCurrentNodeAndPushElementMayFoster(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT;
}
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_SCRIPT:
@@ -1295,6 +1340,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_HEAD: {
@@ -1315,17 +1361,20 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_LINK: {
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_META: {
checkMetaCharset(attributes);
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_STYLE:
@@ -1334,6 +1383,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_HEAD: {
@@ -1357,11 +1407,13 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_COL: {
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -1396,6 +1448,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_OPTION: {
@@ -1403,6 +1456,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
pop();
}
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_OPTGROUP: {
@@ -1413,6 +1467,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
pop();
}
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_SELECT: {
@@ -1441,6 +1496,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -1454,6 +1510,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -1467,11 +1524,13 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
switch(group) {
case NS_HTML5TREE_BUILDER_FRAMESET: {
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_FRAME: {
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
+ attributes = nsnull;
goto starttagloop_end;
}
default:
@@ -1483,6 +1542,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_NOFRAMES: {
@@ -1490,6 +1550,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -1512,6 +1573,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendHtmlElementToDocumentAndPush(attributes);
}
mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD;
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -1526,11 +1588,13 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_HEAD: {
appendToCurrentNodeAndPushHeadElement(attributes);
mode = NS_HTML5TREE_BUILDER_IN_HEAD;
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -1545,6 +1609,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_BODY: {
@@ -1554,11 +1619,13 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendToCurrentNodeAndPushBodyElement(attributes);
}
mode = NS_HTML5TREE_BUILDER_FRAMESET_OK;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_FRAMESET: {
appendToCurrentNodeAndPushElement(kNameSpaceID_XHTML, elementName, attributes);
mode = NS_HTML5TREE_BUILDER_IN_FRAMESET;
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_BASE: {
@@ -1567,6 +1634,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
pop();
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_LINK: {
@@ -1575,6 +1643,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
pop();
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_META: {
@@ -1584,6 +1653,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
appendVoidElementToCurrentMayFoster(kNameSpaceID_XHTML, elementName, attributes);
selfClosing = PR_FALSE;
pop();
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_SCRIPT: {
@@ -1593,6 +1663,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_STYLE:
@@ -1603,6 +1674,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_TITLE: {
@@ -1612,6 +1684,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_RCDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
case NS_HTML5TREE_BUILDER_HEAD: {
@@ -1630,6 +1703,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case NS_HTML5TREE_BUILDER_HTML: {
addAttributesToHtml(attributes);
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -1647,6 +1721,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
originalMode = mode;
mode = NS_HTML5TREE_BUILDER_IN_CDATA_RCDATA;
tokenizer->setContentModelFlag(NS_HTML5TOKENIZER_CDATA, elementName);
+ attributes = nsnull;
goto starttagloop_end;
}
default: {
@@ -1666,6 +1741,9 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
if (selfClosing) {
}
+ if (attributes != nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
+ delete attributes;
+ }
}
nsString*
@@ -3058,7 +3136,7 @@ nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
}
- nsIContent* clone = createElement(kNameSpaceID_XHTML, node->name, node->attributes->cloneAttributes());
+ nsIContent** clone = createElement(kNameSpaceID_XHTML, node->name, node->attributes->cloneAttributes());
nsHtml5StackNode* newNode = new nsHtml5StackNode(node->group, node->ns, node->name, clone, node->scoping, node->special, node->fosterParenting, node->popName, node->attributes);
node->dropAttributes();
stack[nodePos] = newNode;
@@ -3080,7 +3158,7 @@ nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
detachFromParent(lastNode->node);
appendElement(lastNode->node, commonAncestor->node);
}
- nsIContent* clone = createElement(kNameSpaceID_XHTML, formattingElt->name, formattingElt->attributes->cloneAttributes());
+ nsIContent** clone = createElement(kNameSpaceID_XHTML, formattingElt->name, formattingElt->attributes->cloneAttributes());
nsHtml5StackNode* formattingClone = new nsHtml5StackNode(formattingElt->group, formattingElt->ns, formattingElt->name, clone, formattingElt->scoping, formattingElt->special, formattingElt->fosterParenting, formattingElt->popName, formattingElt->attributes);
formattingElt->dropAttributes();
appendChildrenToNewParent(furthestBlock->node, clone);
@@ -3227,7 +3305,7 @@ nsHtml5TreeBuilder::reconstructTheActiveFormattingElements()
while (entryPos < listPtr) {
entryPos++;
nsHtml5StackNode* entry = listOfActiveFormattingElements[entryPos];
- nsIContent* clone = createElement(kNameSpaceID_XHTML, entry->name, entry->attributes->cloneAttributes());
+ nsIContent** clone = createElement(kNameSpaceID_XHTML, entry->name, entry->attributes->cloneAttributes());
nsHtml5StackNode* entryClone = new nsHtml5StackNode(entry->group, entry->ns, entry->name, clone, entry->scoping, entry->special, entry->fosterParenting, entry->popName, entry->attributes);
entry->dropAttributes();
nsHtml5StackNode* currentNode = stack[currentPtr];
@@ -3244,11 +3322,11 @@ nsHtml5TreeBuilder::reconstructTheActiveFormattingElements()
}
void
-nsHtml5TreeBuilder::insertIntoFosterParent(nsIContent* child)
+nsHtml5TreeBuilder::insertIntoFosterParent(nsIContent** child)
{
PRInt32 eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE);
nsHtml5StackNode* node = stack[eltPos];
- nsIContent* elt = node->node;
+ nsIContent** elt = node->node;
if (!eltPos) {
appendElement(child, elt);
return;
@@ -3293,7 +3371,7 @@ nsHtml5TreeBuilder::popOnEof()
void
nsHtml5TreeBuilder::appendHtmlElementToDocumentAndPush(nsHtml5HtmlAttributes* attributes)
{
- nsIContent* elt = createHtmlElementSetAsRoot(attributes);
+ nsIContent** elt = createHtmlElementSetAsRoot(attributes);
nsHtml5StackNode* node = new nsHtml5StackNode(kNameSpaceID_XHTML, nsHtml5ElementName::ELT_HTML, elt);
push(node);
nsHtml5Portability::releaseElement(elt);
@@ -3309,7 +3387,7 @@ void
nsHtml5TreeBuilder::appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes* attributes)
{
flushCharacters();
- nsIContent* elt = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::head, attributes);
+ nsIContent** elt = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::head, attributes);
appendElement(elt, stack[currentPtr]->node);
headPointer = elt;
nsHtml5Portability::retainElement(headPointer);
@@ -3334,7 +3412,7 @@ void
nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormElementMayFoster(nsHtml5HtmlAttributes* attributes)
{
flushCharacters();
- nsIContent* elt = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::form, attributes);
+ nsIContent** elt = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::form, attributes);
formPointer = elt;
nsHtml5Portability::retainElement(formPointer);
nsHtml5StackNode* current = stack[currentPtr];
@@ -3353,7 +3431,7 @@ void
nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormattingElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
{
flushCharacters();
- nsIContent* elt = createElement(ns, elementName->name, attributes);
+ nsIContent** elt = createElement(ns, elementName->name, attributes);
nsHtml5StackNode* current = stack[currentPtr];
if (current->fosterParenting) {
@@ -3372,7 +3450,7 @@ void
nsHtml5TreeBuilder::appendToCurrentNodeAndPushElement(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
{
flushCharacters();
- nsIContent* elt = createElement(ns, elementName->name, attributes);
+ nsIContent** elt = createElement(ns, elementName->name, attributes);
appendElement(elt, stack[currentPtr]->node);
nsHtml5StackNode* node = new nsHtml5StackNode(ns, elementName, elt);
push(node);
@@ -3384,7 +3462,7 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtm
{
flushCharacters();
nsIAtom* popName = elementName->name;
- nsIContent* elt = createElement(ns, popName, attributes);
+ nsIContent** elt = createElement(ns, popName, attributes);
nsHtml5StackNode* current = stack[currentPtr];
if (current->fosterParenting) {
@@ -3402,7 +3480,7 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterNoScoping(PRInt32
{
flushCharacters();
nsIAtom* popName = elementName->name;
- nsIContent* elt = createElement(ns, popName, attributes);
+ nsIContent** elt = createElement(ns, popName, attributes);
nsHtml5StackNode* current = stack[currentPtr];
if (current->fosterParenting) {
@@ -3420,7 +3498,7 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterCamelCase(PRInt32
{
flushCharacters();
nsIAtom* popName = elementName->camelCaseName;
- nsIContent* elt = createElement(ns, popName, attributes);
+ nsIContent** elt = createElement(ns, popName, attributes);
nsHtml5StackNode* current = stack[currentPtr];
if (current->fosterParenting) {
@@ -3434,10 +3512,10 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterCamelCase(PRInt32
}
void
-nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, nsIContent* form)
+nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, nsIContent** form)
{
flushCharacters();
- nsIContent* elt = createElement(ns, elementName->name, attributes, form);
+ nsIContent** elt = createElement(ns, elementName->name, attributes, form);
nsHtml5StackNode* current = stack[currentPtr];
if (current->fosterParenting) {
@@ -3451,10 +3529,10 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtm
}
void
-nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent* form)
+nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form)
{
flushCharacters();
- nsIContent* elt = createElement(ns, name, attributes, form);
+ nsIContent** elt = createElement(ns, name, attributes, form);
nsHtml5StackNode* current = stack[currentPtr];
if (current->fosterParenting) {
@@ -3472,7 +3550,7 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(PRInt32 ns, nsHtml5Eleme
{
flushCharacters();
nsIAtom* popName = elementName->name;
- nsIContent* elt = createElement(ns, popName, attributes);
+ nsIContent** elt = createElement(ns, popName, attributes);
nsHtml5StackNode* current = stack[currentPtr];
if (current->fosterParenting) {
@@ -3490,7 +3568,7 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFosterCamelCase(PRInt32 ns, nsH
{
flushCharacters();
nsIAtom* popName = elementName->camelCaseName;
- nsIContent* elt = createElement(ns, popName, attributes);
+ nsIContent** elt = createElement(ns, popName, attributes);
nsHtml5StackNode* current = stack[currentPtr];
if (current->fosterParenting) {
@@ -3504,10 +3582,10 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFosterCamelCase(PRInt32 ns, nsH
}
void
-nsHtml5TreeBuilder::appendVoidElementToCurrent(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent* form)
+nsHtml5TreeBuilder::appendVoidElementToCurrent(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form)
{
flushCharacters();
- nsIContent* elt = createElement(ns, name, attributes, form);
+ nsIContent** elt = createElement(ns, name, attributes, form);
nsHtml5StackNode* current = stack[currentPtr];
appendElement(elt, current->node);
elementPushed(ns, name, elt);
@@ -3536,7 +3614,7 @@ nsHtml5TreeBuilder::requestSuspension()
}
void
-nsHtml5TreeBuilder::setFragmentContext(nsIAtom* context, PRInt32 ns, nsIContent* node, PRBool quirks)
+nsHtml5TreeBuilder::setFragmentContext(nsIAtom* context, PRInt32 ns, nsIContent** node, PRBool quirks)
{
this->contextName = context;
nsHtml5Portability::retainLocal(context);
@@ -3547,7 +3625,7 @@ nsHtml5TreeBuilder::setFragmentContext(nsIAtom* context, PRInt32 ns, nsIContent*
this->quirks = quirks;
}
-nsIContent*
+nsIContent**
nsHtml5TreeBuilder::currentNode()
{
return stack[currentPtr]->node;
@@ -3580,7 +3658,7 @@ nsHtml5TreeBuilder::flushCharacters()
PRInt32 eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE);
nsHtml5StackNode* node = stack[eltPos];
- nsIContent* elt = node->node;
+ nsIContent** elt = node->node;
if (!eltPos) {
appendCharacters(elt, charBuffer, 0, charBufferLen);
charBufferLen = 0;
diff --git a/parser/html/nsHtml5TreeBuilder.h b/parser/html/nsHtml5TreeBuilder.h
index 03b164d4dcaf..cda5bc99af99 100644
--- a/parser/html/nsHtml5TreeBuilder.h
+++ b/parser/html/nsHtml5TreeBuilder.h
@@ -81,13 +81,13 @@ class nsHtml5TreeBuilder
PRBool fragment;
nsIAtom* contextName;
PRInt32 contextNamespace;
- nsIContent* contextNode;
+ nsIContent** contextNode;
jArray stack;
PRInt32 currentPtr;
jArray listOfActiveFormattingElements;
PRInt32 listPtr;
- nsIContent* formPointer;
- nsIContent* headPointer;
+ nsIContent** formPointer;
+ nsIContent** headPointer;
protected:
jArray charBuffer;
PRInt32 charBufferLen;
@@ -154,7 +154,7 @@ class nsHtml5TreeBuilder
void addAttributesToHtml(nsHtml5HtmlAttributes* attributes);
void pushHeadPointerOntoStack();
void reconstructTheActiveFormattingElements();
- void insertIntoFosterParent(nsIContent* child);
+ void insertIntoFosterParent(nsIContent** child);
PRBool isInStack(nsHtml5StackNode* node);
void pop();
void popOnEof();
@@ -169,38 +169,38 @@ class nsHtml5TreeBuilder
void appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
void appendToCurrentNodeAndPushElementMayFosterNoScoping(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
void appendToCurrentNodeAndPushElementMayFosterCamelCase(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
- void appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, nsIContent* form);
- void appendVoidElementToCurrentMayFoster(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent* form);
+ void appendToCurrentNodeAndPushElementMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, nsIContent** form);
+ void appendVoidElementToCurrentMayFoster(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
void appendVoidElementToCurrentMayFoster(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
void appendVoidElementToCurrentMayFosterCamelCase(PRInt32 ns, nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes);
- void appendVoidElementToCurrent(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent* form);
+ void appendVoidElementToCurrent(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
protected:
void accumulateCharacters(PRUnichar* buf, PRInt32 start, PRInt32 length);
void accumulateCharacter(PRUnichar c);
void requestSuspension();
- nsIContent* createElement(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes);
- nsIContent* createElement(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent* form);
- nsIContent* createHtmlElementSetAsRoot(nsHtml5HtmlAttributes* attributes);
- void detachFromParent(nsIContent* element);
- PRBool hasChildren(nsIContent* element);
- void appendElement(nsIContent* child, nsIContent* newParent);
- void appendChildrenToNewParent(nsIContent* oldParent, nsIContent* newParent);
- void insertFosterParentedChild(nsIContent* child, nsIContent* table, nsIContent* stackParent);
- void insertFosterParentedCharacters(PRUnichar* buf, PRInt32 start, PRInt32 length, nsIContent* table, nsIContent* stackParent);
- void appendCharacters(nsIContent* parent, PRUnichar* buf, PRInt32 start, PRInt32 length);
- void appendComment(nsIContent* parent, PRUnichar* buf, PRInt32 start, PRInt32 length);
+ nsIContent** createElement(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes);
+ nsIContent** createElement(PRInt32 ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form);
+ nsIContent** createHtmlElementSetAsRoot(nsHtml5HtmlAttributes* attributes);
+ void detachFromParent(nsIContent** element);
+ PRBool hasChildren(nsIContent** element);
+ void appendElement(nsIContent** child, nsIContent** newParent);
+ void appendChildrenToNewParent(nsIContent** oldParent, nsIContent** newParent);
+ void insertFosterParentedChild(nsIContent** child, nsIContent** table, nsIContent** stackParent);
+ void insertFosterParentedCharacters(PRUnichar* buf, PRInt32 start, PRInt32 length, nsIContent** table, nsIContent** stackParent);
+ void appendCharacters(nsIContent** parent, PRUnichar* buf, PRInt32 start, PRInt32 length);
+ void appendComment(nsIContent** parent, PRUnichar* buf, PRInt32 start, PRInt32 length);
void appendCommentToDocument(PRUnichar* buf, PRInt32 start, PRInt32 length);
- void addAttributesToElement(nsIContent* element, nsHtml5HtmlAttributes* attributes);
- void markMalformedIfScript(nsIContent* elt);
+ void addAttributesToElement(nsIContent** element, nsHtml5HtmlAttributes* attributes);
+ void markMalformedIfScript(nsIContent** elt);
void start(PRBool fragment);
void end();
void appendDoctypeToDocument(nsIAtom* name, nsString* publicIdentifier, nsString* systemIdentifier);
- void elementPushed(PRInt32 ns, nsIAtom* name, nsIContent* node);
- void elementPopped(PRInt32 ns, nsIAtom* name, nsIContent* node);
+ void elementPushed(PRInt32 ns, nsIAtom* name, nsIContent** node);
+ void elementPopped(PRInt32 ns, nsIAtom* name, nsIContent** node);
public:
- void setFragmentContext(nsIAtom* context, PRInt32 ns, nsIContent* node, PRBool quirks);
+ void setFragmentContext(nsIAtom* context, PRInt32 ns, nsIContent** node, PRBool quirks);
protected:
- nsIContent* currentNode();
+ nsIContent** currentNode();
public:
PRBool isScriptingEnabled();
void setScriptingEnabled(PRBool scriptingEnabled);
diff --git a/parser/html/nsHtml5TreeBuilderCppSupplement.h b/parser/html/nsHtml5TreeBuilderCppSupplement.h
index 11373ec49241..afae73e60176 100644
--- a/parser/html/nsHtml5TreeBuilderCppSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h
@@ -39,22 +39,13 @@
* ***** END LICENSE BLOCK ***** */
#include "nsContentErrors.h"
-#include "nsContentCreatorFunctions.h"
-#include "nsIDOMDocumentType.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsEvent.h"
#include "nsGUIEvent.h"
#include "nsEventDispatcher.h"
#include "nsContentUtils.h"
-#include "nsIDOMHTMLFormElement.h"
-#include "nsIFormControl.h"
#include "nsNodeUtils.h"
-#include "nsIStyleSheetLinkingElement.h"
-#include "nsTraceRefcnt.h"
-#include "mozAutoDocUpdate.h"
-#include "nsIScriptElement.h"
-#include "nsIDTD.h"
// this really should be autogenerated...
jArray nsHtml5TreeBuilder::ISINDEX_PROMPT = jArray();
@@ -65,6 +56,8 @@ nsHtml5TreeBuilder::nsHtml5TreeBuilder(nsHtml5TreeOpExecutor* aExec)
, formPointer(nsnull)
, headPointer(nsnull)
, mExecutor(aExec)
+ , mHandles(new nsIContent*[NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH])
+ , mHandlesUsed(0)
#ifdef DEBUG
, mActive(PR_FALSE)
#endif
@@ -79,54 +72,32 @@ nsHtml5TreeBuilder::~nsHtml5TreeBuilder()
mOpQueue.Clear();
}
-nsIContent*
+nsIContent**
nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes)
{
- nsIContent* newContent;
- nsCOMPtr nodeInfo = mExecutor->GetNodeInfoManager()->GetNodeInfo(aName, nsnull, aNamespace);
- NS_ASSERTION(nodeInfo, "Got null nodeinfo.");
- NS_NewElement(&newContent, nodeInfo->NamespaceID(), nodeInfo, PR_TRUE);
- NS_ASSERTION(newContent, "Element creation created null pointer.");
- PRInt32 len = aAttributes->getLength();
- for (PRInt32 i = 0; i < len; ++i) {
- newContent->SetAttr(aAttributes->getURI(i), aAttributes->getLocalName(i), aAttributes->getPrefix(i), *(aAttributes->getValue(i)), PR_FALSE);
- // XXX what to do with nsresult?
- }
- if (aNamespace != kNameSpaceID_MathML && (aName == nsHtml5Atoms::style || (aNamespace == kNameSpaceID_XHTML && aName == nsHtml5Atoms::link))) {
- nsCOMPtr ssle(do_QueryInterface(newContent));
- if (ssle) {
- ssle->InitStyleLinkElement(PR_FALSE);
- ssle->SetEnableUpdates(PR_FALSE);
-#if 0
- if (!aNodeInfo->Equals(nsGkAtoms::link, kNameSpaceID_XHTML)) {
- ssle->SetLineNumber(aLineNumber);
- }
-#endif
- }
- }
- return newContent;
+ nsIContent** content = AllocateContentHandle();
+ nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
+ // XXX if null, OOM!
+ treeOp->Init(aNamespace, aName, aAttributes, content);
+ return content;
}
-nsIContent*
-nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes, nsIContent* aFormElement)
+nsIContent**
+nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes, nsIContent** aFormElement)
{
- nsIContent* content = createElement(aNamespace, aName, aAttributes);
+ nsIContent** content = createElement(aNamespace, aName, aAttributes);
if (aFormElement) {
- nsCOMPtr formControl(do_QueryInterface(content));
- NS_ASSERTION(formControl, "Form-associated element did not implement nsIFormControl.");
- nsCOMPtr formElement(do_QueryInterface(aFormElement));
- NS_ASSERTION(formElement, "The form element doesn't implement nsIDOMHTMLFormElement.");
- if (formControl) { // avoid crashing on