mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-11-03 23:00:58 +00:00 
			
		
		
		
	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().
		
			
				
	
	
		
			76 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
 | 
						|
 *
 | 
						|
 * SPDX-License-Identifier: BSD-2-Clause
 | 
						|
 */
 | 
						|
 | 
						|
#include <LibWeb/HTML/AttributeNames.h>
 | 
						|
 | 
						|
namespace Web {
 | 
						|
namespace HTML {
 | 
						|
namespace AttributeNames {
 | 
						|
 | 
						|
#define __ENUMERATE_HTML_ATTRIBUTE(name) DeprecatedFlyString name;
 | 
						|
ENUMERATE_HTML_ATTRIBUTES
 | 
						|
#undef __ENUMERATE_HTML_ATTRIBUTE
 | 
						|
 | 
						|
ErrorOr<void> initialize_strings()
 | 
						|
{
 | 
						|
    static bool s_initialized = false;
 | 
						|
    VERIFY(!s_initialized);
 | 
						|
 | 
						|
#define __ENUMERATE_HTML_ATTRIBUTE(name) \
 | 
						|
    name = #name;
 | 
						|
    ENUMERATE_HTML_ATTRIBUTES
 | 
						|
#undef __ENUMERATE_HTML_ATTRIBUTE
 | 
						|
 | 
						|
    // NOTE: Special cases for C++ keywords.
 | 
						|
    class_ = "class";
 | 
						|
    for_ = "for";
 | 
						|
    default_ = "default";
 | 
						|
    char_ = "char";
 | 
						|
 | 
						|
    // NOTE: Special cases for attributes with dashes in them.
 | 
						|
    accept_charset = "accept-charset";
 | 
						|
    http_equiv = "http-equiv";
 | 
						|
 | 
						|
    s_initialized = true;
 | 
						|
    return {};
 | 
						|
}
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
// https://html.spec.whatwg.org/#boolean-attribute
 | 
						|
bool is_boolean_attribute(DeprecatedFlyString const& attribute)
 | 
						|
{
 | 
						|
    // NOTE: This is the list of attributes from https://html.spec.whatwg.org/#attributes-3
 | 
						|
    //       with a Value column value of "Boolean attribute".
 | 
						|
    return attribute.is_one_of(
 | 
						|
        AttributeNames::allowfullscreen,
 | 
						|
        AttributeNames::async,
 | 
						|
        AttributeNames::autofocus,
 | 
						|
        AttributeNames::autoplay,
 | 
						|
        AttributeNames::checked,
 | 
						|
        AttributeNames::controls,
 | 
						|
        AttributeNames::default_,
 | 
						|
        AttributeNames::defer,
 | 
						|
        AttributeNames::disabled,
 | 
						|
        AttributeNames::formnovalidate,
 | 
						|
        AttributeNames::inert,
 | 
						|
        AttributeNames::ismap,
 | 
						|
        AttributeNames::itemscope,
 | 
						|
        AttributeNames::loop,
 | 
						|
        AttributeNames::multiple,
 | 
						|
        AttributeNames::muted,
 | 
						|
        AttributeNames::nomodule,
 | 
						|
        AttributeNames::novalidate,
 | 
						|
        AttributeNames::open,
 | 
						|
        AttributeNames::playsinline,
 | 
						|
        AttributeNames::readonly,
 | 
						|
        AttributeNames::required,
 | 
						|
        AttributeNames::reversed,
 | 
						|
        AttributeNames::selected);
 | 
						|
}
 | 
						|
 | 
						|
}
 | 
						|
}
 |