1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:47:35 +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:
davidot 2022-02-07 13:34:32 +01:00 committed by Linus Groh
parent 4136cbdb09
commit de90d54be0
7 changed files with 30 additions and 26 deletions

View file

@ -10,13 +10,12 @@
namespace JS {
ArrayBuffer* ArrayBuffer::create(GlobalObject& global_object, size_t byte_length)
ThrowCompletionOr<ArrayBuffer*> ArrayBuffer::create(GlobalObject& global_object, size_t byte_length)
{
auto buffer = ByteBuffer::create_zeroed(byte_length);
if (buffer.is_error()) {
global_object.vm().throw_exception<RangeError>(global_object, ErrorType::NotEnoughMemoryToAllocate, byte_length);
return nullptr;
}
if (buffer.is_error())
return global_object.vm().throw_completion<RangeError>(global_object, ErrorType::NotEnoughMemoryToAllocate, byte_length);
return global_object.heap().allocate<ArrayBuffer>(global_object, buffer.release_value(), *global_object.array_buffer_prototype());
}