1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

LibWeb: Make WrapperGenerator generate nullable wrapper types

Previously it was not doing so, and some code relied on this not being
the case.

In particular, set_caption, set_t_head and set_t_foot in
HTMLTableElement relied on this. This commit is not here to fix this,
so I added an assertion to make it equivalent to a reference for now.
This commit is contained in:
Luke 2021-07-05 05:45:20 +01:00 committed by Andreas Kling
parent 62c015dc96
commit a826df773e
5 changed files with 43 additions and 16 deletions

View file

@ -573,7 +573,8 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
)~~~");
}
} else if (is_wrappable_type(parameter.type)) {
scoped_generator.append(R"~~~(
if (!parameter.type.nullable) {
scoped_generator.append(R"~~~(
auto @cpp_name@_object = @js_name@@js_suffix@.to_object(global_object);
if (vm.exception())
@return_statement@
@ -585,6 +586,23 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
auto& @cpp_name@ = static_cast<@parameter.type.name@Wrapper*>(@cpp_name@_object)->impl();
)~~~");
} else {
scoped_generator.append(R"~~~(
@parameter.type.name@* @cpp_name@ = nullptr;
if (!@js_name@@js_suffix@.is_null()) {
auto @cpp_name@_object = @js_name@@js_suffix@.to_object(global_object);
if (vm.exception())
@return_statement@
if (!is<@parameter.type.name@Wrapper>(@cpp_name@_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "@parameter.type.name@");
@return_statement@
}
@cpp_name@ = &static_cast<@parameter.type.name@Wrapper*>(@cpp_name@_object)->impl();
}
)~~~");
}
} else if (parameter.type.name == "double") {
if (!optional) {
scoped_generator.append(R"~~~(