mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
LibWeb: Add support for optional, non-nullable wrapper types
This commit is contained in:
parent
86650e37fe
commit
567abd52a3
1 changed files with 13 additions and 1 deletions
|
@ -335,12 +335,24 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
}
|
}
|
||||||
} else if (IDL::is_wrappable_type(*parameter.type)) {
|
} else if (IDL::is_wrappable_type(*parameter.type)) {
|
||||||
if (!parameter.type->nullable) {
|
if (!parameter.type->nullable) {
|
||||||
scoped_generator.append(R"~~~(
|
if (!optional) {
|
||||||
|
scoped_generator.append(R"~~~(
|
||||||
if (!@js_name@@js_suffix@.is_object() || !is<@wrapper_name@>(@js_name@@js_suffix@.as_object()))
|
if (!@js_name@@js_suffix@.is_object() || !is<@wrapper_name@>(@js_name@@js_suffix@.as_object()))
|
||||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
|
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
|
||||||
|
|
||||||
auto& @cpp_name@ = static_cast<@wrapper_name@&>(@js_name@@js_suffix@.as_object()).impl();
|
auto& @cpp_name@ = static_cast<@wrapper_name@&>(@js_name@@js_suffix@.as_object()).impl();
|
||||||
)~~~");
|
)~~~");
|
||||||
|
} else {
|
||||||
|
scoped_generator.append(R"~~~(
|
||||||
|
Optional<NonnullRefPtr<@parameter.type.name@>> @cpp_name@;
|
||||||
|
if (!@js_name@@js_suffix@.is_undefined()) {
|
||||||
|
if (!@js_name@@js_suffix@.is_object() || !is<@wrapper_name@>(@js_name@@js_suffix@.as_object()))
|
||||||
|
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
|
||||||
|
|
||||||
|
@cpp_name@ = static_cast<@wrapper_name@&>(@js_name@@js_suffix@.as_object()).impl();
|
||||||
|
}
|
||||||
|
)~~~");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
@parameter.type.name@* @cpp_name@ = nullptr;
|
@parameter.type.name@* @cpp_name@ = nullptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue