Bug 791330: Suppress calls to PC after close has been called; r=anant
authorEKR <ekr@rtfm.com>
Sat, 20 Oct 2012 09:43:57 -0700
changeset 111124 585b254104f26e53fb752157b31b1813702c08c2
parent 111123 6a24636cd4a2751dd04ed7e7d314184885406e00
child 111125 c127ae4496a3acb6a95dce93d782cb884859d1e9
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersanant
bugs791330
milestone19.0a1
Bug 791330: Suppress calls to PC after close has been called; r=anant
dom/media/PeerConnection.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -118,16 +118,17 @@ SessionDescription.prototype = {
   }
 };
 
 function PeerConnection() {
   this._queue = [];
 
   this._pc = null;
   this._observer = null;
+  this._closed = false;
 
   this._onCreateOfferSuccess = null;
   this._onCreateOfferFailure = null;
   this._onCreateAnswerSuccess = null;
   this._onCreateAnswerFailure = null;
 
   /**
    * Everytime we get a request from content, we put it in the queue. If
@@ -198,16 +199,19 @@ PeerConnection.prototype = {
 
   /**
    * Add a function to the queue or run it immediately if the queue is empty.
    * Argument is an object with the func, args and wait properties; wait should
    * be set to true if the function has a success/error callback that will
    * call _executeNext, false if it doesn't have a callback.
    */
   _queueOrRun: function(obj) {
+    if (this._closed) {
+	return;
+    }
     if (!this._pending) {
       obj.func.apply(this, obj.args);
       if (obj.wait) {
         this._pending = true;
       }
     } else {
       this._queue.push(obj);
     }
@@ -415,16 +419,17 @@ PeerConnection.prototype = {
   },
 
   close: function() {
     this._queueOrRun({
       func: this._pc.close,
       args: [],
       wait: false
     });
+    this._closed = true;
   },
 
   get localStreams() {
     return this._pc.localStreams;
   },
   get remoteStreams() {
     return this._pc.remoteStreams;
   },