From f69c13579688371f267d4eb4d38d6efcb3e69a80 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 15 Nov 2022 01:51:40 +0200 Subject: [PATCH] LibWeb: Implement the 'Entry Realm/{settings,global} object' concepts --- .../LibWeb/HTML/Scripting/Environments.cpp | 26 +++++++++++++++++++ .../LibWeb/HTML/Scripting/Environments.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index 4d3e9eccc1..4ae23ada87 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -393,6 +393,32 @@ JS::Object& relevant_global_object(JS::Object const& object) return relevant_realm(object).global_object(); } +// https://html.spec.whatwg.org/multipage/webappapis.html#concept-entry-realm +JS::Realm& entry_realm() +{ + auto& event_loop = HTML::main_thread_event_loop(); + auto& vm = event_loop.vm(); + + // With this in hand, we define the entry execution context to be the most recently pushed item in the JavaScript execution context stack that is a realm execution context. + // The entry realm is the entry execution context's Realm component. + // NOTE: Currently all execution contexts in LibJS are realm execution contexts + return *vm.running_execution_context().realm; +} + +// https://html.spec.whatwg.org/multipage/webappapis.html#entry-settings-object +EnvironmentSettingsObject& entry_settings_object() +{ + // Then, the entry settings object is the environment settings object of the entry realm. + return Bindings::host_defined_environment_settings_object(entry_realm()); +} + +// https://html.spec.whatwg.org/multipage/webappapis.html#entry-global-object +JS::Object& entry_global_object() +{ + // Similarly, the entry global object is the global object of the entry realm. + return entry_realm().global_object(); +} + // https://html.spec.whatwg.org/multipage/webappapis.html#secure-context bool is_secure_context(Environment const& environment) { diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h index ea19b05a62..f86932b149 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -143,6 +143,9 @@ JS::Realm& relevant_realm(JS::Object const&); EnvironmentSettingsObject& relevant_settings_object(JS::Object const&); EnvironmentSettingsObject& relevant_settings_object(DOM::Node const&); JS::Object& relevant_global_object(JS::Object const&); +JS::Realm& entry_realm(); +EnvironmentSettingsObject& entry_settings_object(); +JS::Object& entry_global_object(); [[nodiscard]] bool is_secure_context(Environment const&); [[nodiscard]] bool is_non_secure_context(Environment const&);