mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-03 13:02:09 +02: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:
Notes:
sideshowbarker
2024-07-17 19:38:21 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/de90d54be08 Pull-request: https://github.com/SerenityOS/serenity/pull/12343 Reviewed-by: https://github.com/linusg
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user