ladybird/Userland/Libraries/LibWeb/Namespace.cpp
Timothy Flynn db2ba5f1d9 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().
2023-03-18 19:50:45 +01:00

30 lines
565 B
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Namespace.h>
namespace Web::Namespace {
#define __ENUMERATE_NAMESPACE(name, namespace_) DeprecatedFlyString name;
ENUMERATE_NAMESPACES
#undef __ENUMERATE_NAMESPACE
ErrorOr<void> initialize_strings()
{
static bool s_initialized = false;
VERIFY(!s_initialized);
#define __ENUMERATE_NAMESPACE(name, namespace_) \
name = namespace_;
ENUMERATE_NAMESPACES
#undef __ENUMERATE_NAMESPACE
s_initialized = true;
return {};
}
}