Bug 1336811 - Clear mWaitingForOnStopRequest in CloseRequest. r=smaug a=jcristau
authorAndrew McCreight <continuation@gmail.com>
Fri, 17 Feb 2017 11:22:45 -0800
changeset 378639 29545b8aada77f12112e9362d3065342bcbf2d34
parent 378638 3707c5162a5aedee521dd9b1cc87aed40e00beb7
child 378640 6345d678d9c3fc12561ace81c2bada7d6b21d801
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, jcristau
bugs1336811
milestone53.0a2
Bug 1336811 - Clear mWaitingForOnStopRequest in CloseRequest. r=smaug a=jcristau Otherwise, if a tab is closed when we have a request pending, we'll end up leaking the page forever, due to CC optimizations. MozReview-Commit-ID: E5NC0jxWCur
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/tests/browser.ini
dom/xhr/tests/browser_xhr_onchange_leak.html
dom/xhr/tests/browser_xhr_onchange_leak.js
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -1030,16 +1030,17 @@ XMLHttpRequestMainThread::GetStatusText(
   } else {
     aStatusText.AssignLiteral("OK");
   }
 }
 
 void
 XMLHttpRequestMainThread::CloseRequest()
 {
+  mWaitingForOnStopRequest = false;
   if (mChannel) {
     mChannel->Cancel(NS_BINDING_ABORTED);
   }
   if (mTimeoutTimer) {
     mTimeoutTimer->Cancel();
   }
 }
 
new file mode 100644
--- /dev/null
+++ b/dom/xhr/tests/browser.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+support-files =
+  browser_xhr_onchange_leak.html
+[browser_blobFromFile.js]
+[browser_xhr_onchange_leak.js]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/xhr/tests/browser_xhr_onchange_leak.html
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test page for https://bugzilla.mozilla.org/show_bug.cgi?id=1336811
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test page for Bug 1336811</title>
+</head>
+<body onload="onload();">
+<p><span id="samplepage">sample page</span></p>
+<script type="application/javascript">
+  function onload() {
+   var request = new XMLHttpRequest;
+   request.open("GET", "about:blank");
+   request.onreadystatechange = function() {
+     request.foo = request;
+   }
+   request.foo = request;
+   request.send();
+   request.foo = request;
+  }
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/xhr/tests/browser_xhr_onchange_leak.js
@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+// Bug 1336811 - An XHR that has a .onreadystatechange waiting should
+// not leak forever once the tab is closed. CC optimizations need to be
+// turned off once it is closed.
+
+add_task(function* test() {
+  const url = "http://mochi.test:8888/browser/dom/xhr/tests/browser_xhr_onchange_leak.html";
+  let newTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
+  let browser = gBrowser.selectedBrowser;
+  let done = yield ContentTask.spawn(browser,{}, function*(browser){
+    let doc = content.document;
+    let promise = ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", true);
+    content.location = "about:home";
+    yield promise;
+    return true;
+  });
+  is(done, true, "need to check something");
+  yield BrowserTestUtils.removeTab(newTab);
+});