1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

LibWeb: Generate HTMLImageElement bindings from IDL :^)

This commit is contained in:
Andreas Kling 2020-06-21 15:26:09 +02:00
parent af51dc105a
commit 119dd2c541
6 changed files with 18 additions and 118 deletions

View file

@ -407,17 +407,19 @@ void generate_implementation(const IDL::Interface& interface)
out() << "}";
// Implementation: impl_from()
out() << "static " << interface.name << "* impl_from(JS::Interpreter& interpreter, JS::GlobalObject& global_object)";
out() << "{";
out() << " auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);";
out() << " if (!this_object)";
out() << " return {};";
out() << " if (!this_object->inherits(\"" << wrapper_class << "\")) {";
out() << " interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotA, \"" << interface.name << "\");";
out() << " return nullptr;";
out() << " }";
out() << " return &static_cast<" << wrapper_class << "*>(this_object)->impl();";
out() << "}";
if (!interface.attributes.is_empty() || !interface.functions.is_empty()) {
out() << "static " << interface.name << "* impl_from(JS::Interpreter& interpreter, JS::GlobalObject& global_object)";
out() << "{";
out() << " auto* this_object = interpreter.this_value(global_object).to_object(interpreter, global_object);";
out() << " if (!this_object)";
out() << " return {};";
out() << " if (!this_object->inherits(\"" << wrapper_class << "\")) {";
out() << " interpreter.throw_exception<JS::TypeError>(JS::ErrorType::NotA, \"" << interface.name << "\");";
out() << " return nullptr;";
out() << " }";
out() << " return &static_cast<" << wrapper_class << "*>(this_object)->impl();";
out() << "}";
}
auto generate_to_cpp = [&](auto& parameter, auto& js_name, auto& js_suffix, auto cpp_name, bool return_void = false) {
auto generate_return = [&] {