Skip to content

Truly independent web browser

LibWeb: Allow checking interface exposure from a const realm

Shannon Booth951d3b53f4c3
diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
index fa84acb5d92..aef4a04144c 100644
--- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp
+++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp
@@ -147,6 +147,11 @@ JS::Realm& EnvironmentSettingsObject::realm()
return *realm_execution_context().realm;
}
+JS::Realm const& EnvironmentSettingsObject::realm() const
+{
+ return *realm_execution_context().realm;
+}
+
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-global
JS::Object& EnvironmentSettingsObject::global_object()
{
diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.h b/Libraries/LibWeb/HTML/Scripting/Environments.h
index ef5588f1c75..5beb60913ee 100644
--- a/Libraries/LibWeb/HTML/Scripting/Environments.h
+++ b/Libraries/LibWeb/HTML/Scripting/Environments.h
@@ -130,6 +130,7 @@ public:
Optional<Utf16String> encoding_parse_and_serialize_url(Utf16View);
JS::Realm& realm();
+ JS::Realm const& realm() const;
JS::Object& global_object();
JS::Object const& global_object() const { return const_cast<EnvironmentSettingsObject*>(this)->global_object(); }
EventLoop& responsible_event_loop();
diff --git a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
index 09efd342ff0..ad9e4841fde 100644
--- a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
+++ b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
@@ -1743,7 +1743,7 @@ bool WindowOrWorkerGlobalScopeMixin::expose_experimental_interfaces()
// A site-compatibility rule can expose a gated interface or member to the documents and workers it matches, without
// exposing it to the web at large. The rule is keyed by the URL the environment was created with, so it holds for the
// lifetime of that global, the same way the global switch does.
-bool WindowOrWorkerGlobalScopeMixin::expose_experimental_interface(EnvironmentSettingsObject& settings, StringView name)
+bool WindowOrWorkerGlobalScopeMixin::expose_experimental_interface(EnvironmentSettingsObject const& settings, StringView name)
{
if (s_experimental_interfaces_exposed)
return true;
diff --git a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
index c0091c39768..04b81a71bba 100644
--- a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
+++ b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.h
@@ -139,7 +139,7 @@ public:
static void set_experimental_interfaces_exposed(bool);
static bool expose_experimental_interfaces();
- static bool expose_experimental_interface(EnvironmentSettingsObject&, StringView name);
+ static bool expose_experimental_interface(EnvironmentSettingsObject const&, StringView name);
[[nodiscard]] GC::Ref<Crypto::Crypto> crypto();
[[nodiscard]] GC::Ref<ServiceWorker::CacheStorage> caches();
diff --git a/Meta/Generators/libweb_bindings/intrinsics.py b/Meta/Generators/libweb_bindings/intrinsics.py
index 65765d2f290..e603567aa68 100644
--- a/Meta/Generators/libweb_bindings/intrinsics.py
+++ b/Meta/Generators/libweb_bindings/intrinsics.py
@@ -225,7 +225,7 @@ enum class InterfaceName : u16 {
out.write(
"""};
-bool is_exposed(InterfaceName, JS::Realm&);
+bool is_exposed(InterfaceName, JS::Realm const&);
"""
)
write_ensure_web_prototype_declaration(out)
@@ -280,7 +280,7 @@ namespace Web::Bindings {
out.write(
"""
// An interface, callback interface, namespace, or member construct is exposed in a given realm realm if the following steps return true:
-bool is_exposed(InterfaceName name, JS::Realm& realm)
+bool is_exposed(InterfaceName name, JS::Realm const& realm)
{
auto const& global_object = realm.global_object();