1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

LibWeb: Actually instantiate all the web constructors/prototypes

We now instantiate all the generated web API constructors and expose
them on the window object. We also set the generated prototypes on
instantiated wrappers.

Also, we should obviously find a way to generate this code. :^)
This commit is contained in:
Andreas Kling 2021-01-18 09:50:00 +01:00
parent 252a98042d
commit ee7fa49b88
4 changed files with 349 additions and 7 deletions

View file

@ -560,6 +560,7 @@ void generate_implementation(const IDL::Interface& interface)
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("name", interface.name);
generator.set("wrapper_class", interface.wrapper_class);
generator.set("wrapper_base_class", interface.wrapper_base_class);
generator.set("fully_qualified_name", interface.fully_qualified_name);
@ -603,16 +604,17 @@ namespace Web::Bindings {
if (interface.wrapper_base_class == "Wrapper") {
generator.append(R"~~~(
@wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
: Wrapper(*global_object.object_prototype())
, m_impl(impl)
: Wrapper(*global_object.object_prototype())
, m_impl(impl)
{
}
)~~~");
} else {
generator.append(R"~~~(
@wrapper_class@::@wrapper_class@(JS::GlobalObject& global_object, @fully_qualified_name@& impl)
: @wrapper_base_class@(global_object, impl)
: @wrapper_base_class@(global_object, impl)
{
set_prototype(static_cast<WindowObject&>(global_object).web_prototype("@name@"));
}
)~~~");
}