mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1436812 P1 Make ServiceWorker MozPromise types exclusive so they can reject with ErrorResult values. r=baku
This commit is contained in:
parent
be5f3caad5
commit
d660ef1bc9
@ -81,14 +81,13 @@ ServiceWorkerContainer::ServiceWorkerContainer(nsIGlobalObject* aGlobal,
|
||||
|
||||
ServiceWorkerContainer::~ServiceWorkerContainer()
|
||||
{
|
||||
mReadyPromiseHolder.DisconnectIfExists();
|
||||
}
|
||||
|
||||
void
|
||||
ServiceWorkerContainer::DisconnectFromOwner()
|
||||
{
|
||||
mControllerWorker = nullptr;
|
||||
mReadyPromiseHolder.DisconnectIfExists();
|
||||
mReadyPromise = nullptr;
|
||||
DOMEventTargetHelper::DisconnectFromOwner();
|
||||
}
|
||||
|
||||
@ -267,7 +266,7 @@ ServiceWorkerContainer::GetRegistrations(ErrorResult& aRv)
|
||||
}
|
||||
}
|
||||
outer->MaybeResolve(regList);
|
||||
}, [self, outer] (nsresult aRv) {
|
||||
}, [self, outer] (ErrorResult&& aRv) {
|
||||
outer->MaybeReject(aRv);
|
||||
});
|
||||
|
||||
@ -341,14 +340,9 @@ ServiceWorkerContainer::GetRegistration(const nsAString& aURL,
|
||||
RefPtr<ServiceWorkerRegistration> reg =
|
||||
global->GetOrCreateServiceWorkerRegistration(aDescriptor);
|
||||
outer->MaybeResolve(reg);
|
||||
}, [self, outer] (nsresult aRv) {
|
||||
ErrorResult rv;
|
||||
Unused << self->GetGlobalIfValid(rv);
|
||||
if (rv.Failed()) {
|
||||
outer->MaybeReject(rv);
|
||||
return;
|
||||
}
|
||||
if (NS_SUCCEEDED(aRv)) {
|
||||
}, [self, outer] (ErrorResult&& aRv) {
|
||||
Unused << self->GetGlobalIfValid(aRv);
|
||||
if (!aRv.Failed()) {
|
||||
outer->MaybeResolveWithUndefined();
|
||||
return;
|
||||
}
|
||||
@ -388,7 +382,6 @@ ServiceWorkerContainer::GetReady(ErrorResult& aRv)
|
||||
mInner->GetReady(clientInfo.ref())->Then(
|
||||
global->EventTargetFor(TaskCategory::Other), __func__,
|
||||
[self, outer] (const ServiceWorkerRegistrationDescriptor& aDescriptor) {
|
||||
self->mReadyPromiseHolder.Complete();
|
||||
ErrorResult rv;
|
||||
nsIGlobalObject* global = self->GetGlobalIfValid(rv);
|
||||
if (rv.Failed()) {
|
||||
@ -399,10 +392,9 @@ ServiceWorkerContainer::GetReady(ErrorResult& aRv)
|
||||
global->GetOrCreateServiceWorkerRegistration(aDescriptor);
|
||||
NS_ENSURE_TRUE_VOID(reg);
|
||||
outer->MaybeResolve(reg);
|
||||
}, [self, outer] (nsresult aRv) {
|
||||
self->mReadyPromiseHolder.Complete();
|
||||
}, [self, outer] (ErrorResult&& aRv) {
|
||||
outer->MaybeReject(aRv);
|
||||
})->Track(mReadyPromiseHolder);
|
||||
});
|
||||
|
||||
return mReadyPromise;
|
||||
}
|
||||
|
@ -11,15 +11,22 @@
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class ErrorResult;
|
||||
|
||||
namespace dom {
|
||||
|
||||
class ServiceWorkerRegistrationData;
|
||||
class ServiceWorkerRegistrationDescriptor;
|
||||
|
||||
typedef MozPromise<ServiceWorkerRegistrationDescriptor, nsresult, false>
|
||||
// Note: These are exclusive promise types. Only one Then() or ChainTo()
|
||||
// call is allowed. This is necessary since ErrorResult cannot
|
||||
// be copied.
|
||||
|
||||
typedef MozPromise<ServiceWorkerRegistrationDescriptor, ErrorResult, true>
|
||||
ServiceWorkerRegistrationPromise;
|
||||
|
||||
typedef MozPromise<nsTArray<ServiceWorkerRegistrationDescriptor>, nsresult, false>
|
||||
typedef MozPromise<nsTArray<ServiceWorkerRegistrationDescriptor>, ErrorResult, true>
|
||||
ServiceWorkerRegistrationListPromise;
|
||||
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user