/src/serenity/Userland/Libraries/LibWeb/Streams/AbstractOperations.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, Linus Groh <linusg@serenityos.org> |
3 | | * Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org> |
4 | | * Copyright (c) 2023-2024, Shannon Booth <shannon@serenityos.org> |
5 | | * Copyright (c) 2023-2024, Kenneth Myhra <kennethmyhra@serenityos.org> |
6 | | * |
7 | | * SPDX-License-Identifier: BSD-2-Clause |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <LibJS/Heap/GCPtr.h> |
13 | | #include <LibWeb/Forward.h> |
14 | | #include <LibWeb/Streams/ReadableStream.h> |
15 | | #include <LibWeb/WebIDL/CallbackType.h> |
16 | | #include <LibWeb/WebIDL/ExceptionOr.h> |
17 | | #include <LibWeb/WebIDL/Promise.h> |
18 | | #include <LibWeb/WebIDL/Types.h> |
19 | | |
20 | | namespace Web::Streams { |
21 | | |
22 | | using SizeAlgorithm = JS::HeapFunction<JS::Completion(JS::Value)>; |
23 | | using PullAlgorithm = JS::HeapFunction<JS::NonnullGCPtr<WebIDL::Promise>()>; |
24 | | using CancelAlgorithm = JS::HeapFunction<JS::NonnullGCPtr<WebIDL::Promise>(JS::Value)>; |
25 | | using StartAlgorithm = JS::HeapFunction<WebIDL::ExceptionOr<JS::Value>()>; |
26 | | using AbortAlgorithm = JS::HeapFunction<JS::NonnullGCPtr<WebIDL::Promise>(JS::Value)>; |
27 | | using CloseAlgorithm = JS::HeapFunction<JS::NonnullGCPtr<WebIDL::Promise>()>; |
28 | | using WriteAlgorithm = JS::HeapFunction<JS::NonnullGCPtr<WebIDL::Promise>(JS::Value)>; |
29 | | using FlushAlgorithm = JS::HeapFunction<JS::NonnullGCPtr<WebIDL::Promise>()>; |
30 | | using TransformAlgorithm = JS::HeapFunction<JS::NonnullGCPtr<WebIDL::Promise>(JS::Value)>; |
31 | | |
32 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamDefaultReader>> acquire_readable_stream_default_reader(ReadableStream&); |
33 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamBYOBReader>> acquire_readable_stream_byob_reader(ReadableStream&); |
34 | | bool is_readable_stream_locked(ReadableStream const&); |
35 | | |
36 | | JS::NonnullGCPtr<SizeAlgorithm> extract_size_algorithm(JS::VM&, QueuingStrategy const&); |
37 | | WebIDL::ExceptionOr<double> extract_high_water_mark(QueuingStrategy const&, double default_hwm); |
38 | | |
39 | | void readable_stream_close(ReadableStream&); |
40 | | void readable_stream_error(ReadableStream&, JS::Value error); |
41 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> readable_stream_from_iterable(JS::VM& vm, JS::Value async_iterable); |
42 | | void readable_stream_add_read_request(ReadableStream&, JS::NonnullGCPtr<ReadRequest>); |
43 | | void readable_stream_add_read_into_request(ReadableStream&, JS::NonnullGCPtr<ReadIntoRequest>); |
44 | | JS::NonnullGCPtr<WebIDL::Promise> readable_stream_cancel(ReadableStream&, JS::Value reason); |
45 | | void readable_stream_fulfill_read_into_request(ReadableStream&, JS::Value chunk, bool done); |
46 | | void readable_stream_fulfill_read_request(ReadableStream&, JS::Value chunk, bool done); |
47 | | size_t readable_stream_get_num_read_into_requests(ReadableStream const&); |
48 | | size_t readable_stream_get_num_read_requests(ReadableStream const&); |
49 | | bool readable_stream_has_byob_reader(ReadableStream const&); |
50 | | bool readable_stream_has_default_reader(ReadableStream const&); |
51 | | |
52 | | JS::NonnullGCPtr<WebIDL::Promise> readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool prevent_close, bool prevent_abort, bool prevent_cancel, Optional<JS::Value> signal); |
53 | | |
54 | | WebIDL::ExceptionOr<ReadableStreamPair> readable_stream_tee(JS::Realm&, ReadableStream&, bool clone_for_branch2); |
55 | | WebIDL::ExceptionOr<ReadableStreamPair> readable_stream_default_tee(JS::Realm& realm, ReadableStream& stream, bool clone_for_branch2); |
56 | | WebIDL::ExceptionOr<ReadableStreamPair> readable_byte_stream_tee(JS::Realm& realm, ReadableStream& stream); |
57 | | |
58 | | JS::NonnullGCPtr<WebIDL::Promise> readable_stream_reader_generic_cancel(ReadableStreamGenericReaderMixin&, JS::Value reason); |
59 | | void readable_stream_reader_generic_initialize(ReadableStreamReader, ReadableStream&); |
60 | | void readable_stream_reader_generic_release(ReadableStreamGenericReaderMixin&); |
61 | | |
62 | | void readable_stream_default_reader_error_read_requests(ReadableStreamDefaultReader&, JS::Value error); |
63 | | void readable_stream_byob_reader_error_read_into_requests(ReadableStreamBYOBReader&, JS::Value error); |
64 | | JS::Value readable_byte_stream_controller_convert_pull_into_descriptor(JS::Realm&, PullIntoDescriptor const&); |
65 | | void readable_byte_stream_controller_pull_into(ReadableByteStreamController&, WebIDL::ArrayBufferView&, u64 min, ReadIntoRequest&); |
66 | | void readable_stream_byob_reader_read(ReadableStreamBYOBReader&, WebIDL::ArrayBufferView&, u64 min, ReadIntoRequest&); |
67 | | void readable_byte_stream_controller_fill_head_pull_into_descriptor(ReadableByteStreamController const&, u64 size, PullIntoDescriptor&); |
68 | | |
69 | | void readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&); |
70 | | void readable_stream_default_reader_release(ReadableStreamDefaultReader&); |
71 | | void readable_stream_byob_reader_release(ReadableStreamBYOBReader&); |
72 | | WebIDL::ExceptionOr<void> set_up_readable_stream_default_reader(ReadableStreamDefaultReader&, ReadableStream&); |
73 | | WebIDL::ExceptionOr<void> set_up_readable_stream_byob_reader(ReadableStreamBYOBReader&, ReadableStream&); |
74 | | void readable_stream_default_controller_close(ReadableStreamDefaultController&); |
75 | | bool readable_stream_default_controller_has_backpressure(ReadableStreamDefaultController&); |
76 | | WebIDL::ExceptionOr<void> readable_stream_default_controller_enqueue(ReadableStreamDefaultController&, JS::Value chunk); |
77 | | void readable_stream_default_controller_can_pull_if_needed(ReadableStreamDefaultController&); |
78 | | bool readable_stream_default_controller_should_call_pull(ReadableStreamDefaultController&); |
79 | | void readable_stream_default_controller_clear_algorithms(ReadableStreamDefaultController&); |
80 | | |
81 | | void readable_stream_default_controller_error(ReadableStreamDefaultController&, JS::Value error); |
82 | | Optional<double> readable_stream_default_controller_get_desired_size(ReadableStreamDefaultController&); |
83 | | bool readable_stream_default_controller_can_close_or_enqueue(ReadableStreamDefaultController&); |
84 | | WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller(ReadableStream&, ReadableStreamDefaultController&, JS::NonnullGCPtr<StartAlgorithm>, JS::NonnullGCPtr<PullAlgorithm>, JS::NonnullGCPtr<CancelAlgorithm>, double high_water_mark, JS::NonnullGCPtr<SizeAlgorithm>); |
85 | | WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller_from_underlying_source(ReadableStream&, JS::Value underlying_source_value, UnderlyingSource, double high_water_mark, JS::NonnullGCPtr<SizeAlgorithm>); |
86 | | void set_up_readable_stream_controller_with_byte_reading_support(ReadableStream&, JS::GCPtr<PullAlgorithm> = {}, JS::GCPtr<CancelAlgorithm> = {}, double high_water_mark = 0); |
87 | | WebIDL::ExceptionOr<void> set_up_readable_byte_stream_controller(ReadableStream&, ReadableByteStreamController&, JS::NonnullGCPtr<StartAlgorithm>, JS::NonnullGCPtr<PullAlgorithm>, JS::NonnullGCPtr<CancelAlgorithm>, double high_water_mark, JS::Value auto_allocate_chunk_size); |
88 | | WebIDL::ExceptionOr<void> set_up_readable_byte_stream_controller_from_underlying_source(ReadableStream&, JS::Value underlying_source, UnderlyingSource const& underlying_source_dict, double high_water_mark); |
89 | | JS::GCPtr<ReadableStreamBYOBRequest> readable_byte_stream_controller_get_byob_request(JS::NonnullGCPtr<ReadableByteStreamController>); |
90 | | |
91 | | WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_in_readable_state(ReadableByteStreamController&, u64 bytes_written, PullIntoDescriptor&); |
92 | | void readable_byte_stream_controller_respond_in_closed_state(ReadableByteStreamController&, PullIntoDescriptor&); |
93 | | WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_internal(ReadableByteStreamController&, u64 bytes_written); |
94 | | WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond(ReadableByteStreamController&, u64 bytes_written); |
95 | | WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_with_new_view(JS::Realm&, ReadableByteStreamController&, WebIDL::ArrayBufferView&); |
96 | | |
97 | | WebIDL::ExceptionOr<void> readable_stream_enqueue(ReadableStreamController& controller, JS::Value chunk); |
98 | | WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteStreamController& controller, JS::Value chunk); |
99 | | WebIDL::ExceptionOr<void> readable_stream_pull_from_bytes(ReadableStream&, ByteBuffer bytes); |
100 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> transfer_array_buffer(JS::Realm& realm, JS::ArrayBuffer& buffer); |
101 | | WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue_detached_pull_into_queue(ReadableByteStreamController& controller, PullIntoDescriptor& pull_into_descriptor); |
102 | | void readable_byte_stream_controller_commit_pull_into_descriptor(ReadableStream&, PullIntoDescriptor const&); |
103 | | void readable_byte_stream_controller_process_read_requests_using_queue(ReadableByteStreamController& controller); |
104 | | void readable_byte_stream_controller_process_pull_into_descriptors_using_queue(ReadableByteStreamController&); |
105 | | void readable_byte_stream_controller_enqueue_chunk_to_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr<JS::ArrayBuffer> buffer, u32 byte_offset, u32 byte_length); |
106 | | WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue_cloned_chunk_to_queue(ReadableByteStreamController& controller, JS::ArrayBuffer& buffer, u64 byte_offset, u64 byte_length); |
107 | | PullIntoDescriptor readable_byte_stream_controller_shift_pending_pull_into(ReadableByteStreamController& controller); |
108 | | |
109 | | void readable_byte_stream_controller_call_pull_if_needed(ReadableByteStreamController&); |
110 | | void readable_byte_stream_controller_clear_algorithms(ReadableByteStreamController&); |
111 | | void readable_byte_stream_controller_clear_pending_pull_intos(ReadableByteStreamController&); |
112 | | WebIDL::ExceptionOr<void> readable_byte_stream_controller_close(ReadableByteStreamController&); |
113 | | void readable_byte_stream_controller_error(ReadableByteStreamController&, JS::Value error); |
114 | | void readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController&, JS::NonnullGCPtr<ReadRequest>); |
115 | | bool readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(ReadableByteStreamController&, PullIntoDescriptor&); |
116 | | Optional<double> readable_byte_stream_controller_get_desired_size(ReadableByteStreamController const&); |
117 | | void readable_byte_stream_controller_handle_queue_drain(ReadableByteStreamController&); |
118 | | void readable_byte_stream_controller_invalidate_byob_request(ReadableByteStreamController&); |
119 | | bool readable_byte_stream_controller_should_call_pull(ReadableByteStreamController const&); |
120 | | |
121 | | WebIDL::ExceptionOr<void> set_up_readable_stream(JS::Realm& realm, ReadableStream& stream, JS::NonnullGCPtr<StartAlgorithm> start_algorithm, JS::NonnullGCPtr<PullAlgorithm> pull_algorithm, JS::NonnullGCPtr<CancelAlgorithm> cancel_algorithm, Optional<double> high_water_mark = {}, JS::GCPtr<SizeAlgorithm> size_algorithm = {}); |
122 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> create_readable_stream(JS::Realm& realm, JS::NonnullGCPtr<StartAlgorithm> start_algorithm, JS::NonnullGCPtr<PullAlgorithm> pull_algorithm, JS::NonnullGCPtr<CancelAlgorithm> cancel_algorithm, Optional<double> high_water_mark = {}, JS::GCPtr<SizeAlgorithm> size_algorithm = {}); |
123 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> create_readable_byte_stream(JS::Realm& realm, JS::NonnullGCPtr<StartAlgorithm> start_algorithm, JS::NonnullGCPtr<PullAlgorithm> pull_algorithm, JS::NonnullGCPtr<CancelAlgorithm> cancel_algorithm); |
124 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStream>> create_writable_stream(JS::Realm& realm, JS::NonnullGCPtr<StartAlgorithm> start_algorithm, JS::NonnullGCPtr<WriteAlgorithm> write_algorithm, JS::NonnullGCPtr<CloseAlgorithm> close_algorithm, JS::NonnullGCPtr<AbortAlgorithm> abort_algorithm, double high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> size_algorithm); |
125 | | void initialize_readable_stream(ReadableStream&); |
126 | | void initialize_writable_stream(WritableStream&); |
127 | | |
128 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> acquire_writable_stream_default_writer(WritableStream&); |
129 | | bool is_writable_stream_locked(WritableStream const&); |
130 | | WebIDL::ExceptionOr<void> set_up_writable_stream_default_writer(WritableStreamDefaultWriter&, WritableStream&); |
131 | | JS::NonnullGCPtr<WebIDL::Promise> writable_stream_abort(WritableStream&, JS::Value reason); |
132 | | JS::NonnullGCPtr<WebIDL::Promise> writable_stream_close(WritableStream&); |
133 | | |
134 | | JS::NonnullGCPtr<WebIDL::Promise> writable_stream_add_write_request(WritableStream&); |
135 | | bool writable_stream_close_queued_or_in_flight(WritableStream const&); |
136 | | void writable_stream_deal_with_rejection(WritableStream&, JS::Value error); |
137 | | void writable_stream_finish_erroring(WritableStream&); |
138 | | void writable_stream_finish_in_flight_close(WritableStream&); |
139 | | void writable_stream_finish_in_flight_close_with_error(WritableStream&, JS::Value error); |
140 | | void writable_stream_finish_in_flight_write(WritableStream&); |
141 | | void writable_stream_finish_in_flight_write_with_error(WritableStream&, JS::Value error); |
142 | | bool writable_stream_has_operation_marked_in_flight(WritableStream const&); |
143 | | void writable_stream_mark_close_request_in_flight(WritableStream&); |
144 | | void writable_stream_mark_first_write_request_in_flight(WritableStream&); |
145 | | void writable_stream_reject_close_and_closed_promise_if_needed(WritableStream&); |
146 | | void writable_stream_start_erroring(WritableStream&, JS::Value reason); |
147 | | void writable_stream_update_backpressure(WritableStream&, bool backpressure); |
148 | | |
149 | | JS::NonnullGCPtr<WebIDL::Promise> writable_stream_default_writer_abort(WritableStreamDefaultWriter&, JS::Value reason); |
150 | | JS::NonnullGCPtr<WebIDL::Promise> writable_stream_default_writer_close(WritableStreamDefaultWriter&); |
151 | | void writable_stream_default_writer_ensure_closed_promise_rejected(WritableStreamDefaultWriter&, JS::Value error); |
152 | | void writable_stream_default_writer_ensure_ready_promise_rejected(WritableStreamDefaultWriter&, JS::Value error); |
153 | | Optional<double> writable_stream_default_writer_get_desired_size(WritableStreamDefaultWriter const&); |
154 | | void writable_stream_default_writer_release(WritableStreamDefaultWriter&); |
155 | | JS::NonnullGCPtr<WebIDL::Promise> writable_stream_default_writer_write(WritableStreamDefaultWriter&, JS::Value chunk); |
156 | | |
157 | | WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller(WritableStream&, WritableStreamDefaultController&, JS::NonnullGCPtr<StartAlgorithm>, JS::NonnullGCPtr<WriteAlgorithm>, JS::NonnullGCPtr<CloseAlgorithm>, JS::NonnullGCPtr<AbortAlgorithm>, double high_water_mark, JS::NonnullGCPtr<SizeAlgorithm>); |
158 | | WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller_from_underlying_sink(WritableStream&, JS::Value underlying_sink_value, UnderlyingSink&, double high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> size_algorithm); |
159 | | void writable_stream_default_controller_advance_queue_if_needed(WritableStreamDefaultController&); |
160 | | void writable_stream_default_controller_clear_algorithms(WritableStreamDefaultController&); |
161 | | void writable_stream_default_controller_close(WritableStreamDefaultController&); |
162 | | void writable_stream_default_controller_error(WritableStreamDefaultController&, JS::Value error); |
163 | | void writable_stream_default_controller_error_if_needed(WritableStreamDefaultController&, JS::Value error); |
164 | | bool writable_stream_default_controller_get_backpressure(WritableStreamDefaultController const&); |
165 | | JS::Value writable_stream_default_controller_get_chunk_size(WritableStreamDefaultController&, JS::Value chunk); |
166 | | double writable_stream_default_controller_get_desired_size(WritableStreamDefaultController const&); |
167 | | void writable_stream_default_controller_process_close(WritableStreamDefaultController&); |
168 | | void writable_stream_default_controller_process_write(WritableStreamDefaultController&, JS::Value chunk); |
169 | | void writable_stream_default_controller_write(WritableStreamDefaultController&, JS::Value chunk, JS::Value chunk_size); |
170 | | |
171 | | void initialize_transform_stream(TransformStream&, JS::NonnullGCPtr<JS::PromiseCapability> start_promise, double writable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> writable_size_algorithm, double readable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> readable_size_algorithm); |
172 | | void set_up_transform_stream_default_controller(TransformStream&, TransformStreamDefaultController&, JS::NonnullGCPtr<TransformAlgorithm>, JS::NonnullGCPtr<FlushAlgorithm>, JS::NonnullGCPtr<CancelAlgorithm>); |
173 | | void set_up_transform_stream_default_controller_from_transformer(TransformStream&, JS::Value transformer, Transformer&); |
174 | | void transform_stream_default_controller_clear_algorithms(TransformStreamDefaultController&); |
175 | | WebIDL::ExceptionOr<void> transform_stream_default_controller_enqueue(TransformStreamDefaultController&, JS::Value chunk); |
176 | | void transform_stream_default_controller_error(TransformStreamDefaultController&, JS::Value error); |
177 | | void transform_stream_default_controller_terminate(TransformStreamDefaultController&); |
178 | | JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_controller_perform_transform(TransformStreamDefaultController&, JS::Value chunk); |
179 | | JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_abort_algorithm(TransformStream&, JS::Value reason); |
180 | | JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_close_algorithm(TransformStream&); |
181 | | JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_write_algorithm(TransformStream&, JS::Value chunk); |
182 | | JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_source_pull_algorithm(TransformStream&); |
183 | | JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_source_cancel_algorithm(TransformStream&, JS::Value reason); |
184 | | void transform_stream_error(TransformStream&, JS::Value error); |
185 | | void transform_stream_error_writable_and_unblock_write(TransformStream&, JS::Value error); |
186 | | void transform_stream_set_backpressure(TransformStream&, bool backpressure); |
187 | | void transform_stream_set_up(TransformStream&, JS::NonnullGCPtr<TransformAlgorithm>, JS::GCPtr<FlushAlgorithm> = {}, JS::GCPtr<CancelAlgorithm> = {}); |
188 | | void transform_stream_unblock_write(TransformStream&); |
189 | | |
190 | | bool is_non_negative_number(JS::Value); |
191 | | bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer); |
192 | | WebIDL::ExceptionOr<JS::Value> clone_as_uint8_array(JS::Realm&, WebIDL::ArrayBufferView&); |
193 | | WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Realm&, JS::Value value); |
194 | | |
195 | | JS::Value create_close_sentinel(); |
196 | | bool is_close_sentinel(JS::Value); |
197 | | JS::ThrowCompletionOr<JS::Handle<WebIDL::CallbackType>> property_to_callback(JS::VM& vm, JS::Value value, JS::PropertyKey const& property_key, WebIDL::OperationReturnsPromise); |
198 | | |
199 | | // https://streams.spec.whatwg.org/#value-with-size |
200 | | struct ValueWithSize { |
201 | | JS::Value value; |
202 | | double size; |
203 | | }; |
204 | | |
205 | | // https://streams.spec.whatwg.org/#dequeue-value |
206 | | template<typename T> |
207 | | JS::Value dequeue_value(T& container) |
208 | 0 | { |
209 | | // 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots. |
210 | | |
211 | | // 2. Assert: container.[[queue]] is not empty. |
212 | 0 | VERIFY(!container.queue().is_empty()); |
213 | | |
214 | | // 3. Let valueWithSize be container.[[queue]][0]. |
215 | | // 4. Remove valueWithSize from container.[[queue]]. |
216 | 0 | auto value_with_size = container.queue().take_first(); |
217 | | |
218 | | // 5. Set container.[[queueTotalSize]] to container.[[queueTotalSize]] − valueWithSize’s size. |
219 | 0 | container.set_queue_total_size(container.queue_total_size() - value_with_size.size); |
220 | | |
221 | | // 6. If container.[[queueTotalSize]] < 0, set container.[[queueTotalSize]] to 0. (This can occur due to rounding errors.) |
222 | 0 | if (container.queue_total_size() < 0.0) |
223 | 0 | container.set_queue_total_size(0.0); |
224 | | |
225 | | // 7. Return valueWithSize’s value. |
226 | 0 | return value_with_size.value; |
227 | 0 | } Unexecuted instantiation: JS::Value Web::Streams::dequeue_value<Web::Streams::WritableStreamDefaultController>(Web::Streams::WritableStreamDefaultController&) Unexecuted instantiation: JS::Value Web::Streams::dequeue_value<Web::Streams::ReadableStreamDefaultController>(Web::Streams::ReadableStreamDefaultController&) |
228 | | |
229 | | // https://streams.spec.whatwg.org/#enqueue-value-with-size |
230 | | template<typename T> |
231 | | WebIDL::ExceptionOr<void> enqueue_value_with_size(T& container, JS::Value value, JS::Value size) |
232 | 0 | { |
233 | | // 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots. |
234 | | |
235 | | // 2. If ! IsNonNegativeNumber(size) is false, throw a RangeError exception. |
236 | 0 | if (!is_non_negative_number(size)) |
237 | 0 | return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Chunk has non-positive size"sv }; |
238 | | |
239 | | // 3. If size is +∞, throw a RangeError exception. |
240 | 0 | if (size.is_positive_infinity()) |
241 | 0 | return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Chunk has infinite size"sv }; |
242 | | |
243 | | // 4. Append a new value-with-size with value value and size size to container.[[queue]]. |
244 | 0 | container.queue().append({ value, size.as_double() }); |
245 | | |
246 | | // 5. Set container.[[queueTotalSize]] to container.[[queueTotalSize]] + size. |
247 | 0 | container.set_queue_total_size(container.queue_total_size() + size.as_double()); |
248 | |
|
249 | 0 | return {}; |
250 | 0 | } Unexecuted instantiation: Web::WebIDL::ExceptionOr<void> Web::Streams::enqueue_value_with_size<Web::Streams::ReadableStreamDefaultController>(Web::Streams::ReadableStreamDefaultController&, JS::Value, JS::Value) Unexecuted instantiation: Web::WebIDL::ExceptionOr<void> Web::Streams::enqueue_value_with_size<Web::Streams::WritableStreamDefaultController>(Web::Streams::WritableStreamDefaultController&, JS::Value, JS::Value) |
251 | | |
252 | | // https://streams.spec.whatwg.org/#peek-queue-value |
253 | | template<typename T> |
254 | | JS::Value peek_queue_value(T& container) |
255 | 0 | { |
256 | | // 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots. |
257 | | |
258 | | // 2. Assert: container.[[queue]] is not empty. |
259 | 0 | VERIFY(!container.queue().is_empty()); |
260 | | |
261 | | // 3. Let valueWithSize be container.[[queue]][0]. |
262 | 0 | auto& value_with_size = container.queue().first(); |
263 | | |
264 | | // 4. Return valueWithSize’s value. |
265 | 0 | return value_with_size.value; |
266 | 0 | } |
267 | | |
268 | | // https://streams.spec.whatwg.org/#reset-queue |
269 | | template<typename T> |
270 | | void reset_queue(T& container) |
271 | 0 | { |
272 | | // 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots. |
273 | | |
274 | | // 2. Set container.[[queue]] to a new empty list. |
275 | 0 | container.queue().clear(); |
276 | | |
277 | | // 3. Set container.[[queueTotalSize]] to 0. |
278 | 0 | container.set_queue_total_size(0); |
279 | 0 | } Unexecuted instantiation: void Web::Streams::reset_queue<Web::Streams::ReadableStreamDefaultController>(Web::Streams::ReadableStreamDefaultController&) Unexecuted instantiation: void Web::Streams::reset_queue<Web::Streams::ReadableByteStreamController>(Web::Streams::ReadableByteStreamController&) Unexecuted instantiation: void Web::Streams::reset_queue<Web::Streams::WritableStreamDefaultController>(Web::Streams::WritableStreamDefaultController&) |
280 | | |
281 | | } |