diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp
index 06523d312f1..df416ba44bd 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp
@@ -291,4 +291,25 @@ JS::GlobalObject& current_global_object()
return vm.current_realm()->global_object();
}
+// https://html.spec.whatwg.org/multipage/webappapis.html#concept-relevant-realm
+JS::Realm& relevant_realm(JS::Object const& object)
+{
+ // The relevant Realm for a platform object is the value of its [[Realm]] field.
+ return *object.global_object().associated_realm();
+}
+
+// https://html.spec.whatwg.org/multipage/webappapis.html#relevant-settings-object
+EnvironmentSettingsObject& relevant_settings_object(JS::Object const& object)
+{
+ // Then, the relevant settings object for a platform object o is the environment settings object of the relevant Realm for o.
+ return verify_cast(*relevant_realm(object).host_defined());
+}
+
+// https://html.spec.whatwg.org/multipage/webappapis.html#concept-relevant-global
+JS::GlobalObject& relevant_global_object(JS::Object const& object)
+{
+ // Similarly, the relevant global object for a platform object o is the global object of the relevant Realm for o.
+ return relevant_realm(object).global_object();
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h
index 48c9fd2ae87..33e579120cd 100644
--- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h
+++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h
@@ -10,6 +10,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -120,5 +121,8 @@ JS::Realm& incumbent_realm();
JS::GlobalObject& incumbent_global_object();
EnvironmentSettingsObject& current_settings_object();
JS::GlobalObject& current_global_object();
+JS::Realm& relevant_realm(JS::Object const&);
+EnvironmentSettingsObject& relevant_settings_object(JS::Object const&);
+JS::GlobalObject& relevant_global_object(JS::Object const&);
}