mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
LibWeb: Implement AO ReadableByteStreamControllerRespond
This commit is contained in:
parent
2ab933e534
commit
08be5deb3f
2 changed files with 42 additions and 0 deletions
|
@ -1226,6 +1226,47 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_internal(Reada
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-respond
|
||||||
|
WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond(ReadableByteStreamController& controller, u64 bytes_written)
|
||||||
|
{
|
||||||
|
auto& realm = controller.realm();
|
||||||
|
|
||||||
|
// 1. Assert: controller.[[pendingPullIntos]] is not empty.
|
||||||
|
VERIFY(!controller.pending_pull_intos().is_empty());
|
||||||
|
|
||||||
|
// 2. Let firstDescriptor be controller.[[pendingPullIntos]][0].
|
||||||
|
auto& first_descriptor = controller.pending_pull_intos().first();
|
||||||
|
|
||||||
|
// 3. Let state be controller.[[stream]].[[state]].
|
||||||
|
auto state = controller.stream()->state();
|
||||||
|
|
||||||
|
// 4. If state is "closed",
|
||||||
|
if (state == ReadableStream::State::Closed) {
|
||||||
|
// 1. If bytesWritten is not 0, throw a TypeError exception.
|
||||||
|
if (bytes_written != 0)
|
||||||
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Bytes written is not zero for closed stream"sv };
|
||||||
|
}
|
||||||
|
// 5. Otherwise,
|
||||||
|
else {
|
||||||
|
// 1. Assert: state is "readable".
|
||||||
|
VERIFY(state == ReadableStream::State::Readable);
|
||||||
|
|
||||||
|
// 2. If bytesWritten is 0, throw a TypeError exception.
|
||||||
|
if (bytes_written == 0)
|
||||||
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Bytes written is zero for stream which is not closed"sv };
|
||||||
|
|
||||||
|
// 3. If firstDescriptor’s bytes filled + bytesWritten > firstDescriptor’s byte length, throw a RangeError exception.
|
||||||
|
if (first_descriptor.bytes_filled + bytes_written > first_descriptor.byte_length)
|
||||||
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Bytes written is greater than the pull requests byte length"sv };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Set firstDescriptor’s buffer to ! TransferArrayBuffer(firstDescriptor’s buffer).
|
||||||
|
first_descriptor.buffer = MUST(transfer_array_buffer(realm, *first_descriptor.buffer));
|
||||||
|
|
||||||
|
// 7. Perform ? ReadableByteStreamControllerRespondInternal(controller, bytesWritten).
|
||||||
|
return readable_byte_stream_controller_respond_internal(controller, bytes_written);
|
||||||
|
}
|
||||||
|
|
||||||
// https://streams.spec.whatwg.org/#readable-stream-default-controller-error
|
// https://streams.spec.whatwg.org/#readable-stream-default-controller-error
|
||||||
void readable_stream_default_controller_error(ReadableStreamDefaultController& controller, JS::Value error)
|
void readable_stream_default_controller_error(ReadableStreamDefaultController& controller, JS::Value error)
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,6 +83,7 @@ JS::GCPtr<ReadableStreamBYOBRequest> readable_byte_stream_controller_get_byob_re
|
||||||
WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_in_readable_state(ReadableByteStreamController&, u64 bytes_written, PullIntoDescriptor&);
|
WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_in_readable_state(ReadableByteStreamController&, u64 bytes_written, PullIntoDescriptor&);
|
||||||
void readable_byte_stream_controller_respond_in_closed_state(ReadableByteStreamController&, PullIntoDescriptor&);
|
void readable_byte_stream_controller_respond_in_closed_state(ReadableByteStreamController&, PullIntoDescriptor&);
|
||||||
WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_internal(ReadableByteStreamController&, u64 bytes_written);
|
WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond_internal(ReadableByteStreamController&, u64 bytes_written);
|
||||||
|
WebIDL::ExceptionOr<void> readable_byte_stream_controller_respond(ReadableByteStreamController&, u64 bytes_written);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> readable_stream_enqueue(ReadableStreamController& controller, JS::Value chunk);
|
WebIDL::ExceptionOr<void> readable_stream_enqueue(ReadableStreamController& controller, JS::Value chunk);
|
||||||
WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteStreamController& controller, JS::Value chunk);
|
WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteStreamController& controller, JS::Value chunk);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue