mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +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:
parent
60bc5e3b5b
commit
86650e37fe
1 changed files with 4 additions and 8 deletions
|
@ -336,23 +336,19 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
} else if (IDL::is_wrappable_type(*parameter.type)) {
|
} else if (IDL::is_wrappable_type(*parameter.type)) {
|
||||||
if (!parameter.type->nullable) {
|
if (!parameter.type->nullable) {
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
auto @cpp_name@_object = TRY(@js_name@@js_suffix@.to_object(global_object));
|
if (!@js_name@@js_suffix@.is_object() || !is<@wrapper_name@>(@js_name@@js_suffix@.as_object()))
|
||||||
|
|
||||||
if (!is<@wrapper_name@>(@cpp_name@_object))
|
|
||||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
|
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 {
|
} else {
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
@parameter.type.name@* @cpp_name@ = nullptr;
|
@parameter.type.name@* @cpp_name@ = nullptr;
|
||||||
if (!@js_name@@js_suffix@.is_nullish()) {
|
if (!@js_name@@js_suffix@.is_nullish()) {
|
||||||
auto @cpp_name@_object = TRY(@js_name@@js_suffix@.to_object(global_object));
|
if (!@js_name@@js_suffix@.is_object() || !is<@wrapper_name@>(@js_name@@js_suffix@.as_object()))
|
||||||
|
|
||||||
if (!is<@wrapper_name@>(@cpp_name@_object))
|
|
||||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
|
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();
|
||||||
}
|
}
|
||||||
)~~~");
|
)~~~");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue