/src/serenity/Userland/Libraries/LibWeb/Streams/WritableStreamDefaultController.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/WritableStreamDefaultControllerPrototype.h> |
8 | | #include <LibWeb/DOM/AbortSignal.h> |
9 | | #include <LibWeb/Streams/WritableStream.h> |
10 | | #include <LibWeb/Streams/WritableStreamDefaultController.h> |
11 | | |
12 | | namespace Web::Streams { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(WritableStreamDefaultController); |
15 | | |
16 | | void WritableStreamDefaultController::visit_edges(Visitor& visitor) |
17 | 0 | { |
18 | 0 | Base::visit_edges(visitor); |
19 | 0 | visitor.visit(m_signal); |
20 | 0 | for (auto& value : m_queue) |
21 | 0 | visitor.visit(value.value); |
22 | 0 | visitor.visit(m_stream); |
23 | 0 | visitor.visit(m_abort_algorithm); |
24 | 0 | visitor.visit(m_close_algorithm); |
25 | 0 | visitor.visit(m_strategy_size_algorithm); |
26 | 0 | visitor.visit(m_write_algorithm); |
27 | 0 | } |
28 | | |
29 | | // https://streams.spec.whatwg.org/#ws-default-controller-error |
30 | | void WritableStreamDefaultController::error(JS::Value error) |
31 | 0 | { |
32 | | // 1. Let state be this.[[stream]].[[state]]. |
33 | 0 | auto state = m_stream->state(); |
34 | | |
35 | | // 2. If state is not "writable", return. |
36 | 0 | if (state != WritableStream::State::Writable) |
37 | 0 | return; |
38 | | |
39 | | // 3. Perform ! WritableStreamDefaultControllerError(this, e). |
40 | 0 | writable_stream_default_controller_error(*this, error); |
41 | 0 | } |
42 | | |
43 | | // https://streams.spec.whatwg.org/#ws-default-controller-private-abort |
44 | | JS::NonnullGCPtr<WebIDL::Promise> WritableStreamDefaultController::abort_steps(JS::Value reason) |
45 | 0 | { |
46 | | // 1. Let result be the result of performing this.[[abortAlgorithm]], passing reason. |
47 | 0 | auto result = m_abort_algorithm->function()(reason); |
48 | | |
49 | | // 2. Perform ! WritableStreamDefaultControllerClearAlgorithms(this). |
50 | 0 | writable_stream_default_controller_clear_algorithms(*this); |
51 | | |
52 | | // 3. Return result. |
53 | 0 | return result; |
54 | 0 | } |
55 | | |
56 | | // https://streams.spec.whatwg.org/#ws-default-controller-private-error |
57 | | void WritableStreamDefaultController::error_steps() |
58 | 0 | { |
59 | | // 1. Perform ! ResetQueue(this). |
60 | 0 | reset_queue(*this); |
61 | 0 | } |
62 | | |
63 | | WritableStreamDefaultController::WritableStreamDefaultController(JS::Realm& realm) |
64 | 0 | : Bindings::PlatformObject(realm) |
65 | 0 | { |
66 | 0 | } |
67 | | |
68 | | } |