Bug 1178076 - MessagePort should not set listeners nor workerFeature when neutered, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 29 Jun 2015 14:52:49 +0100
changeset 281340 f8de1464929b3c73a3cba30a982e4aad733eb724
parent 281339 17577ea6b9c32fe646b9f5d34ac468043154a9e1
child 281341 9c89dfef9f2cc4bdc2a7950b43bc0a0b5b0b72b8
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1178076
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1178076 - MessagePort should not set listeners nor workerFeature when neutered, r=smaug
dom/messagechannel/MessagePort.cpp
dom/messagechannel/tests/mochitest.ini
dom/messagechannel/tests/test_messageChannel_bug1178076.html
--- a/dom/messagechannel/MessagePort.cpp
+++ b/dom/messagechannel/MessagePort.cpp
@@ -381,18 +381,23 @@ MessagePort::Initialize(const nsID& aUUI
   mIdentifier->uuid() = aUUID;
   mIdentifier->destinationUuid() = aDestinationUUID;
   mIdentifier->sequenceId() = aSequenceID;
 
   mState = aState;
   mNextStep = eNextStepNone;
 
   if (mNeutered) {
+    // If this port is neutered we don't want to keep it alive artificially nor
+    // we want to add listeners or workerFeatures.
     mState = eStateDisentangled;
-  } else if (mState == eStateEntangling) {
+    return;
+  }
+
+  if (mState == eStateEntangling) {
     ConnectToPBackground();
   } else {
     MOZ_ASSERT(mState == eStateUnshippedEntangled);
   }
 
   // The port has to keep itself alive until it's entangled.
   UpdateMustKeepAlive();
 
--- a/dom/messagechannel/tests/mochitest.ini
+++ b/dom/messagechannel/tests/mochitest.ini
@@ -19,8 +19,9 @@ support-files =
 [test_messageChannel_transferable.html]
 [test_messageChannel_unshipped.html]
 [test_messageChannel_worker.html]
 [test_messageChannel_selfTransferring.html]
 [test_messageChannel_sharedWorker.html]
 [test_messageChannel_sharedWorker2.html]
 [test_messageChannel_any.html]
 [test_messageChannel_forceClose.html]
+[test_messageChannel_bug1178076.html]
new file mode 100644
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_bug1178076.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1178076
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1178076</title>
+  <script type="application/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=1178076">Mozilla Bug 1178076</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+  <script type="application/javascript">
+
+  function runTest() {
+    onmessage = function(e) {
+      ok(e.ports.length, 1, "A port has been received!");
+      var port = e.ports[0];
+      ok(port instanceof MessagePort, "This is a port.");
+      SimpleTest.finish();
+    }
+
+    // In this test we want to see if we leak a neutered port closing port1
+    // and sending port2 to the same window. This operation doesn't involve IPC.
+    var mc = new MessageChannel();
+    mc.port1.close();
+    postMessage(42, '*', [mc.port2]);
+  }
+
+  SimpleTest.waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
+  </script>
+</body>
+</html>