diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index d7bdcb550f14..96cb7d7639e9 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -59,9 +59,9 @@ CancelChannelRunnable::Run() } FetchEvent::FetchEvent(EventTarget* aOwner) -: ExtendableEvent(aOwner) -, mIsReload(false) -, mWaitToRespond(false) + : ExtendableEvent(aOwner) + , mIsReload(false) + , mWaitToRespond(false) { } @@ -436,15 +436,6 @@ FetchEvent::RespondWith(Promise& aArg, ErrorResult& aRv) return; } - // 4.5.3.2 If the respond-with entered flag is set, then: - // Throw an "InvalidStateError" exception. - // Here we use |mPromise != nullptr| as respond-with enter flag - if (mPromise) { - aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); - return; - } - mPromise = &aArg; - RefPtr ir = mRequest->GetInternalRequest(); StopImmediatePropagation(); mWaitToRespond = true; @@ -452,6 +443,8 @@ FetchEvent::RespondWith(Promise& aArg, ErrorResult& aRv) new RespondWithHandler(mChannel, mRequest->Mode(), ir->IsClientRequest(), ir->IsNavigationRequest(), mScriptSpec); aArg.AppendNativeHandler(handler); + + WaitUntil(aArg, aRv); } NS_IMPL_ADDREF_INHERITED(FetchEvent, ExtendableEvent) @@ -460,8 +453,7 @@ NS_IMPL_RELEASE_INHERITED(FetchEvent, ExtendableEvent) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FetchEvent) NS_INTERFACE_MAP_END_INHERITING(ExtendableEvent) -NS_IMPL_CYCLE_COLLECTION_INHERITED(FetchEvent, ExtendableEvent, - mRequest, mPromise) +NS_IMPL_CYCLE_COLLECTION_INHERITED(FetchEvent, ExtendableEvent, mRequest) ExtendableEvent::ExtendableEvent(EventTarget* aOwner) : Event(aOwner, nullptr, nullptr) diff --git a/dom/workers/ServiceWorkerEvents.h b/dom/workers/ServiceWorkerEvents.h index 1e095b8ff8ad..0e852fb30bcb 100644 --- a/dom/workers/ServiceWorkerEvents.h +++ b/dom/workers/ServiceWorkerEvents.h @@ -103,7 +103,6 @@ class FetchEvent final : public ExtendableEvent nsMainThreadPtrHandle mChannel; RefPtr mRequest; nsCString mScriptSpec; - RefPtr mPromise; bool mIsReload; bool mWaitToRespond; protected: @@ -150,13 +149,6 @@ public: void RespondWith(Promise& aArg, ErrorResult& aRv); - already_AddRefed - GetPromise() const - { - RefPtr p = mPromise; - return p.forget(); - } - already_AddRefed ForwardTo(const nsAString& aUrl); diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index 11504551fd1c..038d3d271c9f 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -1175,11 +1175,11 @@ private: MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable))); } - RefPtr respondWithPromise = event->GetPromise(); - if (respondWithPromise) { + RefPtr waitUntilPromise = event->GetPromise(); + if (waitUntilPromise) { RefPtr keepAliveHandler = new KeepAliveHandler(mKeepAliveToken); - respondWithPromise->AppendNativeHandler(keepAliveHandler); + waitUntilPromise->AppendNativeHandler(keepAliveHandler); } // 9.8.22 If request is a non-subresource request, then: Invoke Soft Update algorithm