Bug 1322274: Make internal pc._legacyCatchAndCloseGuard responsible for returning content promise. r=mt

MozReview-Commit-ID: WovvgG4Olp

--HG--
extra : rebase_source : 0564f69f426d4267cfe5ae84c147c3d0039a6a51
This commit is contained in:
Jan-Ivar Bruaroey 2016-11-17 00:22:43 -05:00
Родитель b6996d911a
Коммит 884e4ceb56
1 изменённых файлов: 13 добавлений и 12 удалений

Просмотреть файл

@ -532,12 +532,14 @@ RTCPeerConnection.prototype = {
_legacyCatchAndCloseGuard: function(onSuccess, onError, func) {
if (!onSuccess) {
return func().then(v => (this._closed ? new Promise(() => {}) : v),
e => (this._closed ? new Promise(() => {}) : Promise.reject(e)));
return this._win.Promise.resolve(func())
.then(v => (this._closed ? new Promise(() => {}) : v),
e => (this._closed ? new Promise(() => {}) : Promise.reject(e)));
}
try {
return func().then(this._wrapLegacyCallback(onSuccess),
this._wrapLegacyCallback(onError));
return this._win.Promise.resolve(func())
.then(this._wrapLegacyCallback(onSuccess),
this._wrapLegacyCallback(onError));
} catch (e) {
this._wrapLegacyCallback(onError)(e);
return this._win.Promise.resolve(); // avoid webidl TypeError
@ -740,7 +742,7 @@ RTCPeerConnection.prototype = {
let origin = Cu.getWebIDLCallerPrincipal().origin;
return this._chain(() => {
let p = Promise.all([this.getPermission(), this._certificateReady])
.then(() => new this._win.Promise((resolve, reject) => {
.then(() => new Promise((resolve, reject) => {
this._onCreateOfferSuccess = resolve;
this._onCreateOfferFailure = reject;
this._impl.createOffer(options);
@ -763,7 +765,7 @@ RTCPeerConnection.prototype = {
let origin = Cu.getWebIDLCallerPrincipal().origin;
return this._chain(() => {
let p = Promise.all([this.getPermission(), this._certificateReady])
.then(() => new this._win.Promise((resolve, reject) => {
.then(() => new Promise((resolve, reject) => {
// We give up line-numbers in errors by doing this here, but do all
// state-checks inside the chain, to support the legacy feature that
// callers don't have to wait for setRemoteDescription to finish.
@ -837,7 +839,7 @@ RTCPeerConnection.prototype = {
}
return this._chain(() => this.getPermission()
.then(() => new this._win.Promise((resolve, reject) => {
.then(() => new Promise((resolve, reject) => {
this._onSetLocalDescriptionSuccess = resolve;
this._onSetLocalDescriptionFailure = reject;
this._impl.setLocalDescription(type, desc.sdp);
@ -925,7 +927,7 @@ RTCPeerConnection.prototype = {
return this._chain(() => {
let setRem = this.getPermission()
.then(() => new this._win.Promise((resolve, reject) => {
.then(() => new Promise((resolve, reject) => {
this._onSetRemoteDescriptionSuccess = resolve;
this._onSetRemoteDescriptionFailure = reject;
this._impl.setRemoteDescription(type, desc.sdp);
@ -937,8 +939,7 @@ RTCPeerConnection.prototype = {
// Do setRemoteDescription and identity validation in parallel
let validId = this._validateIdentity(desc.sdp, origin);
return this._win.Promise.all([setRem, validId])
.then(() => {}); // must return undefined
return Promise.all([setRem, validId]).then(() => {}); // return undefined
});
});
},
@ -1000,7 +1001,7 @@ RTCPeerConnection.prototype = {
throw new this._win.DOMException("Invalid candidate (both sdpMid and sdpMLineIndex are null).",
"TypeError");
}
return this._chain(() => new this._win.Promise((resolve, reject) => {
return this._chain(() => new Promise((resolve, reject) => {
this._onAddIceCandidateSuccess = resolve;
this._onAddIceCandidateError = reject;
this._impl.addIceCandidate(c.candidate, c.sdpMid || "", c.sdpMLineIndex);
@ -1192,7 +1193,7 @@ RTCPeerConnection.prototype = {
getStats: function(selector, onSuccess, onError) {
return this._legacyCatchAndCloseGuard(onSuccess, onError, () => {
return this._chain(() => new this._win.Promise((resolve, reject) => {
return this._chain(() => new Promise((resolve, reject) => {
this._onGetStatsSuccess = resolve;
this._onGetStatsFailure = reject;
this._impl.getStats(selector);