Bug 619109 - Define the insertion point before and undefine after the synchronous script execution events. r=bzbarsky.
authorHenri Sivonen <hsivonen@hsivonen.fi>
Fri, 29 Oct 2010 12:22:10 +0300
changeset 312388 3b722968c9d4c02152b787c70782971586b6c0fd
parent 312387 57a1ca19b38c948ae15b3977c4f719f175e8d467
child 312389 f615741c86eed245173be02078053f4801403ba4
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs619109
milestone51.0a1
Bug 619109 - Define the insertion point before and undefine after the synchronous script execution events. r=bzbarsky. MozReview-Commit-ID: FAriD6I2m2L
dom/base/nsScriptLoader.cpp
parser/htmlparser/tests/reftest/bug592656-1-ref.html
parser/htmlparser/tests/reftest/bug592656-1.html
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -1913,16 +1913,18 @@ nsScriptLoader::ProcessRequest(nsScriptL
 
   nsCOMPtr<nsIScriptElement> oldParserInsertedScript;
   uint32_t parserCreated = aRequest->mElement->GetParserCreated();
   if (parserCreated) {
     oldParserInsertedScript = mCurrentParserInsertedScript;
     mCurrentParserInsertedScript = aRequest->mElement;
   }
 
+  aRequest->mElement->BeginEvaluating();
+
   FireScriptAvailable(NS_OK, aRequest);
 
   // The window may have gone away by this point, in which case there's no point
   // in trying to run the script.
   nsCOMPtr<nsIDocument> master = mDocument->MasterDocument();
   {
     // Try to perform a microtask checkpoint
     nsAutoMicroTask mt;
@@ -1943,31 +1945,31 @@ nsScriptLoader::ProcessRequest(nsScriptL
     runScript = false;
   }
 
   nsresult rv = NS_OK;
   if (runScript) {
     if (doc) {
       doc->BeginEvaluatingExternalScript();
     }
-    aRequest->mElement->BeginEvaluating();
     rv = EvaluateScript(aRequest);
-    aRequest->mElement->EndEvaluating();
     if (doc) {
       doc->EndEvaluatingExternalScript();
     }
 
     nsContentUtils::DispatchTrustedEvent(scriptElem->OwnerDoc(),
                                          scriptElem,
                                          NS_LITERAL_STRING("afterscriptexecute"),
                                          true, false);
   }
 
   FireScriptEvaluated(rv, aRequest);
 
+  aRequest->mElement->EndEvaluating();
+
   if (parserCreated) {
     mCurrentParserInsertedScript = oldParserInsertedScript;
   }
 
   if (aRequest->mOffThreadToken) {
     // The request was parsed off-main-thread, but the result of the off
     // thread parse was not actually needed to process the request
     // (disappearing window, some other error, ...). Finish the
--- a/parser/htmlparser/tests/reftest/bug592656-1-ref.html
+++ b/parser/htmlparser/tests/reftest/bug592656-1-ref.html
@@ -1,9 +1,9 @@
 <!DOCTYPE html>
 <html>
 <head>
 <title>document.write() from script-inserted inline scripts and script@onload</title>
 </head>
 <body>
-1 2 3 4 5 6 7 8 13 14 15
+1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 </body>
 </html>
--- a/parser/htmlparser/tests/reftest/bug592656-1.html
+++ b/parser/htmlparser/tests/reftest/bug592656-1.html
@@ -4,16 +4,20 @@
 <title>document.write() from script-inserted inline scripts and script@onload</title>
 </head>
 <body>
 1
 <script>
 function write(num) {
   document.write(num + " ");
 }
+function scriptload() {
+document.write("\u003Cscript src='data:text/javascript,write(9)'>\u003C/script> 10 \u003Cscript>write(11)\u003C/script>");
+write(12);
+}
 write(2);
 document.write("\u003Cscript src='data:text/javascript,write(3)'>\u003C/script> 4 \u003Cscript>write(5)\u003C/script>");
 var s = document.createElement("script");
 s.textContent = "write(6)";
 document.body.appendChild(s);
 write(7);
 document.write("\u003Cscript src='data:text/javascript,write(8)' onload='scriptload()'>\u003C/script> 13 \u003Cscript>write(14)\u003C/script>");
 write(15);