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

Side by Side Diff: third_party/WebKit/Source/core/workers/WorkletPendingTasks.cpp

Issue 2839123003: Worklet: Introduce "pending tasks struct" concept defined in the Worklet spec (Closed)
Patch Set: address review comments 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/workers/WorkletPendingTasks.h"
6
7 #include "core/dom/DOMException.h"
8 #include "core/dom/ExceptionCode.h"
9 #include "platform/wtf/WTF.h"
10
11 namespace blink {
12
13 WorkletPendingTasks::WorkletPendingTasks(int counter,
14 ScriptPromiseResolver* resolver)
15 : counter_(counter), resolver_(resolver) {
16 DCHECK(IsMainThread());
17 }
18
19 void WorkletPendingTasks::Abort() {
20 DCHECK(IsMainThread());
21 // Step 3: "If script is null, then queue a task on outsideSettings's
22 // responsible event loop to run these steps:"
23 // 1: "If pendingTaskStruct's counter is not -1, then run these steps:"
24 // 1: "Set pendingTaskStruct's counter to -1."
25 // 2: "Reject promise with an "AbortError" DOMException."
26 if (counter_ != -1) {
27 counter_ = -1;
28 // TODO(nhiroki): This should be kAbortError.
29 resolver_->Reject(DOMException::Create(kNetworkError));
30 }
31 }
32
33 void WorkletPendingTasks::DecrementCounter() {
34 DCHECK(IsMainThread());
35 // Step 5: "Queue a task on outsideSettings's responsible event loop to run
36 // these steps:"
37 // 1: "If pendingTaskStruct's counter is not -1, then run these steps:"
38 // 1: "Decrement pendingTaskStruct's counter by 1."
39 // 2: "If pendingTaskStruct's counter is 0, then resolve promise."
40 if (counter_ != -1) {
41 --counter_;
42 if (counter_ == 0)
43 resolver_->Resolve();
44 }
45 }
46
47 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698