mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 09:20:28 +03:00
AK: Make "foo"_fly_string infallible
Stop worrying about tiny OOMs. Work towards #20405.
This commit is contained in:
parent
34344120f2
commit
25eee91811
Notes:
sideshowbarker
2024-07-17 05:23:40 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/25eee91811 Pull-request: https://github.com/SerenityOS/serenity/pull/20408
@ -89,9 +89,9 @@ struct Formatter<FlyString> : Formatter<StringView> {
|
||||
|
||||
}
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE AK::ErrorOr<AK::FlyString> operator""_fly_string(char const* cstring, size_t length)
|
||||
[[nodiscard]] ALWAYS_INLINE AK::FlyString operator""_fly_string(char const* cstring, size_t length)
|
||||
{
|
||||
return AK::FlyString::from_utf8(AK::StringView(cstring, length));
|
||||
return AK::FlyString::from_utf8(AK::StringView(cstring, length)).release_value();
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
|
@ -68,15 +68,15 @@ TEST_CASE(long_string)
|
||||
|
||||
TEST_CASE(from_string_view)
|
||||
{
|
||||
auto fly1 = MUST("thisisdefinitelymorethan7bytes"_fly_string);
|
||||
auto fly1 = "thisisdefinitelymorethan7bytes"_fly_string;
|
||||
EXPECT_EQ(fly1, "thisisdefinitelymorethan7bytes"sv);
|
||||
EXPECT_EQ(FlyString::number_of_fly_strings(), 1u);
|
||||
|
||||
auto fly2 = MUST("thisisdefinitelymorethan7bytes"_fly_string);
|
||||
auto fly2 = "thisisdefinitelymorethan7bytes"_fly_string;
|
||||
EXPECT_EQ(fly2, "thisisdefinitelymorethan7bytes"sv);
|
||||
EXPECT_EQ(FlyString::number_of_fly_strings(), 1u);
|
||||
|
||||
auto fly3 = MUST("foo"_fly_string);
|
||||
auto fly3 = "foo"_fly_string;
|
||||
EXPECT_EQ(fly3, "foo"sv);
|
||||
EXPECT_EQ(FlyString::number_of_fly_strings(), 1u);
|
||||
|
||||
|
@ -82,19 +82,19 @@ ErrorOr<void> initialize_main_thread_vm()
|
||||
s_main_thread_vm->ref();
|
||||
|
||||
// These strings could potentially live on the VM similar to CommonPropertyNames.
|
||||
TRY(DOM::MutationType::initialize_strings());
|
||||
TRY(HTML::AttributeNames::initialize_strings());
|
||||
TRY(HTML::CustomElementReactionNames::initialize_strings());
|
||||
TRY(HTML::EventNames::initialize_strings());
|
||||
TRY(HTML::TagNames::initialize_strings());
|
||||
TRY(Namespace::initialize_strings());
|
||||
TRY(NavigationTiming::EntryNames::initialize_strings());
|
||||
TRY(PerformanceTimeline::EntryTypes::initialize_strings());
|
||||
TRY(SVG::AttributeNames::initialize_strings());
|
||||
TRY(SVG::TagNames::initialize_strings());
|
||||
TRY(UIEvents::EventNames::initialize_strings());
|
||||
TRY(WebGL::EventNames::initialize_strings());
|
||||
TRY(XHR::EventNames::initialize_strings());
|
||||
DOM::MutationType::initialize_strings();
|
||||
HTML::AttributeNames::initialize_strings();
|
||||
HTML::CustomElementReactionNames::initialize_strings();
|
||||
HTML::EventNames::initialize_strings();
|
||||
HTML::TagNames::initialize_strings();
|
||||
Namespace::initialize_strings();
|
||||
NavigationTiming::EntryNames::initialize_strings();
|
||||
PerformanceTimeline::EntryTypes::initialize_strings();
|
||||
SVG::AttributeNames::initialize_strings();
|
||||
SVG::TagNames::initialize_strings();
|
||||
UIEvents::EventNames::initialize_strings();
|
||||
WebGL::EventNames::initialize_strings();
|
||||
XHR::EventNames::initialize_strings();
|
||||
|
||||
static_cast<WebEngineCustomData*>(s_main_thread_vm->custom_data())->event_loop.set_vm(*s_main_thread_vm);
|
||||
|
||||
|
@ -12,17 +12,16 @@ namespace Web::DOM::MutationType {
|
||||
ENUMERATE_MUTATION_TYPES
|
||||
#undef __ENUMERATE_MUTATION_TYPE
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
|
||||
#define __ENUMERATE_MUTATION_TYPE(name) name = TRY(#name##_fly_string);
|
||||
#define __ENUMERATE_MUTATION_TYPE(name) name = #name##_fly_string;
|
||||
ENUMERATE_MUTATION_TYPES
|
||||
#undef __ENUMERATE_MUTATION_TYPE
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace Web::DOM::MutationType {
|
||||
ENUMERATE_MUTATION_TYPES
|
||||
#undef __ENUMERATE_MUTATION_TYPE
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace AttributeNames {
|
||||
ENUMERATE_HTML_ATTRIBUTES
|
||||
#undef __ENUMERATE_HTML_ATTRIBUTE
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
@ -34,7 +34,6 @@ ErrorOr<void> initialize_strings()
|
||||
http_equiv = "http-equiv";
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ namespace AttributeNames {
|
||||
ENUMERATE_HTML_ATTRIBUTES
|
||||
#undef __ENUMERATE_HTML_ATTRIBUTE
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
||||
|
@ -12,18 +12,17 @@ namespace Web::HTML::CustomElementReactionNames {
|
||||
ENUMERATE_CUSTOM_ELEMENT_REACTION_NAMES
|
||||
#undef __ENUMERATE_CUSTOM_ELEMENT_REACTION_NAME
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
|
||||
#define __ENUMERATE_CUSTOM_ELEMENT_REACTION_NAME(name) \
|
||||
name = TRY(#name##_fly_string);
|
||||
name = #name##_fly_string;
|
||||
ENUMERATE_CUSTOM_ELEMENT_REACTION_NAMES
|
||||
#undef __ENUMERATE_CUSTOM_ELEMENT_REACTION_NAME
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ namespace Web::HTML::CustomElementReactionNames {
|
||||
ENUMERATE_CUSTOM_ELEMENT_REACTION_NAMES
|
||||
#undef __ENUMERATE_CUSTOM_ELEMENT_REACTION_NAME
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,18 +12,17 @@ namespace Web::HTML::EventNames {
|
||||
ENUMERATE_HTML_EVENTS
|
||||
#undef __ENUMERATE_HTML_EVENT
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
|
||||
#define __ENUMERATE_HTML_EVENT(name) \
|
||||
name = TRY(#name##_fly_string);
|
||||
name = #name##_fly_string;
|
||||
ENUMERATE_HTML_EVENTS
|
||||
#undef __ENUMERATE_HTML_EVENT
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -106,6 +106,6 @@ namespace Web::HTML::EventNames {
|
||||
ENUMERATE_HTML_EVENTS
|
||||
#undef __ENUMERATE_HTML_EVENT
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::load_element()
|
||||
|
||||
// 2. Take pending play promises and reject pending play promises with the result and an "AbortError" DOMException.
|
||||
auto promises = take_pending_play_promises();
|
||||
reject_pending_play_promises<WebIDL::AbortError>(promises, TRY_OR_THROW_OOM(vm, "Media playback was aborted"_fly_string));
|
||||
reject_pending_play_promises<WebIDL::AbortError>(promises, "Media playback was aborted"_fly_string);
|
||||
}
|
||||
|
||||
// 7. If seeking is true, set it to false.
|
||||
@ -1251,7 +1251,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::handle_media_source_failure(Span<JS:
|
||||
dispatch_event(TRY(DOM::Event::create(realm, HTML::EventNames::error)));
|
||||
|
||||
// 6. Reject pending play promises with promises and a "NotSupportedError" DOMException.
|
||||
reject_pending_play_promises<WebIDL::NotSupportedError>(promises, TRY_OR_THROW_OOM(vm, "Media is not supported"_fly_string));
|
||||
reject_pending_play_promises<WebIDL::NotSupportedError>(promises, "Media is not supported"_fly_string);
|
||||
|
||||
// 7. Set the element's delaying-the-load-event flag to false. This stops delaying the load event.
|
||||
m_delaying_the_load_event.clear();
|
||||
@ -1477,7 +1477,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::pause_element()
|
||||
dispatch_event(DOM::Event::create(realm, HTML::EventNames::pause).release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
// 3. Reject pending play promises with promises and an "AbortError" DOMException.
|
||||
reject_pending_play_promises<WebIDL::AbortError>(promises, "Media playback was paused"_fly_string.release_value_but_fixme_should_propagate_errors());
|
||||
reject_pending_play_promises<WebIDL::AbortError>(promises, "Media playback was paused"_fly_string);
|
||||
});
|
||||
|
||||
// 4. Set the official playback position to the current playback position.
|
||||
@ -1724,7 +1724,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::reached_end_of_media_playback()
|
||||
|
||||
// 3. Take pending play promises and reject pending play promises with the result and an "AbortError" DOMException.
|
||||
auto promises = take_pending_play_promises();
|
||||
reject_pending_play_promises<WebIDL::AbortError>(promises, "Media playback has ended"_fly_string.release_value_but_fixme_should_propagate_errors());
|
||||
reject_pending_play_promises<WebIDL::AbortError>(promises, "Media playback has ended"_fly_string);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace Web::HTML::TagNames {
|
||||
ENUMERATE_HTML_TAGS
|
||||
#undef __ENUMERATE_HTML_TAG
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
@ -25,7 +25,6 @@ ErrorOr<void> initialize_strings()
|
||||
template_ = "template";
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -161,6 +161,6 @@ namespace Web::HTML::TagNames {
|
||||
ENUMERATE_HTML_TAGS
|
||||
#undef __ENUMERATE_HTML_TAG
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Web::Namespace {
|
||||
ENUMERATE_NAMESPACES
|
||||
#undef __ENUMERATE_NAMESPACE
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
@ -23,7 +23,6 @@ ErrorOr<void> initialize_strings()
|
||||
#undef __ENUMERATE_NAMESPACE
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ namespace Web::Namespace {
|
||||
ENUMERATE_NAMESPACES
|
||||
#undef __ENUMERATE_NAMESPACE
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,18 +12,17 @@ namespace Web::NavigationTiming::EntryNames {
|
||||
ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES
|
||||
#undef __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
|
||||
#define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(name, _) \
|
||||
name = TRY(#name##_fly_string);
|
||||
name = #name##_fly_string;
|
||||
ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES
|
||||
#undef __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,6 @@ namespace Web::NavigationTiming::EntryNames {
|
||||
ENUMERATE_NAVIGATION_TIMING_ENTRY_NAMES
|
||||
#undef __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,23 +12,22 @@ namespace Web::PerformanceTimeline::EntryTypes {
|
||||
ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPES
|
||||
#undef __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
|
||||
#define __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE(name) \
|
||||
name = TRY(#name##_fly_string);
|
||||
name = #name##_fly_string;
|
||||
ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPES
|
||||
#undef __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE
|
||||
|
||||
// NOTE: Special cases for attributes with dashes in them.
|
||||
first_input = TRY("first-input"_fly_string);
|
||||
largest_contentful_paint = TRY("largest-contentful-paint"_fly_string);
|
||||
layout_shift = TRY("layout-shift"_fly_string);
|
||||
first_input = "first-input"_fly_string;
|
||||
largest_contentful_paint = "largest-contentful-paint"_fly_string;
|
||||
layout_shift = "layout-shift"_fly_string;
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,6 @@ namespace Web::PerformanceTimeline::EntryTypes {
|
||||
ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPES
|
||||
#undef __ENUMERATE_PERFORMANCE_TIMELINE_ENTRY_TYPE
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Web::SVG::AttributeNames {
|
||||
ENUMERATE_SVG_ATTRIBUTES(__ENUMERATE_SVG_ATTRIBUTE)
|
||||
#undef __ENUMERATE_SVG_ATTRIBUTE
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
@ -23,7 +23,6 @@ ErrorOr<void> initialize_strings()
|
||||
#undef __ENUMERATE_SVG_ATTRIBUTE
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -100,6 +100,6 @@ namespace Web::SVG::AttributeNames {
|
||||
ENUMERATE_SVG_ATTRIBUTES(__ENUMERATE_SVG_ATTRIBUTE)
|
||||
#undef __ENUMERATE_SVG_ATTRIBUTE
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Web::SVG::TagNames {
|
||||
ENUMERATE_SVG_TAGS
|
||||
#undef __ENUMERATE_SVG_TAG
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
@ -22,7 +22,6 @@ ErrorOr<void> initialize_strings()
|
||||
#undef __ENUMERATE_SVG_TAG
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,6 +43,6 @@ namespace Web::SVG::TagNames {
|
||||
ENUMERATE_SVG_TAGS
|
||||
#undef __ENUMERATE_SVG_TAG
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,18 +12,17 @@ namespace Web::UIEvents::EventNames {
|
||||
ENUMERATE_UI_EVENTS
|
||||
#undef __ENUMERATE_UI_EVENT
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
|
||||
#define __ENUMERATE_UI_EVENT(name) \
|
||||
name = TRY(#name##_fly_string);
|
||||
name = #name##_fly_string;
|
||||
ENUMERATE_UI_EVENTS
|
||||
#undef __ENUMERATE_UI_EVENT
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,6 +36,6 @@ namespace Web::UIEvents::EventNames {
|
||||
ENUMERATE_UI_EVENTS
|
||||
#undef __ENUMERATE_UI_EVENT
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,18 +12,17 @@ namespace Web::WebGL::EventNames {
|
||||
ENUMERATE_GL_EVENTS
|
||||
#undef __ENUMERATE_GL_EVENT
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
|
||||
#define __ENUMERATE_GL_EVENT(name) \
|
||||
name = TRY(#name##_fly_string);
|
||||
name = #name##_fly_string;
|
||||
ENUMERATE_GL_EVENTS
|
||||
#undef __ENUMERATE_GL_EVENT
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace Web::WebGL::EventNames {
|
||||
ENUMERATE_GL_EVENTS
|
||||
#undef __ENUMERATE_GL_EVENT
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
@ -12,18 +12,17 @@ namespace Web::XHR::EventNames {
|
||||
ENUMERATE_XHR_EVENTS
|
||||
#undef __ENUMERATE_XHR_EVENT
|
||||
|
||||
ErrorOr<void> initialize_strings()
|
||||
void initialize_strings()
|
||||
{
|
||||
static bool s_initialized = false;
|
||||
VERIFY(!s_initialized);
|
||||
|
||||
#define __ENUMERATE_XHR_EVENT(name) \
|
||||
name = TRY(#name##_fly_string);
|
||||
name = #name##_fly_string;
|
||||
ENUMERATE_XHR_EVENTS
|
||||
#undef __ENUMERATE_XHR_EVENT
|
||||
|
||||
s_initialized = true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ namespace Web::XHR::EventNames {
|
||||
ENUMERATE_XHR_EVENTS
|
||||
#undef __ENUMERATE_XHR_EVENT
|
||||
|
||||
ErrorOr<void> initialize_strings();
|
||||
void initialize_strings();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user