mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 05:05:32 +03:00
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.
This commit is contained in:
parent
9b1b8828b4
commit
1528e9109c
Notes:
sideshowbarker
2024-07-17 10:16:43 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/1528e9109c Pull-request: https://github.com/SerenityOS/serenity/pull/23319
@ -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<WindowProxy>(this_value.as_object()))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@namespaced_name@");
|
||||
auto& window_proxy = static_cast<WindowProxy&>(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);
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
hello
|
@ -0,0 +1,7 @@
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
window.event = "hello";
|
||||
println(window.event);
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user