Fix bug 392318. r+sr+a=sicking.
authorbzbarsky@mit.edu
Thu, 20 Sep 2007 19:41:08 -0700
changeset 6170 b95425eafd955ae3c53547f50f7c35c3d89aa02a
parent 6169 4cab48babbcdfaa48f313cb8937228cc3075acce
child 6171 2ae619519786a39549239257b9ddd36d35806814
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs392318
milestone1.9a8pre
Fix bug 392318. r+sr+a=sicking.
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/base/test/Makefile.in
content/base/test/test_bug392318.html
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -2847,17 +2847,20 @@ nsDocument::DispatchContentLoadedEvents(
     }
   }
 }
 
 void
 nsDocument::EndLoad()
 {
   // Drop the ref to our parser, if any
-  mParser = nsnull;
+  if (mParser) {
+    mWeakSink = do_GetWeakReference(mParser->GetContentSink());
+    mParser = nsnull;
+  }
   
   NS_DOCUMENT_NOTIFY_OBSERVERS(EndLoad, (this));
 
   DispatchContentLoadedEvents();
   UnblockOnload(PR_TRUE);
 }
 
 void
@@ -4837,23 +4840,26 @@ nsDocument::CreateEventGroup(nsIDOMEvent
   NS_ADDREF(*aInstancePtrResult);
 
   return NS_OK;
 }
 
 void
 nsDocument::FlushPendingNotifications(mozFlushType aType)
 {
+  nsCOMPtr<nsIContentSink> sink;
+  if (mParser) {
+    sink = mParser->GetContentSink();
+  } else {
+    sink = do_QueryReferent(mWeakSink);
+  }
   // Determine if it is safe to flush the sink notifications
   // by determining if it safe to flush all the presshells.
-  if (mParser && (aType == Flush_Content || IsSafeToFlush())) {
-    nsCOMPtr<nsIContentSink> sink = mParser->GetContentSink();
-    if (sink) {
-      sink->FlushPendingNotifications(aType);
-    }
+  if (sink && (aType == Flush_Content || IsSafeToFlush())) {
+    sink->FlushPendingNotifications(aType);
   }
 
   // Should we be flushing pending binding constructors in here?
 
   nsPIDOMWindow *window = GetWindow();
 
   if (aType <= Flush_ContentAndNotify || !window) {
     // Nothing to do here
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -723,16 +723,21 @@ protected:
 
   // Array of owning references to all children
   nsAttrAndChildArray mChildren;
 
   // Pointer to our parser if we're currently in the process of being
   // parsed into.
   nsCOMPtr<nsIParser> mParser;
 
+  // Weak reference to our sink for in case we no longer have a parser.  This
+  // will allow us to flush out any pending stuff from the sink even if
+  // EndLoad() has already happened.
+  nsWeakPtr mWeakSink;
+
   nsCOMArray<nsIStyleSheet> mStyleSheets;
   nsCOMArray<nsIStyleSheet> mCatalogSheets;
 
   // Array of observers
   nsTObserverArray<nsIDocumentObserver> mObservers;
 
   // The document's script global object, the object from which the
   // document can get its script context and scope. This is the
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -82,16 +82,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug371576-3.html \
 		test_bug371576-4.html \
 		test_bug371576-5.html \
 		test_bug372086.html \
 		test_bug373181.xhtml \
 		test_bug375314.html \
 		test_bug382113.html \
 		test_bug390735.html \
+		test_bug392318.html \
 		test_bug392511.html \
 		test_bug395915.html \
 		bug382113_object.html \
 		test_CrossSiteXHR.html \
 		file_CrossSiteXHR_fail1.xml \
 		file_CrossSiteXHR_fail2.xml \
 		file_CrossSiteXHR_fail2.xml^headers^ \
 		file_CrossSiteXHR_fail3.xml \
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug392318.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=392318
+-->
+<head>
+  <title>Test for Bug 392318</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=392318">Mozilla Bug 392318</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+/** Test for Bug 392318 **/
+
+SimpleTest.waitForExplicitFinish();
+var testRan = false;
+
+function runTest() {
+  is($("t").offsetWidth, 202, "Unexpected offsetWidth");
+  is($("t").offsetHeight, 102, "Unexpected offsetHeight");
+  testRan = true;
+}
+
+document.addEventListener("DOMContentLoaded", runTest, false);
+
+addLoadEvent(function() {
+  is(testRan, true, "Onload firing too early");
+});
+
+addLoadEvent(SimpleTest.finish);
+</script>
+<!-- IMPORTANT: This sheet must come after the test that sets up the
+     DOMContentLoaded handler -->
+<link rel="stylesheet" type="text/css" href="data:text/css;%20charset=utf-8,%23t%20%7B%0Awidth%3A%20200px%3B%0Aborder%3A%201px%20solid%20black%3B%0Aheight%3A%20100px%3B%0A%7D">
+<div id="t"></div>
+</pre>
+</body>
+</html>
+