Index: content/html/document/src/nsHTMLDocument.cpp
===================================================================
RCS file: /home/bzbarsky/mozilla/cvs-mirror/mozilla/content/html/document/src/nsHTMLDocument.cpp,v
retrieving revision 3.664
diff -u -p -d -8 -r3.664 nsHTMLDocument.cpp
--- content/html/document/src/nsHTMLDocument.cpp 30 Mar 2006 18:40:40 -0000 3.664
+++ content/html/document/src/nsHTMLDocument.cpp 3 Apr 2006 22:22:55 -0000
@@ -117,14 +117,15 @@
#include "nsICharsetResolver.h"
#include "nsICachingChannel.h"
#include "nsICacheEntryDescriptor.h"
#include "nsIJSContextStack.h"
#include "nsIDocumentViewer.h"
#include "nsIWyciwygChannel.h"
#include "nsIScriptError.h"
+#include "nsArray.h"
#include "nsIPrompt.h"
//AHMED 12-2
#include "nsBidiUtils.h"
#include "nsIEditingSession.h"
#include "nsNodeInfoManager.h"
@@ -953,31 +954,47 @@ nsHTMLDocument::StartDocumentLoad(const
return rv;
}
// static
void
nsHTMLDocument::DocumentWriteTerminationFunc(nsISupports *aRef)
{
- nsIDocument *doc = NS_REINTERPRET_CAST(nsIDocument *, aRef);
- nsHTMLDocument *htmldoc = NS_REINTERPRET_CAST(nsHTMLDocument *, doc);
+ nsCOMPtr arr = do_QueryInterface(aRef);
+ NS_ASSERTION(arr, "Must have array!");
+
+ nsCOMPtr doc = do_QueryElementAt(arr, 0);
+ NS_ASSERTION(doc, "Must have document!");
+
+ nsCOMPtr parser = do_QueryElementAt(arr, 1);
+ NS_ASSERTION(parser, "Must have parser!");
+
+ nsHTMLDocument *htmldoc = NS_STATIC_CAST(nsHTMLDocument *,
+ NS_STATIC_CAST(nsIDocument*,
+ doc.get()));
+
+ // Check whether htmldoc still has the same parser. If not, it's
+ // not for us to mess with it.
+ if (htmldoc->mParser != parser) {
+ return;
+ }
// If the document is in the middle of a document.write() call, this
// most likely means that script on a page document.write()'d out a
// script tag that did location="..." and we're right now finishing
// up executing the script that was written with
// document.write(). Since there's still script on the stack (the
// script that called document.write()) we don't want to release the
// parser now, that would cause the next document.write() call to
// cancel the load that was initiated by the location="..." in the
// script that was written out by document.write().
if (!htmldoc->mWriteLevel && !htmldoc->mIsWriting) {
- // Release the documents parser so that the call to EndLoad()
+ // Release the document's parser so that the call to EndLoad()
// doesn't just return early and set the termination function again.
htmldoc->mParser = nsnull;
}
htmldoc->EndLoad();
}
@@ -1005,25 +1022,35 @@ nsHTMLDocument::EndLoad()
// won't end up creating a new parser and interrupting other
// loads that were started while the script was
// running. I.e. this makes the following case work as
// expected:
//
// document.write("foo");
// location.href = "http://www.mozilla.org";
// document.write("bar");
-
- nsresult rv =
- scx->SetTerminationFunction(DocumentWriteTerminationFunc,
- NS_STATIC_CAST(nsIDocument *, this));
- // If we fail to set the termination function, just go ahead
- // and EndLoad now. The slight bugginess involved is better
- // than leaking.
+
+ nsCOMPtr arr;
+ nsresult rv = NS_NewArray(getter_AddRefs(arr));
if (NS_SUCCEEDED(rv)) {
- return;
+ rv = arr->AppendElement(NS_STATIC_CAST(nsIDocument*, this),
+ PR_FALSE);
+ if (NS_SUCCEEDED(rv)) {
+ rv = arr->AppendElement(mParser, PR_FALSE);
+ if (NS_SUCCEEDED(rv)) {
+ rv = scx->SetTerminationFunction(DocumentWriteTerminationFunc,
+ arr);
+ // If we fail to set the termination function, just go ahead
+ // and EndLoad now. The slight bugginess involved is better
+ // than leaking.
+ if (NS_SUCCEEDED(rv)) {
+ return;
+ }
+ }
+ }
}
}
}
}
}
// Reset this now, since we're really done "loading" this document.written
// document.