Bug 1766122 - Make PeerConnectionImpl::Chain return an already_AddRefed<Promise>. r=bwc

Differential Revision: https://phabricator.services.mozilla.com/D144511
This commit is contained in:
Peter Van der Beken
2022-04-26 09:24:16 +00:00
parent f2c4dde4e7
commit 25d42b6822
3 changed files with 11 additions and 9 deletions

View File

@@ -1172,27 +1172,29 @@ RefPtr<dom::Promise> PeerConnectionImpl::JSOperation::CallImpl() {
return op->Call();
}
dom::Promise* PeerConnectionImpl::Chain(dom::ChainedOperation& aOperation) {
already_AddRefed<dom::Promise> PeerConnectionImpl::Chain(
dom::ChainedOperation& aOperation) {
MOZ_RELEASE_ASSERT(!mChainingOperation);
mChainingOperation = true;
RefPtr<Operation> operation = new JSOperation(this, aOperation);
auto* promise = Chain(operation);
RefPtr<Promise> promise = Chain(operation);
mChainingOperation = false;
return promise;
return promise.forget();
}
// This is kinda complicated, but it is what the spec requires us to do. The
// core of what makes this complicated is the requirement that |aOperation| be
// run _immediately_ (without any Promise.Then!) if the operations chain is
// empty.
dom::Promise* PeerConnectionImpl::Chain(const RefPtr<Operation>& aOperation) {
already_AddRefed<dom::Promise> PeerConnectionImpl::Chain(
const RefPtr<Operation>& aOperation) {
// If connection.[[IsClosed]] is true, return a promise rejected with a newly
// created InvalidStateError.
if (IsClosed()) {
CSFLogDebug(LOGTAG, "%s:%d: Peer connection is closed", __FILE__, __LINE__);
RefPtr<dom::Promise> error = MakePromise();
error->MaybeRejectWithInvalidStateError("Peer connection is closed");
return error;
return error.forget();
}
// Append operation to [[Operations]].
@@ -1204,7 +1206,7 @@ dom::Promise* PeerConnectionImpl::Chain(const RefPtr<Operation>& aOperation) {
}
// This is the promise p from https://w3c.github.io/webrtc-pc/#dfn-chain
return aOperation->GetPromise();
return do_AddRef(aOperation->GetPromise());
}
void PeerConnectionImpl::RunNextOperation() {