Bug 1053407 - return DOMError rather than string in peerConnection callbacks. r=bz, r=jesup

This commit is contained in:
Jan-Ivar Bruaroey 2014-11-26 15:26:37 -05:00
parent e503445ffa
commit d486b47c0c
12 changed files with 34 additions and 44 deletions

View File

@ -1101,27 +1101,6 @@ RTCPeerConnection.prototype = {
}
};
function RTCError(code, message) {
this.name = this.reasonName[Math.min(code, this.reasonName.length - 1)];
this.message = (typeof message === "string")? message : this.name;
this.__exposedProps__ = { name: "rw", message: "rw" };
}
RTCError.prototype = {
// These strings must match those defined in the WebRTC spec.
reasonName: [
"NO_ERROR", // Should never happen -- only used for testing
"INVALID_CONSTRAINTS_TYPE",
"INVALID_CANDIDATE_TYPE",
"INVALID_MEDIASTREAM_TRACK",
"INVALID_STATE",
"INVALID_SESSION_DESCRIPTION",
"INCOMPATIBLE_SESSION_DESCRIPTION",
"INCOMPATIBLE_CONSTRAINTS",
"INCOMPATIBLE_MEDIASTREAMTRACK",
"INTERNAL_ERROR"
]
};
// This is a separate object because we don't want to expose it to DOM.
function PeerConnectionObserver() {
this._dompc = null;
@ -1138,6 +1117,24 @@ PeerConnectionObserver.prototype = {
this._dompc = dompc._innerObject;
},
newError: function(code, message) {
// These strings must match those defined in the WebRTC spec.
const reasonName = [
"",
"InternalError",
"InternalError",
"InvalidParameter",
"InvalidStateError",
"InvalidSessionDescriptionError",
"IncompatibleSessionDescriptionError",
"InternalError",
"IncompatibleMediaStreamTrackError",
"InternalError"
];
let name = reasonName[Math.min(code, reasonName.length - 1)];
return new this._dompc._win.DOMError(name, message);
},
dispatchEvent: function(event) {
this._dompc.dispatchEvent(event);
},
@ -1157,7 +1154,7 @@ PeerConnectionObserver.prototype = {
},
onCreateOfferError: function(code, message) {
this._dompc.callCB(this._dompc._onCreateOfferFailure, new RTCError(code, message));
this._dompc.callCB(this._dompc._onCreateOfferFailure, this.newError(code, message));
this._dompc._executeNext();
},
@ -1177,7 +1174,7 @@ PeerConnectionObserver.prototype = {
onCreateAnswerError: function(code, message) {
this._dompc.callCB(this._dompc._onCreateAnswerFailure,
new RTCError(code, message));
this.newError(code, message));
this._dompc._executeNext();
},
@ -1194,14 +1191,14 @@ PeerConnectionObserver.prototype = {
onSetLocalDescriptionError: function(code, message) {
this._localType = null;
this._dompc.callCB(this._dompc._onSetLocalDescriptionFailure,
new RTCError(code, message));
this.newError(code, message));
this._dompc._executeNext();
},
onSetRemoteDescriptionError: function(code, message) {
this._remoteType = null;
this._dompc.callCB(this._dompc._onSetRemoteDescriptionFailure,
new RTCError(code, message));
this.newError(code, message));
this._dompc._executeNext();
},
@ -1212,7 +1209,7 @@ PeerConnectionObserver.prototype = {
onAddIceCandidateError: function(code, message) {
this._dompc.callCB(this._dompc._onAddIceCandidateError,
new RTCError(code, message));
this.newError(code, message));
this._dompc._executeNext();
},
@ -1343,7 +1340,7 @@ PeerConnectionObserver.prototype = {
onGetStatsError: function(code, message) {
this._dompc.callCB(this._dompc._onGetStatsFailure,
new RTCError(code, message));
this.newError(code, message));
this._dompc._executeNext();
},
@ -1381,7 +1378,7 @@ PeerConnectionObserver.prototype = {
var pc = this._dompc;
pc._onReplaceTrackWithTrack = null;
pc._onReplaceTrackSender = null;
pc.callCB(pc._onReplaceTrackError, new RTCError(code, message));
pc.callCB(pc._onReplaceTrackError, this.newError(code, message));
},
foundIceCandidate: function(cand) {

View File

@ -59,13 +59,10 @@ interface IPeerConnection : nsISupports
/* Constants for 'name' in error callbacks */
const unsigned long kNoError = 0; // Test driver only
const unsigned long kInvalidConstraintsType = 1;
const unsigned long kInvalidCandidateType = 2;
const unsigned long kInvalidMediastreamTrack = 3;
const unsigned long kInvalidState = 4;
const unsigned long kInvalidSessionDescription = 5;
const unsigned long kIncompatibleSessionDescription = 6;
const unsigned long kIncompatibleConstraints = 7;
const unsigned long kIncompatibleMediaStreamTrack = 8;
const unsigned long kInternalError = 9;
const unsigned long kMaxErrorType = 9; // Same as final error

View File

@ -31,7 +31,7 @@
{candidate:"1 1 UDP 2130706431 192.168.2.1 50005 typ host",
sdpMLineIndex: 1}),
function(err) {
is(err.name, "INVALID_STATE", "Error is INVALID_STATE");
is(err.name, "InvalidStateError", "Error is InvalidStateError");
test.next();
} );
}

