Bug 1287229 - port.disconnect should not throw r=billm

MozReview-Commit-ID: 7d8Zmb4OAd0

--HG--
extra : rebase_source : 6766832c0081679eadf1bdbc1576f8b554c68e3c
This commit is contained in:
Rob Wu 2016-07-15 22:46:42 -07:00
Родитель 28a234ae47
Коммит fcbcffffd6
2 изменённых файлов: 6 добавлений и 1 удалений

Просмотреть файл

@ -1048,7 +1048,9 @@ Port.prototype = {
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);

Просмотреть файл

@ -17,6 +17,9 @@ 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");