mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 05:25:13 +00:00
LibWeb: Change WrapperGenerator to emit acessor properties
This is how the Web IDL spec defines it. We might eventually not need native properties anymore, but that's another change for another day. Co-authored-by: Idan Horowitz <idan.horowitz@gmail.com>
This commit is contained in:
parent
09bd5f8772
commit
8ade0df4c3
Notes:
sideshowbarker
2024-07-18 10:26:28 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/8ade0df4c3c Pull-request: https://github.com/SerenityOS/serenity/pull/8262 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/alimpfard ✅ Reviewed-by: https://github.com/awesomekling ✅ Reviewed-by: https://github.com/davidot Reviewed-by: https://github.com/mattco98
1 changed files with 10 additions and 7 deletions
|
@ -1157,12 +1157,12 @@ private:
|
|||
auto attribute_generator = generator.fork();
|
||||
attribute_generator.set("attribute.name:snakecase", attribute.name.to_snakecase());
|
||||
attribute_generator.append(R"~~~(
|
||||
JS_DECLARE_NATIVE_GETTER(@attribute.name:snakecase@_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_getter);
|
||||
)~~~");
|
||||
|
||||
if (!attribute.readonly) {
|
||||
attribute_generator.append(R"~~~(
|
||||
JS_DECLARE_NATIVE_SETTER(@attribute.name:snakecase@_setter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(@attribute.name:snakecase@_setter);
|
||||
)~~~");
|
||||
}
|
||||
}
|
||||
|
@ -1308,7 +1308,7 @@ void @prototype_class@::initialize(JS::GlobalObject& global_object)
|
|||
attribute_generator.set("attribute.setter_callback", attribute.setter_callback_name);
|
||||
|
||||
attribute_generator.append(R"~~~(
|
||||
define_native_property("@attribute.name@", @attribute.getter_callback@, @attribute.setter_callback@, default_attributes);
|
||||
define_native_accessor("@attribute.name@", @attribute.getter_callback@, @attribute.setter_callback@, default_attributes);
|
||||
)~~~");
|
||||
}
|
||||
|
||||
|
@ -1453,7 +1453,7 @@ static @fully_qualified_name@* impl_from(JS::VM& vm, JS::GlobalObject& global_ob
|
|||
}
|
||||
|
||||
attribute_generator.append(R"~~~(
|
||||
JS_DEFINE_NATIVE_GETTER(@prototype_class@::@attribute.getter_callback@)
|
||||
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.getter_callback@)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
|
@ -1491,14 +1491,16 @@ JS_DEFINE_NATIVE_GETTER(@prototype_class@::@attribute.getter_callback@)
|
|||
|
||||
if (!attribute.readonly) {
|
||||
attribute_generator.append(R"~~~(
|
||||
JS_DEFINE_NATIVE_SETTER(@prototype_class@::@attribute.setter_callback@)
|
||||
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::@attribute.setter_callback@)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return;
|
||||
return {};
|
||||
|
||||
auto value = vm.argument(0);
|
||||
)~~~");
|
||||
|
||||
generate_to_cpp(generator, attribute, "value", "", "cpp_value", true, attribute.extended_attributes.contains("LegacyNullToEmptyString"));
|
||||
generate_to_cpp(generator, attribute, "value", "", "cpp_value", false, attribute.extended_attributes.contains("LegacyNullToEmptyString"));
|
||||
|
||||
if (attribute.extended_attributes.contains("Reflect")) {
|
||||
if (attribute.type.name != "boolean") {
|
||||
|
@ -1520,6 +1522,7 @@ JS_DEFINE_NATIVE_SETTER(@prototype_class@::@attribute.setter_callback@)
|
|||
}
|
||||
|
||||
attribute_generator.append(R"~~~(
|
||||
return {};
|
||||
}
|
||||
)~~~");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue