소스 검색

LibWeb/HTML: Port Window.parent to IDL

Linus Groh 2 년 전
부모
커밋
c6353ac8cd
3개의 변경된 파일20개의 추가작업 그리고 38개의 파일을 삭제
  1. 18 33
      Userland/Libraries/LibWeb/HTML/Window.cpp
  2. 1 5
      Userland/Libraries/LibWeb/HTML/Window.h
  3. 1 0
      Userland/Libraries/LibWeb/HTML/Window.idl

+ 18 - 33
Userland/Libraries/LibWeb/HTML/Window.cpp

@@ -867,29 +867,6 @@ JS::NonnullGCPtr<HTML::Storage> Window::session_storage()
     return *storage;
 }
 
-// https://html.spec.whatwg.org/multipage/browsers.html#dom-parent
-WindowProxy* Window::parent()
-{
-    // 1. Let current be this Window object's browsing context.
-    auto* current = browsing_context();
-
-    // 2. If current is null, then return null.
-    if (!current)
-        return nullptr;
-
-    // 3. If current is a child browsing context of another browsing context parent,
-    //    then return parent's WindowProxy object.
-    if (current->parent()) {
-        return current->parent()->window_proxy();
-    }
-
-    // 4. Assert: current is a top-level browsing context.
-    VERIFY(current->is_top_level());
-
-    // 5. Return current's WindowProxy object.
-    return current->window_proxy();
-}
-
 // https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone
 WebIDL::ExceptionOr<JS::Value> Window::structured_clone_impl(JS::VM& vm, JS::Value message)
 {
@@ -1073,7 +1050,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
     MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
 
     // FIXME: These should be native accessors, not properties
-    define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable);
     define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable);
     define_native_accessor(realm, "performance", performance_getter, performance_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
     define_native_accessor(realm, "crypto", crypto_getter, {}, JS::Attribute::Enumerable);
@@ -1262,6 +1238,24 @@ JS::GCPtr<WindowProxy const> Window::top() const
     return browsing_context->top_level_browsing_context().window_proxy();
 }
 
+// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-parent
+JS::GCPtr<WindowProxy const> Window::parent() const
+{
+    // 1. Let navigable be this's navigable.
+    auto* navigable = browsing_context();
+
+    // 2. If navigable is null, then return null.
+    if (!navigable)
+        return {};
+
+    // 3. If navigable's parent is not null, then set navigable to navigable's parent.
+    if (auto parent = navigable->parent())
+        navigable = parent;
+
+    // 4. Return navigable's active WindowProxy.
+    return navigable->window_proxy();
+}
+
 // https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
 JS::NonnullGCPtr<Navigator> Window::navigator() const
 {
@@ -1559,15 +1553,6 @@ size_t Window::document_tree_child_browsing_context_count() const
     return this_browsing_context->document_tree_child_browsing_context_count();
 }
 
-JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter)
-{
-    auto* impl = TRY(impl_from(vm));
-    auto* parent = impl->parent();
-    if (!parent)
-        return JS::js_null();
-    return parent;
-}
-
 // https://html.spec.whatwg.org/multipage/browsers.html#dom-frameelement
 JS_DEFINE_NATIVE_FUNCTION(Window::frame_element_getter)
 {

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

@@ -116,9 +116,6 @@ public:
     JS::NonnullGCPtr<HTML::Storage> local_storage();
     JS::NonnullGCPtr<HTML::Storage> session_storage();
 
-    // https://html.spec.whatwg.org/multipage/browsers.html#dom-parent
-    WindowProxy* parent();
-
     WebIDL::ExceptionOr<JS::Value> structured_clone_impl(JS::VM& vm, JS::Value);
 
     void start_an_idle_period();
@@ -148,6 +145,7 @@ public:
     JS::NonnullGCPtr<WindowProxy> frames() const;
     u32 length() const;
     JS::GCPtr<WindowProxy const> top() const;
+    JS::GCPtr<WindowProxy const> parent() const;
 
     JS::NonnullGCPtr<Navigator> navigator() const;
 
@@ -235,8 +233,6 @@ private:
     JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
     JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
 
-    JS_DECLARE_NATIVE_FUNCTION(parent_getter);
-
     JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter);
 
     JS_DECLARE_NATIVE_FUNCTION(scroll_x_getter);

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

@@ -18,6 +18,7 @@ interface Window : EventTarget {
     [Replaceable] readonly attribute WindowProxy frames;
     [Replaceable] readonly attribute unsigned long length;
     [LegacyUnforgeable] readonly attribute WindowProxy? top;
+    [Replaceable] readonly attribute WindowProxy? parent;
 
     // the user agent
     readonly attribute Navigator navigator;