--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -527,22 +527,24 @@ RTCPeerConnection.prototype = {
// This wrapper helps implement legacy callbacks in a manner that produces
// correct line-numbers in errors, provided that methods validate their inputs
// before putting themselves on the pc's operations chain.
//
// It also serves as guard against settling promises past close().
_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
}
},
_wrapLegacyCallback: function(func) {
return result => {
@@ -735,17 +737,17 @@ RTCPeerConnection.prototype = {
onSuccess = optionsOrOnSuccess;
} else {
options = optionsOrOnSuccess;
}
return this._legacyCatchAndCloseGuard(onSuccess, onError, () => {
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);
}));
p = this._addIdentityAssertion(p, origin);
return p.then(sdp => Cu.cloneInto({ type: "offer", sdp: sdp }, this._win));
});
});
@@ -758,17 +760,17 @@ RTCPeerConnection.prototype = {
onSuccess = optionsOrOnSuccess;
} else {
options = optionsOrOnSuccess;
}
return this._legacyCatchAndCloseGuard(onSuccess, onError, () => {
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.
if (!this.remoteDescription) {
throw new this._win.DOMException("setRemoteDescription not called",
"InvalidStateError");
}
if (this.remoteDescription.type != "offer") {
@@ -832,17 +834,17 @@ RTCPeerConnection.prototype = {
if (desc.type !== "rollback" && !desc.sdp) {
throw new this._win.DOMException(
"Empty or null SDP provided to setLocalDescription",
"InvalidParameterError");
}
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);
})));
});
},
_validateIdentity: function(sdp, origin) {
@@ -920,30 +922,29 @@ RTCPeerConnection.prototype = {
"InvalidParameterError");
}
// Get caller's origin before hitting the promise chain
let origin = Cu.getWebIDLCallerPrincipal().origin;
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);
})).then(() => { this._updateCanTrickle(); });
if (desc.type === "rollback") {
return setRem;
}
// 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
});
});
},
setIdentityProvider: function(provider, protocol, username) {
this._checkClosed();
this._localIdp.setIdentityProvider(provider, protocol, username);
},
@@ -995,17 +996,17 @@ RTCPeerConnection.prototype = {
if (!c) {
// TODO: Implement processing for end-of-candidates (bug 1318167)
return Promise.resolve();
}
if (c.sdpMid === null && c.sdpMLineIndex === null) {
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);
}));
});
},
addStream: function(stream) {
@@ -1187,17 +1188,17 @@ RTCPeerConnection.prototype = {
changeIceConnectionState: function(state) {
this._iceConnectionState = state;
_globalPCList.notifyLifecycleObservers(this, "iceconnectionstatechange");
this.dispatchEvent(new this._win.Event("iceconnectionstatechange"));
},
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);
}));
});
},
createDataChannel: function(label, {