mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
This commit is contained in:
parent
140f1d9e55
commit
45cf40653a
79 changed files with 202 additions and 274 deletions
|
@ -13,7 +13,7 @@ namespace JS {
|
|||
ArrayBuffer* ArrayBuffer::create(GlobalObject& global_object, size_t byte_length)
|
||||
{
|
||||
auto buffer = ByteBuffer::create_zeroed(byte_length);
|
||||
if (!buffer.has_value()) {
|
||||
if (buffer.is_error()) {
|
||||
global_object.vm().throw_exception<RangeError>(global_object, ErrorType::NotEnoughMemoryToAllocate, byte_length);
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -62,11 +62,11 @@ ThrowCompletionOr<ArrayBuffer*> allocate_array_buffer(GlobalObject& global_objec
|
|||
|
||||
// 2. Let block be ? CreateByteDataBlock(byteLength).
|
||||
auto block = ByteBuffer::create_zeroed(byte_length);
|
||||
if (!block.has_value())
|
||||
if (block.is_error())
|
||||
return global_object.vm().throw_completion<RangeError>(global_object, ErrorType::NotEnoughMemoryToAllocate, byte_length);
|
||||
|
||||
// 3. Set obj.[[ArrayBufferData]] to block.
|
||||
obj->set_buffer(move(*block));
|
||||
obj->set_buffer(block.release_value());
|
||||
|
||||
// 4. Set obj.[[ArrayBufferByteLength]] to byteLength.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue