diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-03-15 10:02:04 -0400 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-03-15 12:48:25 -0400 |
commit | 020c2b59c4a20e9e99ffbeacfa9bc2a1319d9bc2 (patch) | |
tree | 4d8716e989f7f15f34ae7ccc2ee0da051b3ab010 /Userland/Libraries/LibWeb/Bindings | |
parent | 61ecdbca543af4f0c832b66162bc198a7cef971a (diff) | |
download | serenity-020c2b59c4a20e9e99ffbeacfa9bc2a1319d9bc2.zip |
LibWeb: Support generating IDL namespaces
These are similar to prototypes and constructors in that they will now
be lazily instantiated when they are first requested.
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings')
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/Intrinsics.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/Intrinsics.h b/Userland/Libraries/LibWeb/Bindings/Intrinsics.h index 67b20512d5..896a143da5 100644 --- a/Userland/Libraries/LibWeb/Bindings/Intrinsics.h +++ b/Userland/Libraries/LibWeb/Bindings/Intrinsics.h @@ -25,6 +25,16 @@ public: { } + template<typename NamespaceType> + JS::Object& ensure_web_namespace(DeprecatedString const& namespace_name) + { + if (auto it = m_namespaces.find(namespace_name); it != m_namespaces.end()) + return *it->value; + + create_web_namespace<NamespaceType>(*m_realm); + return *m_namespaces.find(namespace_name)->value; + } + template<typename PrototypeType> JS::Object& ensure_web_prototype(DeprecatedString const& class_name) { @@ -48,9 +58,13 @@ public: private: virtual void visit_edges(JS::Cell::Visitor&) override; + template<typename NamespaceType> + void create_web_namespace(JS::Realm& realm); + template<typename PrototypeType> void create_web_prototype_and_constructor(JS::Realm& realm); + HashMap<DeprecatedString, JS::NonnullGCPtr<JS::Object>> m_namespaces; HashMap<DeprecatedString, JS::NonnullGCPtr<JS::Object>> m_prototypes; HashMap<DeprecatedString, JS::GCPtr<JS::NativeFunction>> m_constructors; JS::NonnullGCPtr<JS::Realm> m_realm; @@ -62,6 +76,12 @@ private: } template<typename T> +[[nodiscard]] JS::Object& ensure_web_namespace(JS::Realm& realm, DeprecatedString const& namespace_name) +{ + return host_defined_intrinsics(realm).ensure_web_namespace<T>(namespace_name); +} + +template<typename T> [[nodiscard]] JS::Object& ensure_web_prototype(JS::Realm& realm, DeprecatedString const& class_name) { return host_defined_intrinsics(realm).ensure_web_prototype<T>(class_name); |