diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-03-18 10:39:37 -0400 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-03-18 19:50:45 +0100 |
commit | db2ba5f1d9234b51a547ce01c3da8ecd5006ee87 (patch) | |
tree | f373c2bbafe8b1f52724eec7b90ad42883537e53 /Userland/Libraries/LibWeb | |
parent | 0d0b87fd46453e533e6f73a7fd3c13fc9655e85c (diff) | |
download | serenity-db2ba5f1d9234b51a547ce01c3da8ecd5006ee87.zip |
LibWeb: Initialize static web strings during main-thread VM creation
These are currently initialized in a [[gnu::constructor]], which has a
weird initialization order. These constructors are invoked before main()
and, incidentally, before any user-defined default constructors of the
static strings they are initializing.
This will become an issue when these strings are ported to FlyString,
which has a user-defined default constructor. In that scenario, when the
FlyString constructor is executed after the [[gnu::constructor]], the
strings will be "reset" to the empty string.
Instead of relying on a non-standard compiler extension here, let's just
initialize these strings explicitly during main-thread VM creation, as
this now happens in WebContent's main().
Diffstat (limited to 'Userland/Libraries/LibWeb')
19 files changed, 74 insertions, 27 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index 63ee19ef93..7844b16c60 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -19,16 +19,25 @@ #include <LibWeb/Bindings/MainThreadVM.h> #include <LibWeb/Bindings/WindowExposedInterfaces.h> #include <LibWeb/DOM/Document.h> +#include <LibWeb/DOM/MutationType.h> +#include <LibWeb/HTML/AttributeNames.h> +#include <LibWeb/HTML/EventNames.h> #include <LibWeb/HTML/Location.h> #include <LibWeb/HTML/PromiseRejectionEvent.h> #include <LibWeb/HTML/Scripting/ClassicScript.h> #include <LibWeb/HTML/Scripting/Environments.h> #include <LibWeb/HTML/Scripting/ExceptionReporter.h> #include <LibWeb/HTML/Scripting/Fetching.h> +#include <LibWeb/HTML/TagNames.h> #include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/WindowProxy.h> +#include <LibWeb/Namespace.h> #include <LibWeb/Platform/EventLoopPlugin.h> +#include <LibWeb/SVG/AttributeNames.h> +#include <LibWeb/SVG/TagNames.h> +#include <LibWeb/UIEvents/EventNames.h> #include <LibWeb/WebIDL/AbstractOperations.h> +#include <LibWeb/XHR/EventNames.h> namespace Web::Bindings { @@ -64,6 +73,17 @@ ErrorOr<void> initialize_main_thread_vm() // This avoids doing an exhaustive garbage collection on process exit. 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::EventNames::initialize_strings()); + TRY(HTML::TagNames::initialize_strings()); + TRY(Namespace::initialize_strings()); + TRY(SVG::AttributeNames::initialize_strings()); + TRY(SVG::TagNames::initialize_strings()); + TRY(UIEvents::EventNames::initialize_strings()); + TRY(XHR::EventNames::initialize_strings()); + static_cast<WebEngineCustomData*>(s_main_thread_vm->custom_data())->event_loop.set_vm(*s_main_thread_vm); // 8.1.5.1 HostEnsureCanAddPrivateElement(O), https://html.spec.whatwg.org/multipage/webappapis.html#the-hostensurecanaddprivateelement-implementation diff --git a/Userland/Libraries/LibWeb/DOM/MutationType.cpp b/Userland/Libraries/LibWeb/DOM/MutationType.cpp index 976c70a0ec..b14516dfb2 100644 --- a/Userland/Libraries/LibWeb/DOM/MutationType.cpp +++ b/Userland/Libraries/LibWeb/DOM/MutationType.cpp @@ -12,17 +12,17 @@ namespace Web::DOM::MutationType { ENUMERATE_MUTATION_TYPES #undef __ENUMERATE_MUTATION_TYPE -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_MUTATION_TYPE(name) name = #name; ENUMERATE_MUTATION_TYPES #undef __ENUMERATE_MUTATION_TYPE s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/DOM/MutationType.h b/Userland/Libraries/LibWeb/DOM/MutationType.h index e7ddb4c713..709a596e30 100644 --- a/Userland/Libraries/LibWeb/DOM/MutationType.h +++ b/Userland/Libraries/LibWeb/DOM/MutationType.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web::DOM::MutationType { @@ -19,4 +20,6 @@ namespace Web::DOM::MutationType { ENUMERATE_MUTATION_TYPES #undef __ENUMERATE_MUTATION_TYPE +ErrorOr<void> initialize_strings(); + } diff --git a/Userland/Libraries/LibWeb/HTML/AttributeNames.cpp b/Userland/Libraries/LibWeb/HTML/AttributeNames.cpp index 3d4d0b88fa..ead23b4133 100644 --- a/Userland/Libraries/LibWeb/HTML/AttributeNames.cpp +++ b/Userland/Libraries/LibWeb/HTML/AttributeNames.cpp @@ -14,11 +14,10 @@ namespace AttributeNames { ENUMERATE_HTML_ATTRIBUTES #undef __ENUMERATE_HTML_ATTRIBUTE -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_HTML_ATTRIBUTE(name) \ name = #name; @@ -36,6 +35,7 @@ ENUMERATE_HTML_ATTRIBUTES http_equiv = "http-equiv"; s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/HTML/AttributeNames.h b/Userland/Libraries/LibWeb/HTML/AttributeNames.h index 399a820812..10cf26c8c0 100644 --- a/Userland/Libraries/LibWeb/HTML/AttributeNames.h +++ b/Userland/Libraries/LibWeb/HTML/AttributeNames.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web { namespace HTML { @@ -233,6 +234,8 @@ namespace AttributeNames { ENUMERATE_HTML_ATTRIBUTES #undef __ENUMERATE_HTML_ATTRIBUTE +ErrorOr<void> initialize_strings(); + } bool is_boolean_attribute(DeprecatedFlyString const& attribute); diff --git a/Userland/Libraries/LibWeb/HTML/EventNames.cpp b/Userland/Libraries/LibWeb/HTML/EventNames.cpp index f0c0d2e58d..2824b90778 100644 --- a/Userland/Libraries/LibWeb/HTML/EventNames.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventNames.cpp @@ -12,11 +12,10 @@ namespace Web::HTML::EventNames { ENUMERATE_HTML_EVENTS #undef __ENUMERATE_HTML_EVENT -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_HTML_EVENT(name) \ name = #name; @@ -24,6 +23,7 @@ ENUMERATE_HTML_EVENTS #undef __ENUMERATE_HTML_EVENT s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/HTML/EventNames.h b/Userland/Libraries/LibWeb/HTML/EventNames.h index 911f2bd5cf..a55b95813c 100644 --- a/Userland/Libraries/LibWeb/HTML/EventNames.h +++ b/Userland/Libraries/LibWeb/HTML/EventNames.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web::HTML::EventNames { @@ -64,4 +65,6 @@ namespace Web::HTML::EventNames { ENUMERATE_HTML_EVENTS #undef __ENUMERATE_HTML_EVENT +ErrorOr<void> initialize_strings(); + } diff --git a/Userland/Libraries/LibWeb/HTML/TagNames.cpp b/Userland/Libraries/LibWeb/HTML/TagNames.cpp index 435755b9f2..3d0b191303 100644 --- a/Userland/Libraries/LibWeb/HTML/TagNames.cpp +++ b/Userland/Libraries/LibWeb/HTML/TagNames.cpp @@ -12,11 +12,10 @@ namespace Web::HTML::TagNames { ENUMERATE_HTML_TAGS #undef __ENUMERATE_HTML_TAG -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_HTML_TAG(name) \ name = #name; @@ -26,6 +25,7 @@ ENUMERATE_HTML_TAGS template_ = "template"; s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/HTML/TagNames.h b/Userland/Libraries/LibWeb/HTML/TagNames.h index e8fb8dd049..eb0efb7604 100644 --- a/Userland/Libraries/LibWeb/HTML/TagNames.h +++ b/Userland/Libraries/LibWeb/HTML/TagNames.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web::HTML::TagNames { @@ -156,4 +157,6 @@ namespace Web::HTML::TagNames { ENUMERATE_HTML_TAGS #undef __ENUMERATE_HTML_TAG +ErrorOr<void> initialize_strings(); + } diff --git a/Userland/Libraries/LibWeb/Namespace.cpp b/Userland/Libraries/LibWeb/Namespace.cpp index eb05860f04..fa44dfc822 100644 --- a/Userland/Libraries/LibWeb/Namespace.cpp +++ b/Userland/Libraries/LibWeb/Namespace.cpp @@ -12,11 +12,10 @@ namespace Web::Namespace { ENUMERATE_NAMESPACES #undef __ENUMERATE_NAMESPACE -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_NAMESPACE(name, namespace_) \ name = namespace_; @@ -24,6 +23,7 @@ ENUMERATE_NAMESPACES #undef __ENUMERATE_NAMESPACE s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/Namespace.h b/Userland/Libraries/LibWeb/Namespace.h index 330663dfbf..ea13e25874 100644 --- a/Userland/Libraries/LibWeb/Namespace.h +++ b/Userland/Libraries/LibWeb/Namespace.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web::Namespace { @@ -22,4 +23,6 @@ namespace Web::Namespace { ENUMERATE_NAMESPACES #undef __ENUMERATE_NAMESPACE +ErrorOr<void> initialize_strings(); + } diff --git a/Userland/Libraries/LibWeb/SVG/AttributeNames.cpp b/Userland/Libraries/LibWeb/SVG/AttributeNames.cpp index b24c69a2d8..c01f0cb408 100644 --- a/Userland/Libraries/LibWeb/SVG/AttributeNames.cpp +++ b/Userland/Libraries/LibWeb/SVG/AttributeNames.cpp @@ -12,11 +12,10 @@ namespace Web::SVG::AttributeNames { ENUMERATE_SVG_ATTRIBUTES(__ENUMERATE_SVG_ATTRIBUTE) #undef __ENUMERATE_SVG_ATTRIBUTE -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_SVG_ATTRIBUTE(name) \ name = #name; @@ -24,6 +23,7 @@ ENUMERATE_SVG_ATTRIBUTES(__ENUMERATE_SVG_ATTRIBUTE) #undef __ENUMERATE_SVG_ATTRIBUTE s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/SVG/AttributeNames.h b/Userland/Libraries/LibWeb/SVG/AttributeNames.h index 29c64e9718..786de7c486 100644 --- a/Userland/Libraries/LibWeb/SVG/AttributeNames.h +++ b/Userland/Libraries/LibWeb/SVG/AttributeNames.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web::SVG::AttributeNames { @@ -91,4 +92,6 @@ namespace Web::SVG::AttributeNames { ENUMERATE_SVG_ATTRIBUTES(__ENUMERATE_SVG_ATTRIBUTE) #undef __ENUMERATE_SVG_ATTRIBUTE +ErrorOr<void> initialize_strings(); + } diff --git a/Userland/Libraries/LibWeb/SVG/TagNames.cpp b/Userland/Libraries/LibWeb/SVG/TagNames.cpp index fe6b698a32..a2c4a5b574 100644 --- a/Userland/Libraries/LibWeb/SVG/TagNames.cpp +++ b/Userland/Libraries/LibWeb/SVG/TagNames.cpp @@ -12,17 +12,17 @@ namespace Web::SVG::TagNames { ENUMERATE_SVG_TAGS #undef __ENUMERATE_SVG_TAG -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_SVG_TAG(name) name = #name; ENUMERATE_SVG_TAGS #undef __ENUMERATE_SVG_TAG s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/SVG/TagNames.h b/Userland/Libraries/LibWeb/SVG/TagNames.h index f779444591..449c8ac2dc 100644 --- a/Userland/Libraries/LibWeb/SVG/TagNames.h +++ b/Userland/Libraries/LibWeb/SVG/TagNames.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web::SVG::TagNames { @@ -35,4 +36,6 @@ namespace Web::SVG::TagNames { ENUMERATE_SVG_TAGS #undef __ENUMERATE_SVG_TAG +ErrorOr<void> initialize_strings(); + } diff --git a/Userland/Libraries/LibWeb/UIEvents/EventNames.cpp b/Userland/Libraries/LibWeb/UIEvents/EventNames.cpp index a84be33b56..2f2ed22ca5 100644 --- a/Userland/Libraries/LibWeb/UIEvents/EventNames.cpp +++ b/Userland/Libraries/LibWeb/UIEvents/EventNames.cpp @@ -12,11 +12,10 @@ namespace Web::UIEvents::EventNames { ENUMERATE_UI_EVENTS #undef __ENUMERATE_UI_EVENT -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_UI_EVENT(name) \ name = #name; @@ -24,6 +23,7 @@ ENUMERATE_UI_EVENTS #undef __ENUMERATE_UI_EVENT s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/UIEvents/EventNames.h b/Userland/Libraries/LibWeb/UIEvents/EventNames.h index 22e0892804..27dad4c5b1 100644 --- a/Userland/Libraries/LibWeb/UIEvents/EventNames.h +++ b/Userland/Libraries/LibWeb/UIEvents/EventNames.h @@ -8,6 +8,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web::UIEvents::EventNames { @@ -33,4 +34,6 @@ namespace Web::UIEvents::EventNames { ENUMERATE_UI_EVENTS #undef __ENUMERATE_UI_EVENT +ErrorOr<void> initialize_strings(); + } diff --git a/Userland/Libraries/LibWeb/XHR/EventNames.cpp b/Userland/Libraries/LibWeb/XHR/EventNames.cpp index b3848d0b9e..90b747c34e 100644 --- a/Userland/Libraries/LibWeb/XHR/EventNames.cpp +++ b/Userland/Libraries/LibWeb/XHR/EventNames.cpp @@ -12,11 +12,10 @@ namespace Web::XHR::EventNames { ENUMERATE_XHR_EVENTS #undef __ENUMERATE_XHR_EVENT -[[gnu::constructor]] static void initialize() +ErrorOr<void> initialize_strings() { static bool s_initialized = false; - if (s_initialized) - return; + VERIFY(!s_initialized); #define __ENUMERATE_XHR_EVENT(name) \ name = #name; @@ -24,6 +23,7 @@ ENUMERATE_XHR_EVENTS #undef __ENUMERATE_XHR_EVENT s_initialized = true; + return {}; } } diff --git a/Userland/Libraries/LibWeb/XHR/EventNames.h b/Userland/Libraries/LibWeb/XHR/EventNames.h index 9cf36a6102..a543cea26c 100644 --- a/Userland/Libraries/LibWeb/XHR/EventNames.h +++ b/Userland/Libraries/LibWeb/XHR/EventNames.h @@ -7,6 +7,7 @@ #pragma once #include <AK/DeprecatedFlyString.h> +#include <AK/Error.h> namespace Web::XHR::EventNames { @@ -24,4 +25,6 @@ namespace Web::XHR::EventNames { ENUMERATE_XHR_EVENTS #undef __ENUMERATE_XHR_EVENT +ErrorOr<void> initialize_strings(); + } |