From 1bc4070ba9cb5683e25a2d1ed098bc1b18b1e6d3 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Sat, 11 May 2013 20:48:29 -0400 Subject: [PATCH] Bug 823512: Part 3: Deprecated API calls emit warnings to web-console. r=jesup,bz --- dom/media/PeerConnection.js | 71 +++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/dom/media/PeerConnection.js b/dom/media/PeerConnection.js index 6c327d76cc07..8d4487ab5aa4 100644 --- a/dom/media/PeerConnection.js +++ b/dom/media/PeerConnection.js @@ -474,6 +474,44 @@ RTCPeerConnection.prototype = { this.__DOM_IMPL__.dispatchEvent(event); }, + // Log error message to web console and window.onerror, if present. + reportError: function(msg, file, line) { + this.reportMsg(msg, file, line, Ci.nsIScriptError.exceptionFlag); + }, + + reportWarning: function(msg, file, line) { + this.reportMsg(msg, file, line, Ci.nsIScriptError.warningFlag); + }, + + reportMsg: 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); + + if (flag != Ci.nsIScriptError.warningFlag) { + // Safely call onerror directly if present (necessary for testing) + try { + if (typeof this._win.onerror === "function") { + this._win.onerror(msg, file, line); + } + } catch(e) { + // If onerror itself throws, service it. + try { + let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError); + scriptError.initWithWindowID(e.message, e.fileName, null, e.lineNumber, + 0, Ci.nsIScriptError.exceptionFlag, + "content javascript", + this._winID); + console.logMessage(scriptError); + } catch(e) {} + } + } + }, + getEH: function(type) { return this.__DOM_IMPL__.getEventHandler(type); }, @@ -503,7 +541,7 @@ RTCPeerConnection.prototype = { }, deprecated: function(name) { - dump(name + " is deprecated!\n"); + this.reportWarning(name + " is deprecated!", null, 0); }, createOffer: function(onSuccess, onError, constraints) { @@ -852,40 +890,11 @@ PeerConnectionObserver.prototype = { // A content script (user-provided) callback threw an error. We don't // want this to take down peerconnection, but we still want the user // to see it, so we catch it, report it, and move on. - this.reportError(e.message, e.fileName, e.lineNumber); + this._dompc.reportError(e.message, e.fileName, e.lineNumber); } } }, - // Log error message to web console and window.onerror, if present. - reportError: function(msg, file, line) { - let scriptErrorClass = Cc["@mozilla.org/scripterror;1"]; - let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError); - scriptError.initWithWindowID(msg, file, null, line,0, - Ci.nsIScriptError.exceptionFlag, - "content javascript", this._dompc._winID); - let console = Cc["@mozilla.org/consoleservice;1"]. - getService(Ci.nsIConsoleService); - console.logMessage(scriptError); - - // Safely call onerror directly if present (necessary for testing) - try { - if (typeof this._dompc._win.onerror === "function") { - this._dompc._win.onerror(msg, file, line); - } - } catch(e) { - // If onerror itself throws, service it. - try { - let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError); - scriptError.initWithWindowID(e.message, e.fileName, null, e.lineNumber, - 0, Ci.nsIScriptError.exceptionFlag, - "content javascript", - this._dompc._winID); - console.logMessage(scriptError); - } catch(e) {} - } - }, - onCreateOfferSuccess: function(sdp) { this.callCB(this._dompc._onCreateOfferSuccess, new this._dompc._win.mozRTCSessionDescription({ type: "offer",