blob: 6ee7b4e5cd85e3ae3ccc2acba071ff15f7bac280 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/workers/worklet_pending_tasks.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/workers/worklet.h"
#include "third_party/blink/renderer/platform/wtf/wtf.h"
namespace blink {
WorkletPendingTasks::WorkletPendingTasks(Worklet* worklet,
ScriptPromiseResolver* resolver)
: resolver_(resolver), worklet_(worklet) {
DCHECK(IsMainThread());
}
void WorkletPendingTasks::InitializeCounter(int counter) {
DCHECK(IsMainThread());
counter_ = counter;
}
void WorkletPendingTasks::Abort() {
DCHECK(IsMainThread());
// Step 3: "If script is null, then queue a task on outsideSettings's
// responsible event loop to run these steps:"
// 1: "If pendingTaskStruct's counter is not -1, then run these steps:"
// 1: "Set pendingTaskStruct's counter to -1."
// 2: "Reject promise with an "AbortError" DOMException."
if (counter_ != -1) {
counter_ = -1;
worklet_->FinishPendingTasks(this);
resolver_->Reject(DOMException::Create(DOMExceptionCode::kAbortError));
}
}
void WorkletPendingTasks::DecrementCounter() {
DCHECK(IsMainThread());
// Step 5: "Queue a task on outsideSettings's responsible event loop to run
// these steps:"
// 1: "If pendingTaskStruct's counter is not -1, then run these steps:"
// 1: "Decrement pendingTaskStruct's counter by 1."
// 2: "If pendingTaskStruct's counter is 0, then resolve promise."
if (counter_ != -1) {
--counter_;
if (counter_ == 0) {
worklet_->FinishPendingTasks(this);
resolver_->Resolve();
}
}
}
void WorkletPendingTasks::Trace(blink::Visitor* visitor) {
visitor->Trace(resolver_);
visitor->Trace(worklet_);
}
} // namespace blink
|