1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 08:07:45 +00:00

LibWeb/HTML: Port Window.self to IDL

This commit is contained in:
Linus Groh 2023-03-05 18:38:29 +00:00
parent d57876306c
commit 437a7c977e
3 changed files with 9 additions and 10 deletions

View file

@ -1093,7 +1093,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
// FIXME: These should be native accessors, not properties // FIXME: These should be native accessors, not properties
define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable);
define_native_accessor(realm, "frames", frames_getter, {}, JS::Attribute::Enumerable); define_native_accessor(realm, "frames", frames_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "self", self_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable); define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "document", document_getter, {}, JS::Attribute::Enumerable); define_native_accessor(realm, "document", document_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable); define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable);
@ -1210,6 +1209,13 @@ JS::NonnullGCPtr<WindowProxy> Window::window() const
return verify_cast<WindowProxy>(relevant_realm(*this).global_environment().global_this_value()); return verify_cast<WindowProxy>(relevant_realm(*this).global_environment().global_this_value());
} }
// https://html.spec.whatwg.org/multipage/window-object.html#dom-self
JS::NonnullGCPtr<WindowProxy> Window::self() const
{
// The window, frames, and self getter steps are to return this's relevant realm.[[GlobalEnv]].[[GlobalThisValue]].
return verify_cast<WindowProxy>(relevant_realm(*this).global_environment().global_this_value());
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator // https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
JS::NonnullGCPtr<Navigator> Window::navigator() const JS::NonnullGCPtr<Navigator> Window::navigator() const
{ {
@ -1530,14 +1536,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::top_getter)
return browsing_context->top_level_browsing_context().window_proxy(); return browsing_context->top_level_browsing_context().window_proxy();
} }
// https://html.spec.whatwg.org/multipage/window-object.html#dom-self
JS_DEFINE_NATIVE_FUNCTION(Window::self_getter)
{
auto* impl = TRY(impl_from(vm));
// The window, frames, and self getter steps are to return this's relevant realm.[[GlobalEnv]].[[GlobalThisValue]].
return &relevant_realm(*impl).global_environment().global_this_value();
}
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames // https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
JS_DEFINE_NATIVE_FUNCTION(Window::frames_getter) JS_DEFINE_NATIVE_FUNCTION(Window::frames_getter)
{ {

View file

@ -141,6 +141,7 @@ public:
// JS API functions // JS API functions
JS::NonnullGCPtr<WindowProxy> window() const; JS::NonnullGCPtr<WindowProxy> window() const;
JS::NonnullGCPtr<WindowProxy> self() const;
JS::NonnullGCPtr<Navigator> navigator() const; JS::NonnullGCPtr<Navigator> navigator() const;
@ -243,7 +244,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter); JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
JS_DECLARE_NATIVE_FUNCTION(frames_getter); JS_DECLARE_NATIVE_FUNCTION(frames_getter);
JS_DECLARE_NATIVE_FUNCTION(self_getter);
JS_DECLARE_NATIVE_FUNCTION(parent_getter); JS_DECLARE_NATIVE_FUNCTION(parent_getter);

View file

@ -7,6 +7,7 @@
interface Window : EventTarget { interface Window : EventTarget {
// the current browsing context // the current browsing context
[LegacyUnforgeable] readonly attribute WindowProxy window; [LegacyUnforgeable] readonly attribute WindowProxy window;
[Replaceable] readonly attribute WindowProxy self;
// the user agent // the user agent
readonly attribute Navigator navigator; readonly attribute Navigator navigator;