summaryrefslogtreecommitdiff
path: root/Meta/Lagom
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2023-03-06 14:10:39 +0000
committerLinus Groh <mail@linusgroh.de>2023-03-07 23:33:34 +0000
commite13f89c9ebbf40dd434d99de84f9df5c48510c4f (patch)
tree8b371c0ddb833c60a8d67f0aea332ed536aff97c /Meta/Lagom
parent3316d247bffb4c435cb8868872ae310d6a4c694e (diff)
downloadserenity-e13f89c9ebbf40dd434d99de84f9df5c48510c4f.zip
LibWeb: Generate setter for [Replaceable] IDL attributes
The code is directly stolen from the REPLACEABLE_PROPERTY_SETTER() macro which will hopefully be removed soon.
Diffstat (limited to 'Meta/Lagom')
-rw-r--r--Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp
index 3f912b770a..30b98073ef 100644
--- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp
+++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp
@@ -2128,7 +2128,7 @@ static void generate_prototype_or_global_mixin_declarations(IDL::Interface const
JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_getter);
)~~~");
- if (!attribute.readonly) {
+ if (!attribute.readonly || attribute.extended_attributes.contains("Replaceable"sv)) {
attribute_generator.append(R"~~~(
JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_setter);
)~~~");
@@ -2250,10 +2250,10 @@ 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_generator.set("attribute.setter_callback", "nullptr");
- else
+ if (!attribute.readonly || attribute.extended_attributes.contains("Replaceable"sv))
attribute_generator.set("attribute.setter_callback", attribute.setter_callback_name);
+ else
+ attribute_generator.set("attribute.setter_callback", "nullptr");
if (attribute.extended_attributes.contains("Unscopable")) {
attribute_generator.append(R"~~~(
@@ -2394,6 +2394,7 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm)
for (auto& attribute : interface.attributes) {
auto attribute_generator = generator.fork();
+ attribute_generator.set("attribute.name", attribute.name);
attribute_generator.set("attribute.getter_callback", attribute.getter_callback_name);
attribute_generator.set("attribute.setter_callback", attribute.setter_callback_name);
@@ -2479,6 +2480,17 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
return JS::js_undefined();
}
)~~~");
+ } else if (attribute.extended_attributes.contains("Replaceable"sv)) {
+ attribute_generator.append(R"~~~(
+JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
+{
+ auto this_value = vm.this_value();
+ if (!this_value.is_object() || !is<@fully_qualified_name@>(this_value.as_object()))
+ return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@name@");
+ TRY(this_value.as_object().internal_define_own_property("@attribute.name@", JS::PropertyDescriptor { .value = vm.argument(0), .writable = true }));
+ return JS::js_undefined();
+}
+)~~~");
}
}