Browse Source

LibWeb/HTML: Port Window.self to IDL

Linus Groh 2 years ago
parent
commit
437a7c977e

+ 7 - 9
Userland/Libraries/LibWeb/HTML/Window.cpp

@@ -1093,7 +1093,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
     // FIXME: These should be native accessors, not properties
     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, "self", self_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, "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());
 }
 
+// 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
 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();
 }
 
-// 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
 JS_DEFINE_NATIVE_FUNCTION(Window::frames_getter)
 {

+ 1 - 1
Userland/Libraries/LibWeb/HTML/Window.h

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

+ 1 - 0
Userland/Libraries/LibWeb/HTML/Window.idl

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