summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Bindings
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-09 17:49:06 -0500
committerAndreas Kling <kling@serenityos.org>2023-01-10 16:08:14 +0100
commit7bd8fd000f3f8e92ff632be2370a279ac2309250 (patch)
tree212c47b003f275c40bca964cb1fa4fbbe1824abc /Userland/Libraries/LibWeb/Bindings
parent59104262a4fe1b9a5aa234ea810842f205f305db (diff)
downloadserenity-7bd8fd000f3f8e92ff632be2370a279ac2309250.zip
LibWeb: Generate dedicated methods to create Web constructors/prototypes
Currently, for each exposed interface, we generate one massive function to create every Web constructor and prototype. In an effort to lazily create these instead, this first step is to extract the creation of each of these into its own method. First, this generates a forwarding header for all IDL types. This is to allow callers to remain unchanged without forcing them to include the (very heavy) generated IDL headers. This header is included by LibWeb's forwarding header. Next, this defines a base template method on Web::Bindings::Intrinsics to create a prototype/constructor pair. Specializations of this template are now generated in a new .cpp file, IntrinsicDefinitions.cpp. The base Intrinsics class is updated to use this new method, and will continue to cache the result. Last, some WebAssembly classes are updated to use this new mechanism. They were using some ad hoc cache keys that are now in line with the generated specializations. That one massive function is still used to invoke these specializations, so they are not lazy as of this commit.
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/Intrinsics.h30
1 files changed, 14 insertions, 16 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/Intrinsics.h b/Userland/Libraries/LibWeb/Bindings/Intrinsics.h
index 610100c185..012278c402 100644
--- a/Userland/Libraries/LibWeb/Bindings/Intrinsics.h
+++ b/Userland/Libraries/LibWeb/Bindings/Intrinsics.h
@@ -27,36 +27,34 @@ public:
JS::Object& cached_web_prototype(DeprecatedString const& class_name);
- template<typename T>
+ template<typename PrototypeType>
JS::Object& ensure_web_prototype(DeprecatedString const& class_name)
{
- auto it = m_prototypes.find(class_name);
- if (it != m_prototypes.end())
+ if (auto it = m_prototypes.find(class_name); it != m_prototypes.end())
return *it->value;
- auto& realm = *m_realm;
- auto prototype = heap().allocate<T>(realm, realm);
- m_prototypes.set(class_name, prototype);
- return prototype;
+
+ create_web_prototype_and_constructor<PrototypeType>(*m_realm);
+ return *m_prototypes.find(class_name)->value;
}
- template<typename T>
+ template<typename PrototypeType>
JS::NativeFunction& ensure_web_constructor(DeprecatedString const& class_name)
{
- auto it = m_constructors.find(class_name);
- if (it != m_constructors.end())
+ if (auto it = m_constructors.find(class_name); it != m_constructors.end())
return *it->value;
- auto& realm = *m_realm;
- auto constructor = heap().allocate<T>(realm, realm);
- m_constructors.set(class_name, constructor);
- return constructor;
+
+ create_web_prototype_and_constructor<PrototypeType>(*m_realm);
+ return *m_constructors.find(class_name)->value;
}
private:
virtual void visit_edges(JS::Cell::Visitor&) override;
- HashMap<DeprecatedString, JS::Object*> m_prototypes;
- HashMap<DeprecatedString, JS::NativeFunction*> m_constructors;
+ template<typename PrototypeType>
+ void create_web_prototype_and_constructor(JS::Realm& realm);
+ HashMap<DeprecatedString, JS::NonnullGCPtr<JS::Object>> m_prototypes;
+ HashMap<DeprecatedString, JS::GCPtr<JS::NativeFunction>> m_constructors;
JS::NonnullGCPtr<JS::Realm> m_realm;
};