mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 21:45:20 +00:00
LibWeb/Bindings: Use realm's globalObject as thisValue if nullish
We were missing the step to use realm's global object if thisValue was nullish. This is very trivial to fix, as `impl_this` already handles everything as it should, allowing us to also remove the special casing for WindowProxy.
This commit is contained in:
parent
dcc7fe3663
commit
a14711a9d7
Notes:
github-actions[bot]
2025-04-22 10:18:12 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/a14711a9d7e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4415
2 changed files with 5 additions and 36 deletions
|
@ -4254,48 +4254,18 @@ MUST(impl->set_attribute("@attribute.reflect_name@"_fly_string, cpp_value));
|
|||
}
|
||||
)~~~");
|
||||
} else if (attribute.extended_attributes.contains("Replaceable"sv)) {
|
||||
if (interface.name == "Window"sv) {
|
||||
attribute_generator.append(R"~~~(
|
||||
attribute_generator.append(R"~~~(
|
||||
JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
|
||||
{
|
||||
WebIDL::log_trace(vm, "@class_name@::@attribute.setter_callback@");
|
||||
auto this_value = vm.this_value();
|
||||
if (vm.argument_count() < 1)
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "@namespaced_name@ setter");
|
||||
GC::Ptr<Window> window;
|
||||
if (this_value.is_object()) {
|
||||
if (is<WindowProxy>(this_value.as_object())) {
|
||||
auto& window_proxy = static_cast<WindowProxy&>(this_value.as_object());
|
||||
window = window_proxy.window();
|
||||
} else if (is<Window>(this_value.as_object())) {
|
||||
window = &static_cast<Window&>(this_value.as_object());
|
||||
}
|
||||
}
|
||||
|
||||
if (window) {
|
||||
TRY(window->internal_define_own_property("@attribute.name@"_fly_string, JS::PropertyDescriptor { .value = vm.argument(0), .writable = true }));
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@namespaced_name@");
|
||||
}
|
||||
)~~~");
|
||||
} else {
|
||||
|
||||
attribute_generator.append(R"~~~(
|
||||
JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
|
||||
{
|
||||
WebIDL::log_trace(vm, "@class_name@::@attribute.setter_callback@");
|
||||
auto this_value = vm.this_value();
|
||||
if (!this_value.is_object() || !is<@fully_qualified_name@>(this_value.as_object()))
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@namespaced_name@");
|
||||
if (vm.argument_count() < 1)
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "@namespaced_name@ setter");
|
||||
TRY(this_value.as_object().internal_define_own_property("@attribute.name@"_fly_string, JS::PropertyDescriptor { .value = vm.argument(0), .writable = true }));
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
TRY(impl->internal_define_own_property("@attribute.name@"_fly_string, JS::PropertyDescriptor { .value = vm.argument(0), .writable = true }));
|
||||
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);
|
||||
VERIFY(!put_forwards_identifier->is_empty() && !is_ascii_digit(put_forwards_identifier->byte_at(0))); // Ensure `PropertyKey`s are not Numbers.
|
||||
|
|
|
@ -2,8 +2,7 @@ Harness status: OK
|
|||
|
||||
Found 9 tests
|
||||
|
||||
8 Pass
|
||||
1 Fail
|
||||
9 Pass
|
||||
Pass Global object's getter throws when called on incompatible object
|
||||
Pass Global object's setter throws when called on incompatible object
|
||||
Pass Global object's operation throws when called on incompatible object
|
||||
|
@ -11,5 +10,5 @@ Pass Global object's getter throws when called on incompatible object (document.
|
|||
Pass Global object's setter throws when called on incompatible object (document.all)
|
||||
Pass Global object's operation throws when called on incompatible object (document.all)
|
||||
Pass Global object's getter works when called on null / undefined
|
||||
Fail Global object's setter works when called on null / undefined
|
||||
Pass Global object's setter works when called on null / undefined
|
||||
Pass Global object's operation works when called on null / undefined
|
Loading…
Add table
Reference in a new issue