diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-03-14 14:59:06 -0400 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-03-14 16:30:19 -0400 |
commit | 9c569e8a0f33cd156aa4f3379b0c009bd0cd3755 (patch) | |
tree | 79bb91aa847b3308239b0ec388781b492a7f0d22 /Meta/Lagom | |
parent | 3bd1d8bf6c076085d50580ade3758dacf937874d (diff) | |
download | serenity-9c569e8a0f33cd156aa4f3379b0c009bd0cd3755.zip |
LibWeb: Implement the [PutForwards] IDL extended attribute
For example, consider the attribute:
interface Element {
[PutForwards=value] readonly attribute DOMTokenList classList;
}
When `classList` is set, we should instead set the attribute `value` on
the `classList` attribute of the Element interface.
Diffstat (limited to 'Meta/Lagom')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index eefe3109af..decc4891d4 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -2178,7 +2178,7 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_getter); )~~~"); - if (!attribute.readonly || attribute.extended_attributes.contains("Replaceable"sv)) { + if (!attribute.readonly || attribute.extended_attributes.contains("Replaceable"sv) || attribute.extended_attributes.contains("PutForwards"sv)) { attribute_generator.append(R"~~~( JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_setter); )~~~"); @@ -2300,7 +2300,7 @@ JS::ThrowCompletionOr<void> @class_name@::initialize(JS::Realm& realm) attribute_generator.set("attribute.name", attribute.name); attribute_generator.set("attribute.getter_callback", attribute.getter_callback_name); - if (!attribute.readonly || attribute.extended_attributes.contains("Replaceable"sv)) + if (!attribute.readonly || attribute.extended_attributes.contains("Replaceable"sv) || attribute.extended_attributes.contains("PutForwards"sv)) attribute_generator.set("attribute.setter_callback", attribute.setter_callback_name); else attribute_generator.set("attribute.setter_callback", "nullptr"); @@ -2541,6 +2541,22 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@) return JS::js_undefined(); } )~~~"); + } else if (auto put_forwards_identifier = attribute.extended_attributes.get("PutForwards"sv); put_forwards_identifier.has_value()) { + attribute_generator.set("attribute.name", attribute.name.to_snakecase()); + attribute_generator.set("put_forwards_identifier"sv, *put_forwards_identifier); + + attribute_generator.append(R"~~~( +JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@) +{ + auto* impl = TRY(impl_from(vm)); + auto value = vm.argument(0); + + auto receiver = TRY(throw_dom_exception_if_needed(vm, [&]() { return impl->@attribute.name@(); })); + TRY(receiver->set(JS::PropertyKey { "@put_forwards_identifier@" }, value, JS::Object::ShouldThrowExceptions::Yes)); + + return JS::js_undefined(); +} +)~~~"); } } |