diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-02-19 21:45:47 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-20 02:03:24 +0100 |
commit | 86650e37febd3badf5f4bf1748664564f63601c3 (patch) | |
tree | 03f4fb6d18894b5bfc7ade2f62ba0813729be55f | |
parent | 60bc5e3b5bbb5f6999c203e7a53687ab16031bd3 (diff) | |
download | serenity-86650e37febd3badf5f4bf1748664564f63601c3.zip |
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
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 0d9c50b8f1..63c4389785 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -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(); } )~~~"); } |