LibWeb: Pass through [EnforceRange] and [Clamp] extended attributes

To the 'convert to int' AO. Nothing actually makes use of the [Clamp]
attribute yet in our implementation, but we may as well add support for
it now since it is trivial to do do.
This commit is contained in:
Shannon Booth 2024-03-29 17:13:23 +01:00 committed by Andreas Kling
parent 56b0066485
commit a09849072e
Notes: sideshowbarker 2024-07-17 05:05:51 +09:00

View file

@ -397,6 +397,8 @@ static void generate_to_integral(SourceGenerator& scoped_generator, ParameterTyp
VERIFY(it != idl_type_map.end());
scoped_generator.set("cpp_type"sv, it->cpp_type);
scoped_generator.set("enforce_range", parameter.extended_attributes.contains("EnforceRange") ? "Yes" : "No");
scoped_generator.set("clamp", parameter.extended_attributes.contains("Clamp") ? "Yes" : "No");
if ((!optional && !parameter.type->is_nullable()) || optional_default_value.has_value()) {
scoped_generator.append(R"~~~(
@ -418,14 +420,13 @@ static void generate_to_integral(SourceGenerator& scoped_generator, ParameterTyp
)~~~");
}
// FIXME: pass through [EnforceRange] and [Clamp] extended attributes
if (it->cpp_type == "bool"sv) {
scoped_generator.append(R"~~~(
@cpp_name@ = @js_name@@js_suffix@.to_boolean();
)~~~");
} else {
scoped_generator.append(R"~~~(
@cpp_name@ = TRY(WebIDL::convert_to_int<@cpp_type@>(vm, @js_name@@js_suffix@));
@cpp_name@ = TRY(WebIDL::convert_to_int<@cpp_type@>(vm, @js_name@@js_suffix@, WebIDL::EnforceRange::@enforce_range@, WebIDL::Clamp::@clamp@));
)~~~");
}