From 491edaffc708d5174a0126244d3cd99fc05290e3 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 10 Jan 2023 12:52:01 -0500 Subject: LibWeb: Ensure legacy constructors are defined on the global object This regressed in 6e93d89ee3108873a30bd0178b0f84fff3db3315. --- .../LibWeb/GenerateWindowOrWorkerInterfaces.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'Meta') diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWindowOrWorkerInterfaces.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWindowOrWorkerInterfaces.cpp index 0204e2612b..ca95a9dbc9 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWindowOrWorkerInterfaces.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWindowOrWorkerInterfaces.cpp @@ -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 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"~~~( -- cgit v1.2.3