mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1146365 - Add support of union type for FetchEvent.respondWith. r=nsm, r=ehsan
This commit is contained in:
parent
d82e49937f
commit
19a398b233
@ -17,8 +17,8 @@ interface FetchEvent : Event {
|
||||
readonly attribute Client? client; // The window issuing the request.
|
||||
readonly attribute boolean isReload;
|
||||
|
||||
[Throws] void respondWith(Promise<Response> r);
|
||||
[Throws] void respondWith(Response r);
|
||||
[Throws]
|
||||
void respondWith((Response or Promise<Response>) r);
|
||||
};
|
||||
|
||||
dictionary FetchEventInit : EventInit {
|
||||
|
@ -282,37 +282,32 @@ RespondWithHandler::CancelRequest()
|
||||
} // anonymous namespace
|
||||
|
||||
void
|
||||
FetchEvent::RespondWith(Promise& aPromise, ErrorResult& aRv)
|
||||
FetchEvent::RespondWith(const ResponseOrPromise& aArg, ErrorResult& aRv)
|
||||
{
|
||||
if (mWaitToRespond) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<Promise> promise;
|
||||
|
||||
if (aArg.IsResponse()) {
|
||||
nsRefPtr<Response> res = &aArg.GetAsResponse();
|
||||
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(worker);
|
||||
worker->AssertIsOnWorkerThread();
|
||||
promise = Promise::Create(worker->GlobalScope(), aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
promise->MaybeResolve(res);
|
||||
} else if (aArg.IsPromise()) {
|
||||
promise = &aArg.GetAsPromise();
|
||||
}
|
||||
mWaitToRespond = true;
|
||||
nsRefPtr<RespondWithHandler> handler =
|
||||
new RespondWithHandler(mChannel, mServiceWorker, mRequest->Mode());
|
||||
aPromise.AppendNativeHandler(handler);
|
||||
}
|
||||
|
||||
void
|
||||
FetchEvent::RespondWith(Response& aResponse, ErrorResult& aRv)
|
||||
{
|
||||
if (mWaitToRespond) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(worker);
|
||||
worker->AssertIsOnWorkerThread();
|
||||
nsRefPtr<Promise> promise = Promise::Create(worker->GlobalScope(), aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
promise->MaybeResolve(&aResponse);
|
||||
|
||||
RespondWith(*promise, aRv);
|
||||
promise->AppendNativeHandler(handler);
|
||||
}
|
||||
|
||||
already_AddRefed<ServiceWorkerClient>
|
||||
|
@ -19,6 +19,7 @@ class nsIInterceptedChannel;
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class Request;
|
||||
class ResponseOrPromise;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
@ -82,10 +83,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
RespondWith(Promise& aPromise, ErrorResult& aRv);
|
||||
|
||||
void
|
||||
RespondWith(Response& aResponse, ErrorResult& aRv);
|
||||
RespondWith(const ResponseOrPromise& aArg, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise>
|
||||
ForwardTo(const nsAString& aUrl);
|
||||
|
Loading…
Reference in New Issue
Block a user