mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Use Vector<ByteBuffer> to store chunks in ReadLoopReadRequest
This stores the incoming chunks into a Vector of ByteBuffer in order to be able to retrieve them in the same order as they came in.
This commit is contained in:
parent
cb5f30ae98
commit
12cfa08a09
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/kennethmyhra
Commit: 12cfa08a09
Pull-request: https://github.com/SerenityOS/serenity/pull/23869
Reviewed-by: https://github.com/shannonbooth ✅
2 changed files with 10 additions and 6 deletions
|
@ -86,7 +86,7 @@ void ReadLoopReadRequest::on_chunk(JS::Value chunk)
|
||||||
auto const& buffer = array.viewed_array_buffer()->buffer();
|
auto const& buffer = array.viewed_array_buffer()->buffer();
|
||||||
|
|
||||||
// 2. Append the bytes represented by chunk to bytes.
|
// 2. Append the bytes represented by chunk to bytes.
|
||||||
m_bytes.append(buffer);
|
m_byte_chunks.append(buffer);
|
||||||
|
|
||||||
// FIXME: As the spec suggests, implement this non-recursively - instead of directly. It is not too big of a deal currently
|
// FIXME: As the spec suggests, implement this non-recursively - instead of directly. It is not too big of a deal currently
|
||||||
// as we enqueue the entire blob buffer in one go, meaning that we only recurse a single time. Once we begin queuing
|
// as we enqueue the entire blob buffer in one go, meaning that we only recurse a single time. Once we begin queuing
|
||||||
|
@ -104,7 +104,7 @@ void ReadLoopReadRequest::on_chunk(JS::Value chunk)
|
||||||
void ReadLoopReadRequest::on_close()
|
void ReadLoopReadRequest::on_close()
|
||||||
{
|
{
|
||||||
// 1. Call successSteps with bytes.
|
// 1. Call successSteps with bytes.
|
||||||
m_success_steps(m_bytes);
|
m_success_steps(m_byte_chunks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// error steps, given e
|
// error steps, given e
|
||||||
|
@ -206,8 +206,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> ReadableStreamDefaultRead
|
||||||
|
|
||||||
auto promise = WebIDL::create_promise(realm);
|
auto promise = WebIDL::create_promise(realm);
|
||||||
|
|
||||||
auto success_steps = [promise, &realm](ByteBuffer bytes) {
|
auto success_steps = [promise, &realm](Vector<ByteBuffer> const& byte_chunks) {
|
||||||
auto buffer = JS::ArrayBuffer::create(realm, move(bytes));
|
ByteBuffer concatenated_byte_chunks;
|
||||||
|
for (auto const& chunk : byte_chunks)
|
||||||
|
concatenated_byte_chunks.append(chunk);
|
||||||
|
|
||||||
|
auto buffer = JS::ArrayBuffer::create(realm, move(concatenated_byte_chunks));
|
||||||
WebIDL::resolve_promise(realm, promise, buffer);
|
WebIDL::resolve_promise(realm, promise, buffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class ReadLoopReadRequest final : public ReadRequest {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// successSteps, which is an algorithm accepting a byte sequence
|
// successSteps, which is an algorithm accepting a byte sequence
|
||||||
using SuccessSteps = JS::SafeFunction<void(ByteBuffer)>;
|
using SuccessSteps = JS::SafeFunction<void(Vector<ByteBuffer> const&)>;
|
||||||
|
|
||||||
// failureSteps, which is an algorithm accepting a JavaScript value
|
// failureSteps, which is an algorithm accepting a JavaScript value
|
||||||
using FailureSteps = JS::SafeFunction<void(JS::Value error)>;
|
using FailureSteps = JS::SafeFunction<void(JS::Value error)>;
|
||||||
|
@ -55,7 +55,7 @@ private:
|
||||||
JS::VM& m_vm;
|
JS::VM& m_vm;
|
||||||
JS::NonnullGCPtr<JS::Realm> m_realm;
|
JS::NonnullGCPtr<JS::Realm> m_realm;
|
||||||
JS::NonnullGCPtr<ReadableStreamDefaultReader> m_reader;
|
JS::NonnullGCPtr<ReadableStreamDefaultReader> m_reader;
|
||||||
ByteBuffer m_bytes;
|
Vector<ByteBuffer> m_byte_chunks;
|
||||||
SuccessSteps m_success_steps;
|
SuccessSteps m_success_steps;
|
||||||
FailureSteps m_failure_steps;
|
FailureSteps m_failure_steps;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue