LibWeb: Use get_buffer_source_copy for getting the actual byte buffer

`WebIDL::underlying_buffer_source` gets the underlying buffer source
which is not resized according to, for example, `subarray`.
This commit is contained in:
devgianlu 2025-03-01 19:26:17 +01:00 committed by Jelle Raaijmakers
parent e02521911a
commit 033ba43faf
Notes: github-actions[bot] 2025-03-19 12:47:55 +00:00
3 changed files with 8 additions and 12 deletions

View file

@ -115,9 +115,8 @@ WebIDL::ExceptionOr<void> CompressionStream::compress_and_enqueue_chunk(JS::Valu
// 2. Let buffer be the result of compressing chunk with cs's format and context.
auto maybe_buffer = [&]() -> ErrorOr<ByteBuffer> {
if (auto buffer = WebIDL::underlying_buffer_source(chunk.as_object()))
return compress(buffer->buffer(), Finish::No);
return ByteBuffer {};
auto chunk_buffer = TRY(WebIDL::get_buffer_source_copy(chunk.as_object()));
return compress(move(chunk_buffer), Finish::No);
}();
if (maybe_buffer.is_error())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Unable to compress chunk: {}", maybe_buffer.error())) };