From 1528e9109c8f7be7210611309dcc5bfbd40def57 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Fri, 23 Feb 2024 20:26:32 +0100 Subject: [PATCH] LibWeb: Add special handling for WindowProxy in [Replaceable] setters Setters for Window object should consider WindowProxy wrapper by: - Verifying `this_value` is `WindowProxy` (not `HTML::Window`) - Defining properties on the underlying Window object instead of on the WindowProxy itself. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 17 ++++++++++++++++- .../expected/window-event-property-setter.txt | 1 + .../input/window-event-property-setter.html | 7 +++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/window-event-property-setter.txt create mode 100644 Tests/LibWeb/Text/input/window-event-property-setter.html diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index a47a20d178..4be37611e7 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -3186,7 +3186,21 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@) } )~~~"); } else if (attribute.extended_attributes.contains("Replaceable"sv)) { - attribute_generator.append(R"~~~( + if (interface.name.is_one_of("Window")) { + attribute_generator.append(R"~~~( +JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@) +{ + auto this_value = vm.this_value(); + if (!this_value.is_object() || !is(this_value.as_object())) + return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "@namespaced_name@"); + auto& window_proxy = static_cast(this_value.as_object()); + TRY(window_proxy.window()->internal_define_own_property("@attribute.name@", JS::PropertyDescriptor { .value = vm.argument(0), .writable = true })); + return JS::js_undefined(); +} +)~~~"); + } else { + + attribute_generator.append(R"~~~( JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@) { auto this_value = vm.this_value(); @@ -3196,6 +3210,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@) return JS::js_undefined(); } )~~~"); + } } else if (auto put_forwards_identifier = attribute.extended_attributes.get("PutForwards"sv); put_forwards_identifier.has_value()) { attribute_generator.set("put_forwards_identifier"sv, *put_forwards_identifier); diff --git a/Tests/LibWeb/Text/expected/window-event-property-setter.txt b/Tests/LibWeb/Text/expected/window-event-property-setter.txt new file mode 100644 index 0000000000..ce01362503 --- /dev/null +++ b/Tests/LibWeb/Text/expected/window-event-property-setter.txt @@ -0,0 +1 @@ +hello diff --git a/Tests/LibWeb/Text/input/window-event-property-setter.html b/Tests/LibWeb/Text/input/window-event-property-setter.html new file mode 100644 index 0000000000..eafca73ccc --- /dev/null +++ b/Tests/LibWeb/Text/input/window-event-property-setter.html @@ -0,0 +1,7 @@ + +