View File

@ -29,7 +29,7 @@
test.pcLocal._latest_offer.type="answer";
test.pcLocal.setLocalDescriptionAndFail(test.pcLocal._latest_offer,
function(err) {
is(err.name, "INVALID_STATE", "Error is INVALID_STATE");
is(err.name, "InvalidStateError", "Error is InvalidStateError");
test.next();
} );
}

View File

@ -29,7 +29,7 @@
test.pcLocal._latest_offer.type="answer";
test.pcLocal.setLocalDescriptionAndFail(test.pcLocal._latest_offer,
function(err) {
is(err.name, "INVALID_STATE", "Error is INVALID_STATE");
is(err.name, "InvalidStateError", "Error is InvalidStateError");
test.next();
} );
}

View File

@ -28,7 +28,7 @@
function (test) {
test.pcRemote.setLocalDescriptionAndFail(test.pcLocal._latest_offer,
function(err) {
is(err.name, "INVALID_STATE", "Error is INVALID_STATE");
is(err.name, "InvalidStateError", "Error is InvalidStateError");
test.next();
} );
}

View File

@ -29,7 +29,7 @@
test.pcLocal._latest_offer.type="answer";
test.pcRemote.setRemoteDescriptionAndFail(test.pcLocal._latest_offer,
function(err) {
is(err.name, "INVALID_STATE", "Error is INVALID_STATE");
is(err.name, "InvalidStateError", "Error is InvalidStateError");
test.next();
} );
}

View File

@ -29,7 +29,7 @@
test.pcLocal._latest_offer.type="answer";
test.pcLocal.setRemoteDescriptionAndFail(test.pcLocal._latest_offer,
function(err) {
is(err.name, "INVALID_STATE", "Error is INVALID_STATE");
is(err.name, "InvalidStateError", "Error is InvalidStateError");
test.next();
} );
}

View File

@ -28,7 +28,7 @@
function (test) {
test.pcLocal.setRemoteDescriptionAndFail(test.pcLocal._latest_offer,
function(err) {
is(err.name, "INVALID_STATE", "Error is INVALID_STATE");
is(err.name, "InvalidStateError", "Error is InvalidStateError");
test.next();
} );
}

View File

@ -8,7 +8,7 @@
*/
callback RTCSessionDescriptionCallback = void (mozRTCSessionDescription sdp);
callback RTCPeerConnectionErrorCallback = void (DOMString errorInformation);
callback RTCPeerConnectionErrorCallback = void (DOMError error);
callback VoidFunction = void ();
callback RTCStatsCallback = void (RTCStatsReport report);

View File

@ -226,7 +226,6 @@ public:
enum Error {
kNoError = 0,
kInvalidCandidateType = 2,
kInvalidMediastreamTrack = 3,
kInvalidState = 4,
kInvalidSessionDescription = 5,

View File

@ -549,7 +549,7 @@ typedef enum {
*
* PeerConnectionImpl.h
* Peerconnection.js
* nsIDOMPeerConnection.idl
* IPeerConnection.idl
*
* Yes, this is far from ideal, but there isn't an obviously cleaner
* way to deal with the situation within the constraints imposed on us
@ -558,13 +558,10 @@ typedef enum {
typedef enum {
PC_NO_ERROR = 0,
PC_INVALID_CONSTRAINTS_TYPE = 1,
PC_INVALID_CANDIDATE_TYPE = 2,
PC_INVALID_MEDIASTREAM_TRACK = 3,
PC_INVALID_STATE = 4,
PC_INVALID_SESSION_DESCRIPTION = 5,
PC_INCOMPATIBLE_SESSION_DESCRIPTION = 6,
PC_INCOMPATIBLE_CONSTRAINTS = 7,
PC_INCOMPATIBLE_MEDIA_STREAM_TRACK = 8,
PC_INTERNAL_ERROR = 9
} pc_error;