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

LibWeb: More fully implement the LegacyNamespace IDL extended attribute

Interfaces with a LegacyNamespace extended attribute should have their
constructors defined on the namespace identified by the LegacyNamespace
attribute value.
This commit is contained in:
Timothy Flynn 2023-03-16 12:55:59 -04:00 committed by Linus Groh
parent a277e645d3
commit aa06dd7f21

View file

@ -159,6 +159,21 @@ void Intrinsics::create_web_namespace<@namespace_class@>(JS::Realm& realm)
{
auto namespace_object = heap().allocate<@namespace_class@>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
m_namespaces.set("@interface_name@"sv, namespace_object);
[[maybe_unused]] static constexpr u8 attr = JS::Attribute::Writable | JS::Attribute::Configurable;)~~~");
for (auto& interface : exposed_interfaces) {
if (interface.extended_attributes.get("LegacyNamespace"sv) != name)
continue;
gen.set("owned_interface_name", interface.name);
gen.set("owned_prototype_class", interface.prototype_class);
gen.append(R"~~~(
namespace_object->define_intrinsic_accessor("@owned_interface_name@", attr, [](auto& realm) -> JS::Value { return &Bindings::ensure_web_constructor<@owned_prototype_class@>(realm, "@interface_name@.@owned_interface_name@"sv); });)~~~");
}
gen.append(R"~~~(
}
)~~~");
};
@ -316,7 +331,7 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object& global)
if (interface.is_namespace)
add_namespace(gen, interface.name, interface.namespace_class);
else
else if (!interface.extended_attributes.contains("LegacyNamespace"sv))
add_interface(gen, interface.namespaced_name, interface.prototype_class, lookup_legacy_constructor(interface));
}