From 1871b744ff0c8dfdfc5734a4009b6ca523305cfd Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Fri, 25 Oct 2024 15:49:06 +1300 Subject: [PATCH] LibWeb: Add principal settings object helper function To more clearly represent the host binding which a principal setting realm has. --- .../Libraries/LibWeb/HTML/Scripting/Environments.cpp | 9 ++++++++- Userland/Libraries/LibWeb/HTML/Scripting/Environments.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index f1f77535159..b3e127b21b2 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -347,12 +347,19 @@ JS::Realm& principal_realm(JS::Realm& realm) return realm; } +// https://whatpr.org/html/9893/webappapis.html#concept-realm-settings-object +EnvironmentSettingsObject& principal_realm_settings_object(JS::Realm& realm) +{ + // A principal realm has a [[HostDefined]] field, which contains the principal realm's settings object. + return Bindings::host_defined_environment_settings_object(realm); +} + // https://html.spec.whatwg.org/multipage/webappapis.html#current-settings-object // https://whatpr.org/html/9893/webappapis.html#current-principal-settings-object EnvironmentSettingsObject& current_principal_settings_object() { // Then, the current principal settings object is the environment settings object of the current principal realm. - return Bindings::host_defined_environment_settings_object(current_principal_realm()); + return principal_realm_settings_object(current_principal_realm()); } // https://html.spec.whatwg.org/multipage/webappapis.html#current-global-object diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h index a54fcd4cbf2..2a0ad875451 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -147,6 +147,7 @@ JS::Realm& incumbent_realm(); JS::Object& incumbent_global_object(); JS::Realm& current_principal_realm(); +EnvironmentSettingsObject& principal_realm_settings_object(JS::Realm&); EnvironmentSettingsObject& current_principal_settings_object(); JS::Realm& principal_realm(JS::Realm&);