mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
LibWeb: Remove Element::set_attribute(name, value?)
That API came from a mistake in the IDL compiler, where reflected nullable attributes would try to call set_attribute(name, null). This commit fixes the mistake in the IDL generator, and removes the meaningless API.
This commit is contained in:
parent
d2c7e1ea7d
commit
988c6568a9
4 changed files with 20 additions and 11 deletions
|
@ -2951,9 +2951,18 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
|
||||||
|
|
||||||
if (attribute.extended_attributes.contains("Reflect")) {
|
if (attribute.extended_attributes.contains("Reflect")) {
|
||||||
if (attribute.type->name() != "boolean") {
|
if (attribute.type->name() != "boolean") {
|
||||||
attribute_generator.append(R"~~~(
|
if (attribute.type->is_nullable()) {
|
||||||
|
attribute_generator.append(R"~~~(
|
||||||
|
if (!cpp_value.has_value())
|
||||||
|
impl->remove_attribute(HTML::AttributeNames::@attribute.reflect_name@);
|
||||||
|
else
|
||||||
|
MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, cpp_value.value()));
|
||||||
|
)~~~");
|
||||||
|
} else {
|
||||||
|
attribute_generator.append(R"~~~(
|
||||||
MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, cpp_value));
|
MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, cpp_value));
|
||||||
)~~~");
|
)~~~");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
attribute_generator.append(R"~~~(
|
attribute_generator.append(R"~~~(
|
||||||
if (!cpp_value)
|
if (!cpp_value)
|
||||||
|
|
|
@ -206,12 +206,9 @@ WebIDL::ExceptionOr<void> Element::set_attribute(DeprecatedFlyString const& name
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> Element::set_attribute(DeprecatedFlyString const& name, Optional<String> const& value)
|
WebIDL::ExceptionOr<void> Element::set_attribute(DeprecatedFlyString const& name, String const& value)
|
||||||
{
|
{
|
||||||
if (!value.has_value())
|
return set_attribute(name, value.to_deprecated_string());
|
||||||
return set_attribute(name, DeprecatedString {});
|
|
||||||
|
|
||||||
return set_attribute(name, value->to_deprecated_string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#validate-and-extract
|
// https://dom.spec.whatwg.org/#validate-and-extract
|
||||||
|
|
|
@ -110,8 +110,8 @@ public:
|
||||||
DeprecatedString get_attribute_value(StringView local_name, DeprecatedFlyString const& namespace_ = {}) const;
|
DeprecatedString get_attribute_value(StringView local_name, DeprecatedFlyString const& namespace_ = {}) const;
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value);
|
WebIDL::ExceptionOr<void> set_attribute(DeprecatedFlyString const& name, DeprecatedString const& value);
|
||||||
WebIDL::ExceptionOr<void> set_attribute(DeprecatedFlyString const& name, Optional<String> const& value);
|
WebIDL::ExceptionOr<void> set_attribute(DeprecatedFlyString const& name, String const& value);
|
||||||
WebIDL::ExceptionOr<void> set_attribute(FlyString const& name, Optional<String> const& value)
|
WebIDL::ExceptionOr<void> set_attribute(FlyString const& name, String const& value)
|
||||||
{
|
{
|
||||||
return set_attribute(name.to_deprecated_fly_string(), value);
|
return set_attribute(name.to_deprecated_fly_string(), value);
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,10 @@ public:
|
||||||
\
|
\
|
||||||
WebIDL::ExceptionOr<void> set_##name(Optional<String> const& value) override \
|
WebIDL::ExceptionOr<void> set_##name(Optional<String> const& value) override \
|
||||||
{ \
|
{ \
|
||||||
TRY(set_attribute(attribute, value)); \
|
if (value.has_value()) \
|
||||||
|
TRY(set_attribute(attribute, *value)); \
|
||||||
|
else \
|
||||||
|
remove_attribute(attribute); \
|
||||||
return {}; \
|
return {}; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -358,7 +358,7 @@ WebIDL::ExceptionOr<void> Page::toggle_media_loop_state()
|
||||||
if (media_element->has_attribute(HTML::AttributeNames::loop))
|
if (media_element->has_attribute(HTML::AttributeNames::loop))
|
||||||
media_element->remove_attribute(HTML::AttributeNames::loop);
|
media_element->remove_attribute(HTML::AttributeNames::loop);
|
||||||
else
|
else
|
||||||
TRY(media_element->set_attribute(HTML::AttributeNames::loop, OptionalNone {}));
|
TRY(media_element->set_attribute(HTML::AttributeNames::loop, {}));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -374,7 +374,7 @@ WebIDL::ExceptionOr<void> Page::toggle_media_controls_state()
|
||||||
if (media_element->has_attribute(HTML::AttributeNames::controls))
|
if (media_element->has_attribute(HTML::AttributeNames::controls))
|
||||||
media_element->remove_attribute(HTML::AttributeNames::controls);
|
media_element->remove_attribute(HTML::AttributeNames::controls);
|
||||||
else
|
else
|
||||||
TRY(media_element->set_attribute(HTML::AttributeNames::controls, OptionalNone {}));
|
TRY(media_element->set_attribute(HTML::AttributeNames::controls, {}));
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue