mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
Meta: Reuse "define the operations" algorithm for generated namespaces
This is one step closer to the spec. No functional changes.
This commit is contained in:
parent
cb1a1a5cb5
commit
3522ff16c0
Notes:
github-actions[bot]
2025-08-26 08:15:41 +00:00
Author: https://github.com/gmta
Commit: 3522ff16c0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5987
1 changed files with 22 additions and 33 deletions
|
@ -4904,6 +4904,27 @@ using namespace Web::XHR;
|
|||
)~~~"sv);
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#define-the-operations
|
||||
static void define_the_operations(SourceGenerator& generator, OrderedHashMap<ByteString, Vector<Function&>> const& operations)
|
||||
{
|
||||
for (auto const& operation : operations) {
|
||||
auto function_generator = generator.fork();
|
||||
function_generator.set("function.name", operation.key);
|
||||
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(operation.key.to_snakecase()));
|
||||
function_generator.set("function.length", ByteString::number(get_shortest_function_length(operation.value)));
|
||||
|
||||
// NOTE: This assumes that every function in the overload set has the same attribute set.
|
||||
if (operation.value[0].extended_attributes.contains("LegacyUnforgable"sv))
|
||||
function_generator.set("function.attributes", "JS::Attribute::Enumerable");
|
||||
else
|
||||
function_generator.set("function.attributes", "JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable");
|
||||
|
||||
function_generator.append(R"~~~(
|
||||
define_native_function(realm, "@function.name@"_utf16_fly_string, @function.name:snakecase@, @function.length@, @function.attributes@);
|
||||
)~~~");
|
||||
}
|
||||
}
|
||||
|
||||
void generate_namespace_implementation(IDL::Interface const& interface, StringBuilder& builder)
|
||||
{
|
||||
SourceGenerator generator { builder };
|
||||
|
@ -4958,7 +4979,6 @@ GC_DEFINE_ALLOCATOR(@namespace_class@);
|
|||
void @namespace_class@::initialize(JS::Realm& realm)
|
||||
{
|
||||
[[maybe_unused]] auto& vm = this->vm();
|
||||
[[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable;
|
||||
|
||||
Base::initialize(realm);
|
||||
|
||||
|
@ -4966,17 +4986,7 @@ void @namespace_class@::initialize(JS::Realm& realm)
|
|||
|
||||
)~~~");
|
||||
|
||||
// https://webidl.spec.whatwg.org/#es-operations
|
||||
for (auto const& overload_set : interface.overload_sets) {
|
||||
auto function_generator = generator.fork();
|
||||
function_generator.set("function.name", overload_set.key);
|
||||
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(overload_set.key.to_snakecase()));
|
||||
function_generator.set("function.length", ByteString::number(get_shortest_function_length(overload_set.value)));
|
||||
|
||||
function_generator.append(R"~~~(
|
||||
define_native_function(realm, "@function.name@"_utf16_fly_string, @function.name:snakecase@, @function.length@, default_attributes);
|
||||
)~~~");
|
||||
}
|
||||
define_the_operations(generator, interface.overload_sets);
|
||||
|
||||
if (interface.extended_attributes.contains("WithInitializer"sv)) {
|
||||
generator.append(R"~~~(
|
||||
|
@ -5101,27 +5111,6 @@ private:
|
|||
)~~~");
|
||||
}
|
||||
|
||||
// https://webidl.spec.whatwg.org/#define-the-operations
|
||||
static void define_the_operations(SourceGenerator& generator, HashMap<ByteString, Vector<Function&>> const& operations)
|
||||
{
|
||||
for (auto const& operation : operations) {
|
||||
auto function_generator = generator.fork();
|
||||
function_generator.set("function.name", operation.key);
|
||||
function_generator.set("function.name:snakecase", make_input_acceptable_cpp(operation.key.to_snakecase()));
|
||||
function_generator.set("function.length", ByteString::number(get_shortest_function_length(operation.value)));
|
||||
|
||||
// NOTE: This assumes that every function in the overload set has the same attribute set.
|
||||
if (operation.value[0].extended_attributes.contains("LegacyUnforgable"sv))
|
||||
function_generator.set("function.attributes", "JS::Attribute::Enumerable");
|
||||
else
|
||||
function_generator.set("function.attributes", "JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable");
|
||||
|
||||
function_generator.append(R"~~~(
|
||||
define_native_function(realm, "@function.name@"_utf16_fly_string, @function.name:snakecase@, @function.length@, @function.attributes@);
|
||||
)~~~");
|
||||
}
|
||||
}
|
||||
|
||||
void generate_constructor_implementation(IDL::Interface const& interface, StringBuilder& builder)
|
||||
{
|
||||
SourceGenerator generator { builder };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue