diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index 7f46a11ff6..06523d312f 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Luke Wilde + * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -270,4 +271,24 @@ JS::GlobalObject& incumbent_global_object() return incumbent_settings_object().global_object(); } +// https://html.spec.whatwg.org/multipage/webappapis.html#current-settings-object +EnvironmentSettingsObject& current_settings_object() +{ + auto& event_loop = HTML::main_thread_event_loop(); + auto& vm = event_loop.vm(); + + // Then, the current settings object is the environment settings object of the current Realm Record. + return verify_cast(*vm.current_realm()->host_defined()); +} + +// https://html.spec.whatwg.org/multipage/webappapis.html#current-global-object +JS::GlobalObject& current_global_object() +{ + auto& event_loop = HTML::main_thread_event_loop(); + auto& vm = event_loop.vm(); + + // Similarly, the current global object is the global object of the current Realm Record. + return vm.current_realm()->global_object(); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h index a006b80257..48c9fd2ae8 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Luke Wilde + * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -117,5 +118,7 @@ private: EnvironmentSettingsObject& incumbent_settings_object(); JS::Realm& incumbent_realm(); JS::GlobalObject& incumbent_global_object(); +EnvironmentSettingsObject& current_settings_object(); +JS::GlobalObject& current_global_object(); }