diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index 872dae53d63..2193e0bfac4 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -966,6 +966,19 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
return rv;
}
+void
+nsHTMLDocument::StopDocumentLoad()
+{
+ // If we're writing (i.e., there's been a document.open call), then
+ // nsDocument::StopDocumentLoad will do the wrong thing and simply terminate
+ // our parser.
+ if (mWriteState != eNotWriting) {
+ Close();
+ } else {
+ nsDocument::StopDocumentLoad();
+ }
+}
+
// static
void
nsHTMLDocument::DocumentWriteTerminationFunc(nsISupports *aRef)
@@ -2191,6 +2204,12 @@ nsHTMLDocument::Close()
nsresult rv = NS_OK;
if (mParser && mWriteState == eDocumentOpened) {
+ mPendingScripts.RemoveElement(GenerateParserKey());
+
+ mWriteState = mPendingScripts.Count() == 0
+ ? eDocumentClosed
+ : ePendingClose;
+
++mWriteLevel;
if (mContentType.EqualsLiteral("text/html")) {
rv = mParser->Parse(NS_LITERAL_STRING("