mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 07:32:44 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									0d0b87fd46
								
							
						
					
					
						commit
						db2ba5f1d9
					
				
					 19 changed files with 74 additions and 27 deletions
				
			
		|  | @ -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 {}; | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -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(); | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -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 {}; | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -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(); | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn