diff --git a/parser/html/nsHtml5StreamParser.cpp b/parser/html/nsHtml5StreamParser.cpp index 9f511983936e..ebece6ca64ec 100644 --- a/parser/html/nsHtml5StreamParser.cpp +++ b/parser/html/nsHtml5StreamParser.cpp @@ -992,6 +992,13 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer, mSpeculations.RemoveElementAt(0); if (mSpeculations.IsEmpty()) { // yes, it was still the only speculation. Now stop speculating + if (mTreeBuilder->IsDiscretionaryFlushSafe()) { + // However, before telling the executor to read from stage, flush + // any pending ops straight to the executor, because otherwise + // they remain unflushed until we get more data from the network. + mTreeBuilder->SetOpSink(mExecutor); + mTreeBuilder->Flush(); + } mTreeBuilder->SetOpSink(mExecutor->GetStage()); mExecutor->StartReadingFromStage(); mSpeculating = PR_FALSE; diff --git a/parser/htmlparser/tests/mochitest/Makefile.in b/parser/htmlparser/tests/mochitest/Makefile.in index 9bc8270947b0..9f93acdc4d94 100644 --- a/parser/htmlparser/tests/mochitest/Makefile.in +++ b/parser/htmlparser/tests/mochitest/Makefile.in @@ -62,6 +62,9 @@ _TEST_FILES = parser_datreader.js \ test_bug566879.html \ test_compatmode.html \ invalidchar.xml \ + test_bug568470.html \ + file_bug568470.sjs \ + file_bug568470-script.sjs \ $(NULL) libs:: $(_TEST_FILES) diff --git a/parser/htmlparser/tests/mochitest/file_bug568470-script.sjs b/parser/htmlparser/tests/mochitest/file_bug568470-script.sjs new file mode 100644 index 000000000000..6ba6ff08a6b1 --- /dev/null +++ b/parser/htmlparser/tests/mochitest/file_bug568470-script.sjs @@ -0,0 +1,14 @@ +function handleRequest(request, response) +{ + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "text/javascript", false); + response.write("var i = 0;"); + response.bodyOutputStream.flush(); + response.processAsync(); + var timer = Components.classes["@mozilla.org/timer;1"] + .createInstance(Components.interfaces.nsITimer); + timer.initWithCallback(function() { + response.finish(); + }, 500, Components.interfaces.nsITimer.TYPE_ONE_SHOT); +} + diff --git a/parser/htmlparser/tests/mochitest/file_bug568470.sjs b/parser/htmlparser/tests/mochitest/file_bug568470.sjs new file mode 100644 index 000000000000..2a5b7d8deaf8 --- /dev/null +++ b/parser/htmlparser/tests/mochitest/file_bug568470.sjs @@ -0,0 +1,19 @@ +function handleRequest(request, response) +{ + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "text/html", false); + response.write(""); + response.write("
+ ++ + + +