LibWeb: Throw TypeError for new Headers(null)

The WebIDL for the `Headers` constructor specifies that the `init`
parameter is optional and must be of type `HeadersInit`. While the
parameter can be omitted (or explicitly set to `undefined`),
`null` is not a valid value.

This change fixes at least 2 "Create headers with null should throw"
WPT subtests which I have imported in this patch.
This commit is contained in:
Feng Yu 2024-12-09 11:47:14 -08:00 committed by Tim Flynn
commit f2eaf3381f
Notes: github-actions[bot] 2024-12-10 14:47:27 +00:00
7 changed files with 717 additions and 3 deletions

View file

@ -1550,14 +1550,20 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
@union_type@ @cpp_name@ = TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
)~~~");
} else {
if (!optional_default_value.has_value() || optional_default_value == "null"sv) {
if (!optional_default_value.has_value()) {
union_generator.append(R"~~~(
Optional<@union_type@> @cpp_name@;
if (!@js_name@@js_suffix@.is_undefined())
@cpp_name@ = TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
)~~~");
} else {
if (optional_default_value == "null"sv) {
union_generator.append(R"~~~(
Optional<@union_type@> @cpp_name@;
if (!@js_name@@js_suffix@.is_nullish())
@cpp_name@ = TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
)~~~");
} else {
if (optional_default_value == "\"\"") {
} else if (optional_default_value == "\"\"") {
union_generator.append(R"~~~(
@union_type@ @cpp_name@ = @js_name@@js_suffix@.is_undefined() ? String {} : TRY(@js_name@@js_suffix@_to_variant(@js_name@@js_suffix@));
)~~~");