Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp

Issue 2867023002: [ServiceWorker] waitUntil() should wait until all promises got resolved/rejected. (Closed)
Patch Set: More clean up Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp b/third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp
index 839f336a2d17707a5f95b998d9b2cb2cfe5e688f..f4bf2346ba52562bcc1561aa55f67d84aefd72fa 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/WaitUntilObserver.cpp
@@ -65,11 +65,12 @@ class WaitUntilObserver::ThenFunction final : public ScriptFunction {
ASSERT(observer_);
ASSERT(resolve_type_ == kFulfilled || resolve_type_ == kRejected);
if (resolve_type_ == kRejected) {
- observer_->ReportError(value);
+ observer_->OnPromiseRejected();
value =
ScriptPromise::Reject(value.GetScriptState(), value).GetScriptValue();
+ } else {
+ observer_->OnPromiseFulfilled();
}
- observer_->DecrementPendingActivity();
observer_ = nullptr;
return value;
}
@@ -97,17 +98,17 @@ void WaitUntilObserver::WillDispatchEvent() {
IncrementPendingActivity();
}
-void WaitUntilObserver::DidDispatchEvent(bool error_occurred) {
- if (error_occurred)
- has_error_ = true;
+void WaitUntilObserver::DidDispatchEvent(bool event_dispatch_failed) {
+ event_dispatch_state_ = event_dispatch_failed
+ ? EventDispatchState::kFailed
+ : EventDispatchState::kCompleted;
DecrementPendingActivity();
- event_dispatched_ = true;
}
void WaitUntilObserver::WaitUntil(ScriptState* script_state,
ScriptPromise script_promise,
ExceptionState& exception_state) {
- if (event_dispatched_) {
+ if (event_dispatch_state_ != EventDispatchState::kInitial) {
exception_state.ThrowDOMException(kInvalidStateError,
"The event handler is already finished.");
return;
@@ -143,11 +144,13 @@ WaitUntilObserver::WaitUntilObserver(ExecutionContext* context,
this,
&WaitUntilObserver::ConsumeWindowInteraction) {}
-void WaitUntilObserver::ReportError(const ScriptValue& value) {
- // FIXME: Propagate error message to the client for onerror handling.
- NOTIMPLEMENTED();
+void WaitUntilObserver::OnPromiseFulfilled() {
+ DecrementPendingActivity();
+}
- has_error_ = true;
+void WaitUntilObserver::OnPromiseRejected() {
+ has_rejected_promise_ = true;
+ DecrementPendingActivity();
}
void WaitUntilObserver::IncrementPendingActivity() {
@@ -156,14 +159,18 @@ void WaitUntilObserver::IncrementPendingActivity() {
void WaitUntilObserver::DecrementPendingActivity() {
ASSERT(pending_activity_ > 0);
- if (!execution_context_ || (!has_error_ && --pending_activity_))
+ if (!execution_context_ ||
+ (event_dispatch_state_ != EventDispatchState::kFailed &&
+ --pending_activity_))
return;
ServiceWorkerGlobalScopeClient* client =
ServiceWorkerGlobalScopeClient::From(execution_context_);
WebServiceWorkerEventResult result =
- has_error_ ? kWebServiceWorkerEventResultRejected
- : kWebServiceWorkerEventResultCompleted;
+ (event_dispatch_state_ == EventDispatchState::kFailed ||
+ has_rejected_promise_)
+ ? kWebServiceWorkerEventResultRejected
+ : kWebServiceWorkerEventResultCompleted;
switch (type_) {
case kActivate:
client->DidHandleActivateEvent(event_id_, result, event_dispatch_time_);

Powered by Google App Engine
This is Rietveld 408576698