LibWeb: Remove OOM propagation from Fetch::Body

This commit is contained in:
Timothy Flynn 2024-04-27 10:15:01 -04:00 committed by Andreas Kling
commit 3e991a55fa
Notes: sideshowbarker 2024-07-17 07:09:53 +09:00
6 changed files with 8 additions and 8 deletions

View file

@ -112,7 +112,7 @@ WebIDL::ExceptionOr<JS::Value> package_data(JS::Realm& realm, ByteBuffer bytes,
case PackageDataType::Blob: { case PackageDataType::Blob: {
// Return a Blob whose contents are bytes and type attribute is mimeType. // Return a Blob whose contents are bytes and type attribute is mimeType.
// NOTE: If extracting the mime type returns failure, other browsers set it to an empty string - not sure if that's spec'd. // NOTE: If extracting the mime type returns failure, other browsers set it to an empty string - not sure if that's spec'd.
auto mime_type_string = mime_type.has_value() ? TRY_OR_THROW_OOM(vm, mime_type->serialized()) : String {}; auto mime_type_string = mime_type.has_value() ? MUST(mime_type->serialized()) : String {};
return FileAPI::Blob::create(realm, move(bytes), move(mime_type_string)); return FileAPI::Blob::create(realm, move(bytes), move(mime_type_string));
} }
case PackageDataType::FormData: case PackageDataType::FormData:
@ -142,7 +142,7 @@ WebIDL::ExceptionOr<JS::Value> package_data(JS::Realm& realm, ByteBuffer bytes,
auto decoder = TextCodec::decoder_for("UTF-8"sv); auto decoder = TextCodec::decoder_for("UTF-8"sv);
VERIFY(decoder.has_value()); VERIFY(decoder.has_value());
auto utf8_text = TRY_OR_THROW_OOM(vm, TextCodec::convert_input_to_utf8_using_given_decoder_unless_there_is_a_byte_order_mark(*decoder, bytes)); auto utf8_text = MUST(TextCodec::convert_input_to_utf8_using_given_decoder_unless_there_is_a_byte_order_mark(*decoder, bytes));
return JS::PrimitiveString::create(vm, move(utf8_text)); return JS::PrimitiveString::create(vm, move(utf8_text));
} }
default: default:
@ -181,7 +181,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> consume_body(JS::Realm& realm
HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) };
auto value_or_error = Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::Value> { auto value_or_error = Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr<JS::Value> {
return package_data(realm, data, type, TRY_OR_THROW_OOM(vm, object.mime_type_impl())); return package_data(realm, data, type, object.mime_type_impl());
}); });
if (value_or_error.is_error()) { if (value_or_error.is_error()) {

View file

@ -26,7 +26,7 @@ class BodyMixin {
public: public:
virtual ~BodyMixin(); virtual ~BodyMixin();
virtual ErrorOr<Optional<MimeSniff::MimeType>> mime_type_impl() const = 0; virtual Optional<MimeSniff::MimeType> mime_type_impl() const = 0;
virtual JS::GCPtr<Infrastructure::Body> body_impl() = 0; virtual JS::GCPtr<Infrastructure::Body> body_impl() = 0;
virtual JS::GCPtr<Infrastructure::Body const> body_impl() const = 0; virtual JS::GCPtr<Infrastructure::Body const> body_impl() const = 0;
virtual Bindings::PlatformObject& as_platform_object() = 0; virtual Bindings::PlatformObject& as_platform_object() = 0;

View file

@ -47,7 +47,7 @@ void Request::visit_edges(Cell::Visitor& visitor)
// https://fetch.spec.whatwg.org/#concept-body-mime-type // https://fetch.spec.whatwg.org/#concept-body-mime-type
// https://fetch.spec.whatwg.org/#ref-for-concept-body-mime-type%E2%91%A0 // https://fetch.spec.whatwg.org/#ref-for-concept-body-mime-type%E2%91%A0
ErrorOr<Optional<MimeSniff::MimeType>> Request::mime_type_impl() const Optional<MimeSniff::MimeType> Request::mime_type_impl() const
{ {
// Objects including the Body interface mixin need to define an associated MIME type algorithm which takes no arguments and returns failure or a MIME type. // Objects including the Body interface mixin need to define an associated MIME type algorithm which takes no arguments and returns failure or a MIME type.
// A Request objects MIME type is to return the result of extracting a MIME type from its requests header list. // A Request objects MIME type is to return the result of extracting a MIME type from its requests header list.

View file

@ -73,7 +73,7 @@ public:
virtual ~Request() override; virtual ~Request() override;
// ^BodyMixin // ^BodyMixin
virtual ErrorOr<Optional<MimeSniff::MimeType>> mime_type_impl() const override; virtual Optional<MimeSniff::MimeType> mime_type_impl() const override;
virtual JS::GCPtr<Infrastructure::Body> body_impl() override; virtual JS::GCPtr<Infrastructure::Body> body_impl() override;
virtual JS::GCPtr<Infrastructure::Body const> body_impl() const override; virtual JS::GCPtr<Infrastructure::Body const> body_impl() const override;
virtual Bindings::PlatformObject& as_platform_object() override { return *this; } virtual Bindings::PlatformObject& as_platform_object() override { return *this; }

View file

@ -44,7 +44,7 @@ void Response::visit_edges(Cell::Visitor& visitor)
// https://fetch.spec.whatwg.org/#concept-body-mime-type // https://fetch.spec.whatwg.org/#concept-body-mime-type
// https://fetch.spec.whatwg.org/#ref-for-concept-header-extract-mime-type%E2%91%A7 // https://fetch.spec.whatwg.org/#ref-for-concept-header-extract-mime-type%E2%91%A7
ErrorOr<Optional<MimeSniff::MimeType>> Response::mime_type_impl() const Optional<MimeSniff::MimeType> Response::mime_type_impl() const
{ {
// Objects including the Body interface mixin need to define an associated MIME type algorithm which takes no arguments and returns failure or a MIME type. // Objects including the Body interface mixin need to define an associated MIME type algorithm which takes no arguments and returns failure or a MIME type.
// A Response objects MIME type is to return the result of extracting a MIME type from its responses header list. // A Response objects MIME type is to return the result of extracting a MIME type from its responses header list.

View file

@ -40,7 +40,7 @@ public:
virtual ~Response() override; virtual ~Response() override;
// ^BodyMixin // ^BodyMixin
virtual ErrorOr<Optional<MimeSniff::MimeType>> mime_type_impl() const override; virtual Optional<MimeSniff::MimeType> mime_type_impl() const override;
virtual JS::GCPtr<Infrastructure::Body> body_impl() override; virtual JS::GCPtr<Infrastructure::Body> body_impl() override;
virtual JS::GCPtr<Infrastructure::Body const> body_impl() const override; virtual JS::GCPtr<Infrastructure::Body const> body_impl() const override;
virtual Bindings::PlatformObject& as_platform_object() override { return *this; } virtual Bindings::PlatformObject& as_platform_object() override { return *this; }