mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibWeb: Fix that non-member calls to window gave the wrong this_value
We treat all NativeFunctions as strict mode and thus window function which were called in a global context (i.e. `setTimeout(f, 0)`) got a null this_value. But we really need to treat all functions not defined by the ECMAScript specification as non-strict. In most cases this won't matter however since Window is also the global_object we have an extra bit of logic. To fix this more correctly we would need to track the strictness of NativeFunctions.
This commit is contained in:
parent
a67f0cbfa2
commit
e22539bdd9
Notes:
sideshowbarker
2024-07-18 08:19:09 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/e22539bdd95 Pull-request: https://github.com/SerenityOS/serenity/pull/9016 Issue: https://github.com/SerenityOS/serenity/issues/8989 Reviewed-by: https://github.com/linusg ✅
1 changed files with 13 additions and 4 deletions
|
@ -102,11 +102,20 @@ Origin WindowObject::origin() const
|
|||
|
||||
static DOM::Window* impl_from(JS::VM& vm, JS::GlobalObject& global_object)
|
||||
{
|
||||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object) {
|
||||
VERIFY_NOT_REACHED();
|
||||
return nullptr;
|
||||
// Since this is a non built-in function we must treat it as non-strict mode
|
||||
// this means that a nullish this_value should be converted to the
|
||||
// global_object. Generally this does not matter as we try to convert the
|
||||
// this_value to a specific object type in the bindings. But since window is
|
||||
// the global object we make an exception here.
|
||||
// This allows calls like `setTimeout(f, 10)` to work.
|
||||
auto this_value = vm.this_value(global_object);
|
||||
if (this_value.is_nullish()) {
|
||||
this_value = global_object.value_of();
|
||||
}
|
||||
|
||||
auto* this_object = this_value.to_object(global_object);
|
||||
VERIFY(this_object);
|
||||
|
||||
if (StringView("WindowObject") != this_object->class_name()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "WindowObject");
|
||||
return nullptr;
|
||||
|
|
Loading…
Reference in a new issue