LibWeb: Return instead of throwing on unknown enums in attribute setters

I saw one site relying on this, where they are trying to set
XHR.responseType to "text/plain", which is not a valid responseType.
However, they also don't expect it to throw. The IDL spec special cases
enumerations to make it return instead of throwing in this case.
This commit is contained in:
Luke Wilde 2022-06-27 19:56:06 +01:00 committed by Linus Groh
parent 3fe66bddf4
commit 885c6b6678
Notes: sideshowbarker 2024-07-17 09:52:29 +09:00

View file

@ -605,10 +605,18 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
)~~~");
}
enum_generator.append(R"~~~(
// NOTE: Attribute setters return undefined instead of throwing when the string doesn't match an enum value.
if constexpr (!IsSame<Attribute, RemoveConst<ParameterType>>) {
enum_generator.append(R"~~~(
@else@
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidEnumerationValue, @js_name.as_string@, "@parameter.type.name@");
)~~~");
} else {
enum_generator.append(R"~~~(
@else@
return JS::js_undefined();
)~~~");
}
if (optional) {
enum_generator.append(R"~~~(