Bug 1287229 - port.disconnect should not throw r=billm
authorRob Wu <rob@robwu.nl>
Fri, 15 Jul 2016 22:46:42 -0700
changeset 305521 e8e2132fa883f916ed763f890c9cbdfddbf8cdf1
parent 305520 7c026e26932d9e32d0a7c7fdef330917c52a9620
child 305522 4dd2466573eceb92c70f8436ad54bb400ae4110b
push id30703
push userwmccloskey@mozilla.com
push dateTue, 19 Jul 2016 23:57:50 +0000
treeherderautoland@e8e2132fa883 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1287229
milestone50.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 1287229 - port.disconnect should not throw r=billm MozReview-Commit-ID: 7d8Zmb4OAd0
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/components/extensions/test/mochitest/test_ext_runtime_disconnect.html
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -1043,17 +1043,19 @@ Port.prototype = {
       }
 
       this.handleDisconnection();
     }
   },
 
   disconnect() {
     if (this.disconnected) {
-      throw new this.context.contentWindow.Error("Attempt to disconnect() a disconnected port");
+      // disconnect() may be called without side effects even after the port is
+      // closed - https://developer.chrome.com/extensions/runtime#type-Port
+      return;
     }
     this.handleDisconnection();
     this.messageManager.sendAsyncMessage(this.disconnectName);
   },
 
   close() {
     this.disconnect();
   },
--- a/toolkit/components/extensions/test/mochitest/test_ext_runtime_disconnect.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_runtime_disconnect.html
@@ -12,16 +12,19 @@
 
 <script type="text/javascript">
 "use strict";
 
 function backgroundScript() {
   browser.runtime.onConnect.addListener(port => {
     browser.test.assertEq(port.name, "ernie", "port name correct");
     port.onDisconnect.addListener(() => {
+      // Closing an already-disconnected port is a no-op.
+      port.disconnect();
+      port.disconnect();
       browser.test.sendMessage("disconnected");
     });
     browser.test.sendMessage("connected");
   });
 }
 
 function contentScript() {
   browser.runtime.connect({name: "ernie"});