Bug 1281366. Ensure that when unblocking the scriptloader we try to process scripts if we have _any_ scripts to process, not just parser-blocking ones. r=smaug, a=lizzard
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 23 Jun 2016 00:22:29 -0400
changeset 339807 e883641e228b3c5829752ea96c8900bdb88a4b94
parent 339806 d36dbe26035d26757ba6797ba446c92f807aeeca
child 339808 6683dd1bf7fd5823fdebd103b71c0f7cf9ec84d4
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, lizzard
bugs1281366
milestone49.0a2
Bug 1281366. Ensure that when unblocking the scriptloader we try to process scripts if we have _any_ scripts to process, not just parser-blocking ones. r=smaug, a=lizzard
dom/base/nsScriptLoader.cpp
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/XMLHttpRequest/xmlhttprequest-sync-not-hang-scriptloader-subframe.html
testing/web-platform/tests/XMLHttpRequest/xmlhttprequest-sync-not-hang-scriptloader.html
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -2024,17 +2024,22 @@ nsScriptLoader::EvaluateScript(nsScriptL
 
   context->SetProcessingScriptTag(oldProcessingScriptTag);
   return rv;
 }
 
 void
 nsScriptLoader::ProcessPendingRequestsAsync()
 {
-  if (mParserBlockingRequest || !mPendingChildLoaders.IsEmpty()) {
+  if (mParserBlockingRequest ||
+      !mXSLTRequests.isEmpty() ||
+      !mLoadedAsyncRequests.isEmpty() ||
+      !mNonAsyncExternalScriptInsertedRequests.isEmpty() ||
+      !mDeferRequests.isEmpty() ||
+      !mPendingChildLoaders.IsEmpty()) {
     NS_DispatchToCurrentThread(NewRunnableMethod(this,
                                                  &nsScriptLoader::ProcessPendingRequests));
   }
 }
 
 void
 nsScriptLoader::ProcessPendingRequests()
 {
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -36001,16 +36001,22 @@
           }
         ],
         "XMLHttpRequest/xmlhttprequest-sync-block-scripts.html": [
           {
             "path": "XMLHttpRequest/xmlhttprequest-sync-block-scripts.html",
             "url": "/XMLHttpRequest/xmlhttprequest-sync-block-scripts.html"
           }
         ],
+        "XMLHttpRequest/xmlhttprequest-sync-not-hang-scriptloader.html": [
+          {
+            "path": "XMLHttpRequest/xmlhttprequest-sync-not-hang-scriptloader.html",
+            "url": "/XMLHttpRequest/xmlhttprequest-sync-not-hang-scriptloader.html"
+          }
+        ],
         "dom/events/EventListener-incumbent-global-1.sub.html": [
           {
             "path": "dom/events/EventListener-incumbent-global-1.sub.html",
             "url": "/dom/events/EventListener-incumbent-global-1.sub.html"
           }
         ],
         "dom/events/EventListener-incumbent-global-2.sub.html": [
           {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/XMLHttpRequest/xmlhttprequest-sync-not-hang-scriptloader-subframe.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<script>
+  function secondScriptRan() {
+    parent.postMessage("done", "*");
+  }
+
+  function createSecondScript() {
+      var script = document.createElement("script");
+      script.src = "data:application/javascript,secondScriptRan()";
+      document.head.appendChild(script);
+
+      var xhr = new XMLHttpRequest();
+      xhr.open("GET", "data:,", false);
+      xhr.send();
+  }
+</script>
+<script src="data:application/javascript,createSecondScript()" defer></script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/XMLHttpRequest/xmlhttprequest-sync-not-hang-scriptloader.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>Ensure that an async script added during a defer script that then does a
+  sync XHR still runs</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<!--
+  We run the test in a subframe, because something in the testharness stuff
+  interferes with defer scripts -->
+<script>
+  var t = async_test();
+  onmessage = t.step_func_done(function(e) {
+    assert_equals(e.data, "done");
+  });
+</script>
+<iframe src="xmlhttprequest-sync-not-hang-scriptloader-subframe.html"></iframe>