mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb/IDL: Add support for optional sequences
This commit is contained in:
parent
4493702fb2
commit
3845982d38
Notes:
sideshowbarker
2024-07-17 18:23:22 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/3845982d38 Pull-request: https://github.com/SerenityOS/serenity/pull/14559
1 changed files with 43 additions and 1 deletions
|
@ -707,6 +707,41 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
// 3. If method is undefined, throw a TypeError.
|
||||
// 4. Return the result of creating a sequence from V and method.
|
||||
|
||||
if (optional) {
|
||||
auto sequence_cpp_type = idl_type_name_to_cpp_type(parameterized_type.parameters.first(), interface);
|
||||
sequence_generator.set("sequence.type", sequence_cpp_type.name);
|
||||
sequence_generator.set("sequence.storage_type", sequence_storage_type_to_cpp_storage_type_name(sequence_cpp_type.sequence_storage_type));
|
||||
|
||||
if (!optional_default_value.has_value()) {
|
||||
if (sequence_cpp_type.sequence_storage_type == IDL::SequenceStorageType::Vector) {
|
||||
sequence_generator.append(R"~~~(
|
||||
Optional<@sequence.storage_type@<@sequence.type@>> @cpp_name@;
|
||||
)~~~");
|
||||
} else {
|
||||
sequence_generator.append(R"~~~(
|
||||
Optional<@sequence.storage_type@> @cpp_name@;
|
||||
)~~~");
|
||||
}
|
||||
} else {
|
||||
if (optional_default_value != "[]")
|
||||
TODO();
|
||||
|
||||
if (sequence_cpp_type.sequence_storage_type == IDL::SequenceStorageType::Vector) {
|
||||
sequence_generator.append(R"~~~(
|
||||
@sequence.storage_type@<@sequence.type@> @cpp_name@;
|
||||
)~~~");
|
||||
} else {
|
||||
sequence_generator.append(R"~~~(
|
||||
@sequence.storage_type@ @cpp_name@ { global_object.heap() };
|
||||
)~~~");
|
||||
}
|
||||
}
|
||||
|
||||
sequence_generator.append(R"~~~(
|
||||
if (!@js_name@@js_suffix@.is_undefined()) {
|
||||
)~~~");
|
||||
}
|
||||
|
||||
sequence_generator.append(R"~~~(
|
||||
if (!@js_name@@js_suffix@.is_object())
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObject, @js_name@@js_suffix@.to_string_without_side_effects());
|
||||
|
@ -716,7 +751,14 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotIterable, @js_name@@js_suffix@.to_string_without_side_effects());
|
||||
)~~~");
|
||||
|
||||
parameterized_type.generate_sequence_from_iterable(sequence_generator, acceptable_cpp_name, String::formatted("{}{}", js_name, js_suffix), String::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
|
||||
parameterized_type.generate_sequence_from_iterable(sequence_generator, String::formatted("{}{}", acceptable_cpp_name, optional ? "_non_optional" : ""), String::formatted("{}{}", js_name, js_suffix), String::formatted("iterator_method{}", recursion_depth), interface, recursion_depth + 1);
|
||||
|
||||
if (optional) {
|
||||
sequence_generator.append(R"~~~(
|
||||
@cpp_name@ = move(@cpp_name@_non_optional);
|
||||
}
|
||||
)~~~");
|
||||
}
|
||||
} else if (parameter.type->name == "record") {
|
||||
// https://webidl.spec.whatwg.org/#es-record
|
||||
|
||||
|
|
Loading…
Reference in a new issue