#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/core/streams/readable_byte_stream_controller.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/clamped_math.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_underlying_source.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_underlying_source_cancel_callback.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_underlying_source_pull_callback.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_underlying_source_start_callback.h"
#include "third_party/blink/renderer/core/streams/miscellaneous_operations.h"
#include "third_party/blink/renderer/core/streams/promise_handler.h"
#include "third_party/blink/renderer/core/streams/read_into_request.h"
#include "third_party/blink/renderer/core/streams/read_request.h"
#include "third_party/blink/renderer/core/streams/readable_stream.h"
#include "third_party/blink/renderer/core/streams/readable_stream_byob_request.h"
#include "third_party/blink/renderer/core/streams/stream_algorithms.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_data_view.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_binding.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "v8/include/v8.h"
namespace blink {
namespace {
template <typename DOMType>
DOMArrayBufferView* CreateAsArrayBufferView(DOMArrayBuffer* buffer,
size_t byte_offset,
size_t length) { … }
}
ReadableByteStreamController::QueueEntry::QueueEntry(DOMArrayBuffer* buffer,
size_t byte_offset,
size_t byte_length)
: … { … }
void ReadableByteStreamController::QueueEntry::Trace(Visitor* visitor) const { … }
ReadableByteStreamController::PullIntoDescriptor::PullIntoDescriptor(
DOMArrayBuffer* buffer,
size_t buffer_byte_length,
size_t byte_offset,
size_t byte_length,
size_t bytes_filled,
size_t element_size,
ViewConstructorType view_constructor,
ReaderType reader_type)
: … { … }
void ReadableByteStreamController::PullIntoDescriptor::Trace(
Visitor* visitor) const { … }
ReadableByteStreamController::ReadableByteStreamController()
: … { … }
ReadableStreamBYOBRequest* ReadableByteStreamController::byobRequest() { … }
ReadableStreamBYOBRequest* ReadableByteStreamController::GetBYOBRequest(
ReadableByteStreamController* controller) { … }
std::optional<double> ReadableByteStreamController::desiredSize() { … }
std::optional<double> ReadableByteStreamController::GetDesiredSize(
ReadableByteStreamController* controller) { … }
void ReadableByteStreamController::close(ScriptState* script_state,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::enqueue(ScriptState* script_state,
NotShared<DOMArrayBufferView> chunk,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::error(ScriptState* script_state) { … }
void ReadableByteStreamController::error(ScriptState* script_state,
const ScriptValue& e) { … }
void ReadableByteStreamController::Close(
ScriptState* script_state,
ReadableByteStreamController* controller,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::Error(
ScriptState* script_state,
ReadableByteStreamController* controller,
v8::Local<v8::Value> e) { … }
void ReadableByteStreamController::Enqueue(
ScriptState* script_state,
ReadableByteStreamController* controller,
NotShared<DOMArrayBufferView> chunk,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::EnqueueChunkToQueue(
ReadableByteStreamController* controller,
DOMArrayBuffer* buffer,
size_t byte_offset,
size_t byte_length) { … }
void ReadableByteStreamController::EnqueueClonedChunkToQueue(
ReadableByteStreamController* controller,
DOMArrayBuffer* buffer,
size_t byte_offset,
size_t byte_length) { … }
void ReadableByteStreamController::EnqueueDetachedPullIntoToQueue(
ReadableByteStreamController* controller,
PullIntoDescriptor* pull_into_descriptor) { … }
void ReadableByteStreamController::ProcessPullIntoDescriptorsUsingQueue(
ScriptState* script_state,
ReadableByteStreamController* controller,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::ProcessReadRequestsUsingQueue(
ScriptState* script_state,
ReadableByteStreamController* controller,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::CallPullIfNeeded(
ScriptState* script_state,
ReadableByteStreamController* controller) { … }
ReadableByteStreamController::PullIntoDescriptor*
ReadableByteStreamController::ShiftPendingPullInto(
ReadableByteStreamController* controller) { … }
bool ReadableByteStreamController::ShouldCallPull(
ReadableByteStreamController* controller) { … }
void ReadableByteStreamController::CommitPullIntoDescriptor(
ScriptState* script_state,
ReadableStream* stream,
PullIntoDescriptor* pull_into_descriptor,
ExceptionState& exception_state) { … }
DOMArrayBufferView* ReadableByteStreamController::ConvertPullIntoDescriptor(
ScriptState* script_state,
PullIntoDescriptor* pull_into_descriptor,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::ClearPendingPullIntos(
ReadableByteStreamController* controller) { … }
void ReadableByteStreamController::ClearAlgorithms(
ReadableByteStreamController* controller) { … }
void ReadableByteStreamController::InvalidateBYOBRequest(
ReadableByteStreamController* controller) { … }
void ReadableByteStreamController::SetUp(
ScriptState* script_state,
ReadableStream* stream,
ReadableByteStreamController* controller,
StreamStartAlgorithm* start_algorithm,
StreamAlgorithm* pull_algorithm,
StreamAlgorithm* cancel_algorithm,
double high_water_mark,
size_t auto_allocate_chunk_size,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::SetUpFromUnderlyingSource(
ScriptState* script_state,
ReadableStream* stream,
v8::Local<v8::Object> underlying_source,
UnderlyingSource* underlying_source_dict,
double high_water_mark,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::FillHeadPullIntoDescriptor(
ReadableByteStreamController* controller,
size_t size,
PullIntoDescriptor* pull_into_descriptor) { … }
bool ReadableByteStreamController::FillPullIntoDescriptorFromQueue(
ReadableByteStreamController* controller,
PullIntoDescriptor* pull_into_descriptor,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::FillReadRequestFromQueue(
ScriptState* script_state,
ReadableByteStreamController* controller,
ReadRequest* read_request,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::PullInto(
ScriptState* script_state,
ReadableByteStreamController* controller,
NotShared<DOMArrayBufferView> view,
ReadIntoRequest* read_into_request,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::HandleQueueDrain(
ScriptState* script_state,
ReadableByteStreamController* controller) { … }
void ReadableByteStreamController::ResetQueue(
ReadableByteStreamController* controller) { … }
void ReadableByteStreamController::Respond(
ScriptState* script_state,
ReadableByteStreamController* controller,
size_t bytes_written,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::RespondInClosedState(
ScriptState* script_state,
ReadableByteStreamController* controller,
PullIntoDescriptor* first_descriptor,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::RespondInReadableState(
ScriptState* script_state,
ReadableByteStreamController* controller,
size_t bytes_written,
PullIntoDescriptor* pull_into_descriptor,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::RespondInternal(
ScriptState* script_state,
ReadableByteStreamController* controller,
size_t bytes_written,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::RespondWithNewView(
ScriptState* script_state,
ReadableByteStreamController* controller,
NotShared<DOMArrayBufferView> view,
ExceptionState& exception_state) { … }
bool ReadableByteStreamController::CanTransferArrayBuffer(
DOMArrayBuffer* buffer) { … }
DOMArrayBuffer* ReadableByteStreamController::TransferArrayBuffer(
ScriptState* script_state,
DOMArrayBuffer* buffer,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::Trace(Visitor* visitor) const { … }
v8::Local<v8::Promise> ReadableByteStreamController::CancelSteps(
ScriptState* script_state,
v8::Local<v8::Value> reason) { … }
void ReadableByteStreamController::PullSteps(ScriptState* script_state,
ReadRequest* read_request,
ExceptionState& exception_state) { … }
void ReadableByteStreamController::ReleaseSteps() { … }
}