LibWeb: Add support for the BufferSource IDL parameter type

This commit is contained in:
Linus Groh 2021-12-13 22:06:33 +00:00 committed by Andreas Kling
parent 841bd680fa
commit 976ab23b9c
Notes: sideshowbarker 2024-07-17 22:47:59 +09:00

View file

@ -1138,6 +1138,14 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
@js_name@@js_suffix@ = new_promise;
}
auto @cpp_name@ = JS::make_handle(&static_cast<JS::Promise&>(@js_name@@js_suffix@.as_object()));
)~~~");
} else if (parameter.type->name == "BufferSource") {
scoped_generator.append(R"~~~(
if (!@js_name@@js_suffix@.is_object() || !(is<JS::TypedArrayBase>(@js_name@@js_suffix@.as_object()) || is<JS::ArrayBuffer>(@js_name@@js_suffix@.as_object()) || is<JS::DataView>(@js_name@@js_suffix@.as_object())))
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
// TODO: Should we make this a Variant?
auto @cpp_name@ = JS::make_handle(&@js_name@@js_suffix@.as_object());
)~~~");
} else if (parameter.type->name == "any") {
if (!optional) {
@ -2756,6 +2764,7 @@ void generate_prototype_implementation(IDL::Interface const& interface)
generator.append(R"~~~(
#include <AK/Function.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/DataView.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>