LibWeb: Ensure legacy constructors are defined on the global object

This regressed in 6e93d89ee3.
This commit is contained in:
Timothy Flynn 2023-01-10 12:52:01 -05:00 committed by Linus Groh
parent 4d335f3819
commit 491edaffc7
Notes: sideshowbarker 2024-07-17 23:07:41 +09:00

View file

@ -306,23 +306,30 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object& global)
static constexpr u8 attr = JS::Attribute::Writable | JS::Attribute::Configurable;
)~~~");
auto add_interface = [](SourceGenerator& gen, StringView name, StringView prototype_class) {
auto add_interface = [](SourceGenerator& gen, StringView name, StringView prototype_class, Optional<LegacyConstructor> const& legacy_constructor) {
gen.set("interface_name", name);
gen.set("prototype_class", prototype_class);
gen.append(R"~~~(
global.define_intrinsic_accessor("@interface_name@", attr, [](auto& realm) -> JS::Value { return &ensure_web_constructor<@prototype_class@>(realm, "@interface_name@"sv); });)~~~"); };
global.define_intrinsic_accessor("@interface_name@", attr, [](auto& realm) -> JS::Value { return &ensure_web_constructor<@prototype_class@>(realm, "@interface_name@"sv); });)~~~");
if (legacy_constructor.has_value()) {
gen.set("legacy_interface_name", legacy_constructor->name);
gen.append(R"~~~(
global.define_intrinsic_accessor("@legacy_interface_name@", attr, [](auto& realm) -> JS::Value { return &ensure_web_constructor<@prototype_class@>(realm, "@legacy_interface_name@"sv); });)~~~");
}
};
for (auto& interface : exposed_interfaces) {
auto gen = generator.fork();
add_interface(gen, interface.name, interface.prototype_class);
add_interface(gen, interface.name, interface.prototype_class, lookup_legacy_constructor(interface));
}
// FIXME: Special case window. We should convert Window and Location to use IDL
if (class_name == "Window"sv) {
auto gen = generator.fork();
add_interface(gen, "Window"sv, "WindowPrototype"sv);
add_interface(gen, "Location"sv, "LocationPrototype"sv);
add_interface(gen, "Window"sv, "WindowPrototype"sv, {});
add_interface(gen, "Location"sv, "LocationPrototype"sv, {});
}
generator.append(R"~~~(