1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:07:45 +00:00

AK: Make "foo"_string infallible

Stop worrying about tiny OOMs.

Work towards #20405.
This commit is contained in:
Andreas Kling 2023-08-07 11:12:38 +02:00
parent db2a8725c6
commit 34344120f2
181 changed files with 626 additions and 630 deletions

View file

@ -226,10 +226,10 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
disabled_features = TRY(convert_value_to_sequence_of_strings(vm, disabled_features_iterable));
// 9. Set disableInternals to true if disabledFeatures contains "internals".
disable_internals = disabled_features.contains_slow(TRY_OR_THROW_OOM(vm, "internals"_string));
disable_internals = disabled_features.contains_slow("internals"_string);
// 10. Set disableShadow to true if disabledFeatures contains "shadow".
disable_shadow = disabled_features.contains_slow(TRY_OR_THROW_OOM(vm, "shadow"_string));
disable_shadow = disabled_features.contains_slow("shadow"_string);
// 11. Let formAssociatedValue be ? Get( constructor, "formAssociated").
auto form_associated_value = TRY(constructor->callback->get(JS::PropertyKey { "formAssociated" }));

View file

@ -37,7 +37,7 @@ WebIDL::ExceptionOr<XHR::FormDataEntry> create_entry(JS::Realm& realm, String co
if (filename.has_value())
name_attribute = filename.value();
else
name_attribute = TRY_OR_THROW_OOM(vm, "blob"_string);
name_attribute = "blob"_string;
return JS::make_handle(TRY(FileAPI::File::create(realm, { JS::make_handle(*blob) }, move(name_attribute), {})));
}));
@ -136,7 +136,7 @@ WebIDL::ExceptionOr<Optional<Vector<XHR::FormDataEntry>>> construct_entry_list(J
// 1. If there are no selected files, then create an entry with name and a new File object with an empty name, application/octet-stream as type, and an empty body, and append it to entry list.
if (file_element->files()->length() == 0) {
FileAPI::FilePropertyBag options {};
options.type = TRY_OR_THROW_OOM(vm, "application/octet-stream"_string);
options.type = "application/octet-stream"_string;
auto file = TRY(FileAPI::File::create(realm, {}, String {}, options));
TRY_OR_THROW_OOM(vm, entry_list.try_append(XHR::FormDataEntry { .name = move(name), .value = JS::make_handle(file) }));
}
@ -151,7 +151,7 @@ WebIDL::ExceptionOr<Optional<Vector<XHR::FormDataEntry>>> construct_entry_list(J
// 9. Otherwise, if the field element is an input element whose type attribute is in the Hidden state and name is an ASCII case-insensitive match for "_charset_":
else if (auto* hidden_input = dynamic_cast<HTML::HTMLInputElement*>(control.ptr()); hidden_input && hidden_input->type_state() == HTMLInputElement::TypeAttributeState::Hidden && Infra::is_ascii_case_insensitive_match(name, "_charset_"sv)) {
// 1. Let charset be the name of encoding if encoding is given, and "UTF-8" otherwise.
auto charset = encoding.has_value() ? encoding.value() : TRY_OR_THROW_OOM(vm, "UTF-8"_string);
auto charset = encoding.has_value() ? encoding.value() : "UTF-8"_string;
// 2. Create an entry with name and charset, and append it to entry list.
TRY_OR_THROW_OOM(vm, entry_list.try_append(XHR::FormDataEntry { .name = move(name), .value = move(charset) }));

View file

@ -829,7 +829,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::select_resource()
// 1. ⌛ If the src attribute's value is the empty string, then end the synchronous section, and jump down to the failed with attribute step below.
auto source = attribute(HTML::AttributeNames::src);
if (source.is_empty()) {
failed_with_attribute(TRY_OR_THROW_OOM(vm, "The 'src' attribute is empty"_string));
failed_with_attribute("The 'src' attribute is empty"_string);
return {};
}
@ -850,7 +850,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::select_resource()
return {};
}
failed_with_attribute(TRY_OR_THROW_OOM(vm, "Failed to parse 'src' attribute as a URL"_string));
failed_with_attribute("Failed to parse 'src' attribute as a URL"_string);
// 8. Return. The element won't attempt to load another resource until this algorithm is triggered again.
return {};

View file

@ -98,7 +98,7 @@ void MessagePort::post_message(JS::Value message)
main_thread_event_loop().task_queue().add(HTML::Task::create(HTML::Task::Source::PostedMessage, nullptr, [target_port, message] {
MessageEventInit event_init {};
event_init.data = message;
event_init.origin = "<origin>"_string.release_value_but_fixme_should_propagate_errors();
event_init.origin = "<origin>"_string;
target_port->dispatch_event(MessageEvent::create(target_port->realm(), HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors());
}));
}

View file

@ -35,10 +35,10 @@ String const& MimeType::type() const
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-mimetype-description
JS::ThrowCompletionOr<String> MimeType::description() const
String MimeType::description() const
{
// The MimeType interface's description getter steps are to return "Portable Document Format".
static String description_string = TRY_OR_THROW_OOM(vm(), "Portable Document Format"_string);
static String description_string = "Portable Document Format"_string;
return description_string;
}

View file

@ -18,7 +18,7 @@ public:
virtual ~MimeType() override;
String const& type() const;
JS::ThrowCompletionOr<String> description() const;
String description() const;
String const& suffixes() const;
JS::NonnullGCPtr<Plugin> enabled_plugin() const;

View file

@ -36,18 +36,18 @@ String const& Plugin::name() const
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-plugin-description
JS::ThrowCompletionOr<String> Plugin::description() const
String Plugin::description() const
{
// The Plugin interface's description getter steps are to return "Portable Document Format".
static String description_string = TRY_OR_THROW_OOM(vm(), "Portable Document Format"_string);
static String description_string = "Portable Document Format"_string;
return description_string;
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-plugin-filename
JS::ThrowCompletionOr<String> Plugin::filename() const
String Plugin::filename() const
{
// The Plugin interface's filename getter steps are to return "internal-pdf-viewer".
static String filename_string = TRY_OR_THROW_OOM(vm(), "internal-pdf-viewer"_string);
static String filename_string = "internal-pdf-viewer"_string;
return filename_string;
}

View file

@ -18,8 +18,8 @@ public:
virtual ~Plugin() override;
String const& name() const;
JS::ThrowCompletionOr<String> description() const;
JS::ThrowCompletionOr<String> filename() const;
String description() const;
String filename() const;
size_t length() const;
JS::GCPtr<MimeType> item(u32 index) const;
JS::GCPtr<MimeType> named_item(String const& name) const;

View file

@ -730,11 +730,11 @@ Vector<JS::NonnullGCPtr<Plugin>> Window::pdf_viewer_plugin_objects()
if (m_pdf_viewer_plugin_objects.is_empty()) {
// FIXME: Propagate errors.
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "PDF Viewer"_string.release_value_but_fixme_should_propagate_errors()).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "Chrome PDF Viewer"_string.release_value_but_fixme_should_propagate_errors()).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "Chromium PDF Viewer"_string.release_value_but_fixme_should_propagate_errors()).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "Microsoft Edge PDF Viewer"_string.release_value_but_fixme_should_propagate_errors()).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "WebKit built-in PDF"_string.release_value_but_fixme_should_propagate_errors()).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "PDF Viewer"_string).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "Chrome PDF Viewer"_string).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "Chromium PDF Viewer"_string).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "Microsoft Edge PDF Viewer"_string).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_plugin_objects.append(realm().heap().allocate<Plugin>(realm(), realm(), "WebKit built-in PDF"_string).release_allocated_value_but_fixme_should_propagate_errors());
}
return m_pdf_viewer_plugin_objects;
@ -753,8 +753,8 @@ Vector<JS::NonnullGCPtr<MimeType>> Window::pdf_viewer_mime_type_objects()
return {};
if (m_pdf_viewer_mime_type_objects.is_empty()) {
m_pdf_viewer_mime_type_objects.append(realm().heap().allocate<MimeType>(realm(), realm(), "application/pdf"_string.release_value_but_fixme_should_propagate_errors()).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_mime_type_objects.append(realm().heap().allocate<MimeType>(realm(), realm(), "text/pdf"_string.release_value_but_fixme_should_propagate_errors()).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_mime_type_objects.append(realm().heap().allocate<MimeType>(realm(), realm(), "application/pdf"_string).release_allocated_value_but_fixme_should_propagate_errors());
m_pdf_viewer_mime_type_objects.append(realm().heap().allocate<MimeType>(realm(), realm(), "text/pdf"_string).release_allocated_value_but_fixme_should_propagate_errors());
}
return m_pdf_viewer_mime_type_objects;
@ -1042,7 +1042,7 @@ void Window::post_message(JS::Value message, String const&)
queue_global_task(Task::Source::PostedMessage, *this, [this, message] {
MessageEventInit event_init {};
event_init.data = message;
event_init.origin = "<origin>"_string.release_value_but_fixme_should_propagate_errors();
event_init.origin = "<origin>"_string;
dispatch_event(MessageEvent::create(realm(), EventNames::message, event_init).release_value_but_fixme_should_propagate_errors());
});
}

View file

@ -169,7 +169,7 @@ void Worker::run_a_worker(AK::URL& url, EnvironmentSettingsObject& outside_setti
event_loop.task_queue().add(HTML::Task::create(HTML::Task::Source::PostedMessage, nullptr, [this, message] {
MessageEventInit event_init {};
event_init.data = message;
event_init.origin = "<origin>"_string.release_value_but_fixme_should_propagate_errors();
event_init.origin = "<origin>"_string;
dispatch_event(MessageEvent::create(*m_worker_realm, HTML::EventNames::message, event_init).release_value_but_fixme_should_propagate_errors());
}));

View file

@ -26,8 +26,8 @@
namespace Web::HTML {
struct WorkerOptions {
String type { "classic"_string.release_value_but_fixme_should_propagate_errors() };
String credentials { "same-origin"_string.release_value_but_fixme_should_propagate_errors() };
String type { "classic"_string };
String credentials { "same-origin"_string };
String name { String {} };
};