diff --git a/dom/media/PeerConnection.js b/dom/media/PeerConnection.js index cffa3b87dddc..887e89aa7751 100644 --- a/dom/media/PeerConnection.js +++ b/dom/media/PeerConnection.js @@ -622,8 +622,8 @@ RTCPeerConnection.prototype = { dispatchEvent: function(event) { // PC can close while events are firing if there is an async dispatch - // in c++ land - if (!this._closed) { + // in c++ land. But let through "closed" signaling and ice connection events. + if (!this._closed || this._inClose) { this.__DOM_IMPL__.dispatchEvent(event); } }, @@ -1139,11 +1139,13 @@ RTCPeerConnection.prototype = { if (this._closed) { return; } + this._closed = true; + this._inClose = true; this.changeIceConnectionState("closed"); this._localIdp.close(); this._remoteIdp.close(); this._impl.close(); - this._closed = true; + this._inClose = false; }, getLocalStreams: function() { diff --git a/dom/media/tests/mochitest/test_peerConnection_close.html b/dom/media/tests/mochitest/test_peerConnection_close.html index d32d7ad4ecd8..60ea634e530c 100644 --- a/dom/media/tests/mochitest/test_peerConnection_close.html +++ b/dom/media/tests/mochitest/test_peerConnection_close.html @@ -29,6 +29,16 @@ is(pc.signalingState, "closed", "signalingState is 'closed'"); is(pc.iceConnectionState, "closed", "iceConnectionState is 'closed'"); + // test that pc is really closed (and doesn't crash, bug 1259728) + try { + pc.getLocalStreams(); + } catch (e) { + exception = e; + } + is(exception && exception.name, "InvalidStateError", + "pc.getLocalStreams should throw when closed"); + exception = null; + try { pc.close(); } catch (e) {