mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 08:08:43 +00:00
LibWeb: Add support for dictionaries in overload resolution
By making use of the known set of supported dictionary names in that overload set. Note that this list is typically very small (the max that we have currently is 1).
This commit is contained in:
parent
013c2a1c7c
commit
70599d3f8d
Notes:
github-actions[bot]
2024-10-28 22:33:23 +00:00
Author: https://github.com/shannonbooth
Commit: 70599d3f8d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2022
3 changed files with 45 additions and 12 deletions
|
@ -2250,6 +2250,21 @@ static size_t resolve_distinguishing_argument_index(Interface const& interface,
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
static void generate_dictionary_types(SourceGenerator& generator, Vector<ByteString> const& dictionary_types)
|
||||
{
|
||||
generator.append(R"~~~(
|
||||
Vector<StringView> dictionary_types {
|
||||
)~~~");
|
||||
|
||||
for (auto const& dictionary : dictionary_types) {
|
||||
generator.append(" \"");
|
||||
generator.append(dictionary);
|
||||
generator.appendln("\"sv,");
|
||||
}
|
||||
|
||||
generator.append("};\n");
|
||||
}
|
||||
|
||||
static void generate_overload_arbiter(SourceGenerator& generator, auto const& overload_set, IDL::Interface const& interface, ByteString const& class_name, IsConstructor is_constructor)
|
||||
{
|
||||
auto function_generator = generator.fork();
|
||||
|
@ -2260,6 +2275,8 @@ static void generate_overload_arbiter(SourceGenerator& generator, auto const& ov
|
|||
|
||||
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
|
||||
|
||||
HashTable<ByteString> dictionary_types;
|
||||
|
||||
if (is_constructor == IsConstructor::Yes) {
|
||||
function_generator.append(R"~~~(
|
||||
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> @constructor_class@::construct(JS::FunctionObject& new_target)
|
||||
|
@ -2324,6 +2341,10 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
|
|||
optionality_builder.append(", "sv);
|
||||
}
|
||||
|
||||
auto const& type = overload.types[i];
|
||||
if (interface.dictionaries.contains(type->name()))
|
||||
dictionary_types.set(type->name());
|
||||
|
||||
types_builder.append(generate_constructor_for_idl_type(overload.types[i]));
|
||||
|
||||
optionality_builder.append("IDL::Optionality::"sv);
|
||||
|
@ -2360,11 +2381,16 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@function.name:snakecase@)
|
|||
|
||||
function_generator.append(R"~~~(
|
||||
}
|
||||
)~~~");
|
||||
|
||||
generate_dictionary_types(function_generator, dictionary_types.values());
|
||||
|
||||
function_generator.append(R"~~~(
|
||||
|
||||
if (!effective_overload_set.has_value())
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::OverloadResolutionFailed);
|
||||
|
||||
auto chosen_overload = TRY(WebIDL::resolve_overload(vm, effective_overload_set.value()));
|
||||
auto chosen_overload = TRY(WebIDL::resolve_overload(vm, effective_overload_set.value(), dictionary_types));
|
||||
switch (chosen_overload.callable_id) {
|
||||
)~~~");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue