summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-20 11:14:23 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-20 14:48:07 +0200
commitac76df3d47bb2de85aef2440ea1bb203bf7bd018 (patch)
tree1f766e794d7ee424fe4feea2ed401e9e47a57eb6
parente4fd04204144b9ac40dc4791aab5562066e3f349 (diff)
downloadserenity-ac76df3d47bb2de85aef2440ea1bb203bf7bd018.zip
LibWeb: Implement Window.frameElement
-rw-r--r--Userland/Libraries/LibWeb/HTML/Window.cpp28
-rw-r--r--Userland/Libraries/LibWeb/HTML/Window.h2
2 files changed, 30 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index 5235112692..b6cd397fbf 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -764,6 +764,7 @@ void Window::initialize(JS::Realm& realm)
define_native_accessor(realm, "top", top_getter, nullptr, 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);
define_native_accessor(realm, "name", name_getter, name_setter, JS::Attribute::Enumerable);
define_native_accessor(realm, "history", history_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "performance", performance_getter, performance_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
@@ -1134,6 +1135,33 @@ JS_DEFINE_NATIVE_FUNCTION(Window::document_getter)
return &impl->associated_document();
}
+// https://html.spec.whatwg.org/multipage/browsers.html#dom-frameelement
+JS_DEFINE_NATIVE_FUNCTION(Window::frame_element_getter)
+{
+ auto* impl = TRY(impl_from(vm));
+
+ // 1. Let current be this Window object's browsing context.
+ auto* current = impl->browsing_context();
+
+ // 2. If current is null, then return null.
+ if (!current)
+ return JS::js_null();
+
+ // 3. Let container be current's container.
+ auto* container = current->container();
+
+ // 4. If container is null, then return null.
+ if (!container)
+ return JS::js_null();
+
+ // 5. If container's node document's origin is not same origin-domain with the current settings object's origin, then return null.
+ if (!container->document().origin().is_same_origin(current_settings_object().origin()))
+ return JS::js_null();
+
+ // 6. Return container.
+ return container;
+}
+
JS_DEFINE_NATIVE_FUNCTION(Window::performance_getter)
{
auto* impl = TRY(impl_from(vm));
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index 31f0f89206..144898fe38 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.h
+++ b/Userland/Libraries/LibWeb/HTML/Window.h
@@ -211,6 +211,8 @@ private:
JS_DECLARE_NATIVE_FUNCTION(document_getter);
+ JS_DECLARE_NATIVE_FUNCTION(frame_element_getter);
+
JS_DECLARE_NATIVE_FUNCTION(location_getter);
JS_DECLARE_NATIVE_FUNCTION(location_setter);