mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:18:12 +00:00
LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449. While going through these, I also changed the function signature in many places where returning ThrowCompletionOr<T> is no longer necessary.
This commit is contained in:
parent
980e7164fe
commit
72c9f56c66
337 changed files with 1229 additions and 1251 deletions
|
@ -22,9 +22,9 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::create(JS::Realm& realm, ByteBuffer byte_buffer, String type)
|
||||
JS::NonnullGCPtr<Blob> Blob::create(JS::Realm& realm, ByteBuffer byte_buffer, String type)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<Blob>(realm, realm, move(byte_buffer), move(type)));
|
||||
return realm.heap().allocate<Blob>(realm, realm, move(byte_buffer), move(type));
|
||||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#convert-line-endings-to-native
|
||||
|
@ -146,18 +146,16 @@ void Blob::initialize(JS::Realm& realm)
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#ref-for-dom-blob-blob
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::create(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
||||
JS::NonnullGCPtr<Blob> Blob::create(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
||||
{
|
||||
auto& vm = realm.vm();
|
||||
|
||||
// 1. If invoked with zero parameters, return a new Blob object consisting of 0 bytes, with size set to 0, and with type set to the empty string.
|
||||
if (!blob_parts.has_value() && !options.has_value())
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<Blob>(realm, realm));
|
||||
return realm.heap().allocate<Blob>(realm, realm);
|
||||
|
||||
ByteBuffer byte_buffer {};
|
||||
// 2. Let bytes be the result of processing blob parts given blobParts and options.
|
||||
if (blob_parts.has_value()) {
|
||||
byte_buffer = TRY_OR_THROW_OOM(realm.vm(), process_blob_parts(blob_parts.value(), options));
|
||||
byte_buffer = MUST(process_blob_parts(blob_parts.value(), options));
|
||||
}
|
||||
|
||||
auto type = String {};
|
||||
|
@ -173,11 +171,11 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::create(JS::Realm& realm, Optio
|
|||
|
||||
// 2. Convert every character in t to ASCII lowercase.
|
||||
if (!type.is_empty())
|
||||
type = TRY_OR_THROW_OOM(vm, Infra::to_ascii_lowercase(type));
|
||||
type = MUST(Infra::to_ascii_lowercase(type));
|
||||
}
|
||||
|
||||
// 4. Return a Blob object referring to bytes as its associated byte sequence, with its size set to the length of bytes, and its type set to the value of t from the substeps above.
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<Blob>(realm, realm, move(byte_buffer), move(type)));
|
||||
return realm.heap().allocate<Blob>(realm, realm, move(byte_buffer), move(type));
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::construct_impl(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
||||
|
@ -250,7 +248,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::slice(Optional<i64> start, Opt
|
|||
// b. S.size = span.
|
||||
// c. S.type = relativeContentType.
|
||||
auto byte_buffer = TRY_OR_THROW_OOM(vm, m_byte_buffer.slice(relative_start, span));
|
||||
return MUST_OR_THROW_OOM(heap().allocate<Blob>(realm(), realm(), move(byte_buffer), move(relative_content_type)));
|
||||
return heap().allocate<Blob>(realm(), realm(), move(byte_buffer), move(relative_content_type));
|
||||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dom-blob-stream
|
||||
|
@ -266,7 +264,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Streams::ReadableStream>> Blob::get_stream(
|
|||
auto& realm = this->realm();
|
||||
|
||||
// 1. Let stream be a new ReadableStream created in blob’s relevant Realm.
|
||||
auto stream = MUST_OR_THROW_OOM(realm.heap().allocate<Streams::ReadableStream>(realm, realm));
|
||||
auto stream = realm.heap().allocate<Streams::ReadableStream>(realm, realm);
|
||||
|
||||
// 2. Set up stream with byte reading support.
|
||||
TRY(set_up_readable_stream_controller_with_byte_reading_support(stream));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue