From 60c228b914b52172a711c762bb4054c65d9bf0d6 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Thu, 3 Mar 2022 21:32:55 +0100 Subject: [PATCH] LibWeb: Handle nullish this_value when creating idl functions --- .../LibWeb/WrapperGenerator/IDLGenerators.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 2ca0578b26..9d56cbfc16 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -2994,7 +2994,12 @@ void @prototype_class@::initialize(JS::GlobalObject& global_object) generator.append(R"~~~( static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm, JS::GlobalObject& global_object) { - auto* this_object = TRY(vm.this_value(global_object).to_object(global_object)); + auto this_value = vm.this_value(global_object); + JS::Object* this_object = nullptr; + if (this_value.is_nullish()) + this_object = &vm.current_realm()->global_object(); + else + this_object = TRY(this_value.to_object(global_object)); )~~~"); if (interface.name == "EventTarget") {