-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
abort_controller.cc
42 lines (32 loc) · 1.49 KB
/
abort_controller.cc
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
// Copyright 2018 The Chromium Authors
// 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/dom/abort_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_throw_dom_exception.h"
#include "third_party/blink/renderer/core/dom/abort_signal.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
namespace blink {
AbortController* AbortController::Create(ExecutionContext* context) {
return MakeGarbageCollected<AbortController>(
MakeGarbageCollected<AbortSignal>(context,
AbortSignal::SignalType::kController));
}
AbortController::AbortController(AbortSignal* signal) : signal_(signal) {}
AbortController::~AbortController() = default;
void AbortController::abort(ScriptState* script_state) {
v8::Local<v8::Value> dom_exception = V8ThrowDOMException::CreateOrEmpty(
script_state->GetIsolate(), DOMExceptionCode::kAbortError,
"signal is aborted without reason");
CHECK(!dom_exception.IsEmpty());
ScriptValue reason(script_state->GetIsolate(), dom_exception);
abort(script_state, reason);
}
void AbortController::abort(ScriptState* script_state, ScriptValue reason) {
signal_->SignalAbort(script_state, reason);
}
void AbortController::Trace(Visitor* visitor) const {
visitor->Trace(signal_);
ScriptWrappable::Trace(visitor);
}
} // namespace blink