From f7a4d94b243faa175a348ab5ecb59cb31b788245 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 24 Oct 2024 19:26:37 +1300 Subject: [PATCH] LibWeb: Add scaffold for 'principal realm of realm' Allowing us to implement other AOs in terms of this one. --- .../LibWeb/HTML/Scripting/Environments.cpp | 15 +++++++++++++-- .../LibWeb/HTML/Scripting/Environments.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index 119bb183424..f1f77535159 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -329,11 +329,22 @@ JS::Object& incumbent_global_object() // https://whatpr.org/html/9893/webappapis.html#current-principal-realm JS::Realm& current_principal_realm() { - // FIXME: The current principal realm is the principal realm of the current realm. auto& event_loop = HTML::main_thread_event_loop(); auto& vm = event_loop.vm(); - return *vm.current_realm(); + // The current principal realm is the principal realm of the current realm. + return principal_realm(*vm.current_realm()); +} + +// https://whatpr.org/html/9893/webappapis.html#concept-principal-realm-of-realm +JS::Realm& principal_realm(JS::Realm& realm) +{ + // FIXME: 1. If realm.[[HostDefined]] is a synthetic realm settings object, then: + // FIXME: 1.1. Assert: realm is a synthetic realm. + // FIXME: 1.2. Set realm to the principal realm of realm.[[HostDefined]]. + // FIXME: 2. Assert: realm.[[HostDefined]] is an environment settings object and realm is a principal realm. + // 3. Return realm. + return realm; } // https://html.spec.whatwg.org/multipage/webappapis.html#current-settings-object diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h index ec8b611dbba..a54fcd4cbf2 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -149,6 +149,7 @@ JS::Object& incumbent_global_object(); JS::Realm& current_principal_realm(); EnvironmentSettingsObject& current_principal_settings_object(); +JS::Realm& principal_realm(JS::Realm&); JS::Object& current_principal_global_object(); JS::Realm& relevant_realm(JS::Object const&); EnvironmentSettingsObject& relevant_settings_object(JS::Object const&);