LibWeb: Implement window.top
This simply returns the main frame's window object. If accessed inside the main frame, it will return itself.
This commit is contained in:
parent
779f0c6e91
commit
2f9321a0d4
Notes:
sideshowbarker
2024-07-18 20:39:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2f9321a0d43
2 changed files with 16 additions and 0 deletions
|
@ -46,6 +46,7 @@
|
|||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/Origin.h>
|
||||
#include <LibWeb/Page/Frame.h>
|
||||
|
||||
#include <LibWeb/Bindings/WindowObjectHelper.h>
|
||||
|
||||
|
@ -66,6 +67,7 @@ void WindowObject::initialize_global_object()
|
|||
define_property("window", this, JS::Attribute::Enumerable);
|
||||
define_property("frames", this, JS::Attribute::Enumerable);
|
||||
define_property("self", this, JS::Attribute::Enumerable);
|
||||
define_native_property("top", top_getter, JS::Attribute::Enumerable);
|
||||
define_native_property("document", document_getter, nullptr, JS::Attribute::Enumerable);
|
||||
define_native_property("performance", performance_getter, nullptr, JS::Attribute::Enumerable);
|
||||
define_native_property("screen", screen_getter, nullptr, JS::Attribute::Enumerable);
|
||||
|
@ -352,6 +354,18 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::btoa)
|
|||
return JS::js_string(vm, move(encoded));
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(WindowObject::top_getter)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto* this_frame = impl->document().frame();
|
||||
VERIFY(this_frame);
|
||||
VERIFY(this_frame->main_frame().document());
|
||||
auto& top_window = this_frame->main_frame().document()->window();
|
||||
return top_window.wrapper();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(WindowObject::document_getter)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
|
|
|
@ -78,6 +78,8 @@ public:
|
|||
private:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
JS_DECLARE_NATIVE_GETTER(top_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_GETTER(document_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_GETTER(performance_getter);
|
||||
|
|
Loading…
Add table
Reference in a new issue