mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 00:57:44 +00:00
LibJS: Convert ArrayBuffer construction to ThrowCompletionOr
This also allows us to create TypedArrays with an existing buffer thus clearing up an additional FIXME in TextEncoder.
This commit is contained in:
parent
4136cbdb09
commit
de90d54be0
7 changed files with 30 additions and 26 deletions
|
@ -27,11 +27,9 @@ JS::Uint8Array* TextEncoder::encode(String const& input) const
|
|||
// 4. If result is finished, then convert output into a byte sequence and return a Uint8Array object wrapping an ArrayBuffer containing output.
|
||||
|
||||
auto byte_buffer = input.to_byte_buffer();
|
||||
|
||||
// FIXME: Support `TypedArray::create()` with existing `ArrayBuffer`, so that we don't have to allocate two `ByteBuffer`s.
|
||||
auto* typed_array = JS::Uint8Array::create(global_object, byte_buffer.size());
|
||||
typed_array->viewed_array_buffer()->buffer() = move(byte_buffer);
|
||||
return typed_array;
|
||||
auto array_length = byte_buffer.size();
|
||||
auto* array_buffer = JS::ArrayBuffer::create(global_object, move(byte_buffer));
|
||||
return JS::Uint8Array::create(global_object, array_length, *array_buffer);
|
||||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
|
||||
|
|
|
@ -20,9 +20,10 @@ RefPtr<ImageData> ImageData::create_with_size(JS::GlobalObject& global_object, i
|
|||
|
||||
dbgln("Creating ImageData with {}x{}", width, height);
|
||||
|
||||
auto* data = JS::Uint8ClampedArray::create(global_object, width * height * 4);
|
||||
if (!data)
|
||||
auto data_or_error = JS::Uint8ClampedArray::create(global_object, width * height * 4);
|
||||
if (data_or_error.is_error())
|
||||
return nullptr;
|
||||
auto* data = data_or_error.release_value();
|
||||
|
||||
auto data_handle = JS::make_handle(data);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue