Bug 1313966 - Add deprecation warnings to writable RTCSessionDescription. r=drno,smaug
authorJan-Ivar Bruaroey <jib@mozilla.com>
Tue, 08 Nov 2016 17:50:24 -0500
changeset 440386 1ef70e4bf1a748d3eccafb55e0f5b370a1d848bb
parent 440385 91c099f8ec09b1fbf9b0159210f63a25f63d7208
child 440387 ef895cb3fb7d0b9c0d09e2fd773951e696d69d0f
push id36216
push userbmo:ato@mozilla.com
push dateThu, 17 Nov 2016 13:57:13 +0000
reviewersdrno, smaug
bugs1313966
milestone53.0a1
Bug 1313966 - Add deprecation warnings to writable RTCSessionDescription. r=drno,smaug MozReview-Commit-ID: AZAjbgJHTAc
dom/media/PeerConnection.js
dom/webidl/RTCSessionDescription.webidl
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -35,16 +35,26 @@ const PC_SESSION_CID = Components.ID("{1
 const PC_MANAGER_CID = Components.ID("{7293e901-2be3-4c02-b4bd-cbef6fc24f78}");
 const PC_STATS_CID = Components.ID("{7fe6e18b-0da3-4056-bf3b-440ef3809e06}");
 const PC_STATIC_CID = Components.ID("{0fb47c47-a205-4583-a9fc-cbadf8c95880}");
 const PC_SENDER_CID = Components.ID("{4fff5d46-d827-4cd4-a970-8fd53977440e}");
 const PC_RECEIVER_CID = Components.ID("{d974b814-8fde-411c-8c45-b86791b81030}");
 const PC_COREQUEST_CID = Components.ID("{74b2122d-65a8-4824-aa9e-3d664cb75dc2}");
 const PC_DTMF_SENDER_CID = Components.ID("{3610C242-654E-11E6-8EC0-6D1BE389A607}");
 
+function logMsg(msg, file, line, flag, winID) {
+  let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
+  let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
+  scriptError.initWithWindowID(msg, file, null, line, 0, flag,
+                               "content javascript", winID);
+  let console = Cc["@mozilla.org/consoleservice;1"].
+  getService(Ci.nsIConsoleService);
+  console.logMessage(scriptError);
+};
+
 // Global list of PeerConnection objects, so they can be cleaned up when
 // a page is torn down. (Maps inner window ID to an array of PC objects).
 function GlobalPCList() {
   this._list = {};
   this._networkdown = false; // XXX Need to query current state somehow
   this._lifecycleobservers = {};
   this._nextId = 1;
   Services.obs.addObserver(this, "inner-window-destroyed", true);
@@ -233,31 +243,59 @@ RTCIceCandidate.prototype = {
 
   __init: function(dict) {
     this.candidate = dict.candidate;
     this.sdpMid = dict.sdpMid;
     this.sdpMLineIndex = ("sdpMLineIndex" in dict)? dict.sdpMLineIndex : null;
   }
 };
 
-function RTCSessionDescription() {
-  this.type = this.sdp = null;
-}
+function RTCSessionDescription() {}
 RTCSessionDescription.prototype = {
   classDescription: "RTCSessionDescription",
   classID: PC_SESSION_CID,
   contractID: PC_SESSION_CONTRACT,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
                                          Ci.nsIDOMGlobalPropertyInitializer]),
 
-  init: function(win) { this._win = win; },
+  init: function(win) {
+    this._win = win;
+    this._winID = this._win.QueryInterface(Ci.nsIInterfaceRequestor)
+    .getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
+  },
+
+  __init: function({ type, sdp }) {
+    Object.assign(this, { _type: type, _sdp: sdp });
+  },
+
+  get type() { return this._type; },
+  set type(type) {
+    this.warn();
+    this._type = type;
+  },
 
-  __init: function(dict) {
-    this.type = dict.type;
-    this.sdp  = dict.sdp;
+  get sdp() { return this._sdp; },
+  set sdp(sdp) {
+    this.warn();
+    this._sdp = sdp;
+  },
+
+  warn: function() {
+    if (!this._warned) {
+      // Warn once per RTCSessionDescription about deprecated writable usage.
+      this.logWarning("RTCSessionDescription's members are readonly! " +
+                      "Writing to them is deprecated and will break soon!");
+      this._warned = true;
+    }
+  },
+
+  logWarning: function(msg) {
+    let err = this._win.Error();
+    logMsg(msg, err.fileName, err.lineNumber, Ci.nsIScriptError.warningFlag,
+           this._winID);
   }
 };
 
 function RTCStatsReport(win, dict) {
   this._win = win;
   this._pcid = dict.pcid;
   this._report = convertToRTCStatsReport(dict);
 }
@@ -630,23 +668,17 @@ RTCPeerConnection.prototype = {
   },
 
   logStackMsg: function(msg, flag) {
     let err = this._win.Error();
     this.logMsg(msg, err.fileName, err.lineNumber, flag);
   },
 
   logMsg: function(msg, file, line, flag) {
-    let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
-    let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
-    scriptError.initWithWindowID(msg, file, null, line, 0, flag,
-                                 "content javascript", this._winID);
-    let console = Cc["@mozilla.org/consoleservice;1"].
-      getService(Ci.nsIConsoleService);
-    console.logMessage(scriptError);
+    return logMsg(msg, file, line, flag, this._winID);
   },
 
   getEH: function(type) {
     return this.__DOM_IMPL__.getEventHandler(type);
   },
 
   setEH: function(type, handler) {
     this.__DOM_IMPL__.setEventHandler(type, handler);
--- a/dom/webidl/RTCSessionDescription.webidl
+++ b/dom/webidl/RTCSessionDescription.webidl
@@ -10,21 +10,22 @@
 enum RTCSdpType {
   "offer",
   "pranswer",
   "answer",
   "rollback"
 };
 
 dictionary RTCSessionDescriptionInit {
-  RTCSdpType? type = null;
-  DOMString? sdp = "";
+  required RTCSdpType type;
+  DOMString sdp = "";
 };
 
 [Pref="media.peerconnection.enabled",
  JSImplementation="@mozilla.org/dom/rtcsessiondescription;1",
  Constructor(optional RTCSessionDescriptionInit descriptionInitDict)]
 interface RTCSessionDescription {
-  attribute RTCSdpType? type;
-  attribute DOMString? sdp;
+  // These should be readonly, but writing causes deprecation warnings for a bit
+  attribute RTCSdpType type;
+  attribute DOMString sdp;
 
   jsonifier;
 };