summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Bindings/Intrinsics.h
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings/Intrinsics.h')
-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;
};