1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:28:11 +00:00

LibWeb: Don't perform ToObject when converting values to wrapper types

WebIDL checks the type of the value is Object instead of performing
ToObject on the value.

https://webidl.spec.whatwg.org/#implements
This commit is contained in:
Luke Wilde 2022-02-19 21:45:47 +00:00 committed by Andreas Kling
parent 60bc5e3b5b
commit 86650e37fe

View file

@ -336,23 +336,19 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} else if (IDL::is_wrappable_type(*parameter.type)) {
if (!parameter.type->nullable) {
scoped_generator.append(R"~~~(
auto @cpp_name@_object = TRY(@js_name@@js_suffix@.to_object(global_object));
if (!is<@wrapper_name@>(@cpp_name@_object))
if (!@js_name@@js_suffix@.is_object() || !is<@wrapper_name@>(@js_name@@js_suffix@.as_object()))
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
auto& @cpp_name@ = static_cast<@wrapper_name@*>(@cpp_name@_object)->impl();
auto& @cpp_name@ = static_cast<@wrapper_name@&>(@js_name@@js_suffix@.as_object()).impl();
)~~~");
} else {
scoped_generator.append(R"~~~(
@parameter.type.name@* @cpp_name@ = nullptr;
if (!@js_name@@js_suffix@.is_nullish()) {
auto @cpp_name@_object = TRY(@js_name@@js_suffix@.to_object(global_object));
if (!is<@wrapper_name@>(@cpp_name@_object))
if (!@js_name@@js_suffix@.is_object() || !is<@wrapper_name@>(@js_name@@js_suffix@.as_object()))
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
@cpp_name@ = &static_cast<@wrapper_name@*>(@cpp_name@_object)->impl();
@cpp_name@ = &static_cast<@wrapper_name@&>(@js_name@@js_suffix@.as_object()).impl();
}
)~~~");
}