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().
This commit is contained in:
Timothy Flynn 2023-03-18 10:39:37 -04:00 committed by Jelle Raaijmakers
parent 0d0b87fd46
commit db2ba5f1d9
Notes: sideshowbarker 2024-07-17 22:55:25 +09:00
19 changed files with 74 additions and 27 deletions

View file

@ -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 {};
}
}