diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index 207bfc0ef1..7f08327e5e 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -45,6 +46,16 @@ LocationObject::~LocationObject() { } +// https://html.spec.whatwg.org/multipage/history.html#relevant-document +DOM::Document const* LocationObject::relevant_document() const +{ + // A Location object has an associated relevant Document, which is this Location object's + // relevant global object's browsing context's active document, if this Location object's + // relevant global object's browsing context is non-null, and null otherwise. + auto* browsing_context = static_cast(global_object()).impl().browsing_context(); + return browsing_context ? browsing_context->active_document() : nullptr; +} + // https://html.spec.whatwg.org/multipage/history.html#dom-location-href JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter) { diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.h b/Userland/Libraries/LibWeb/Bindings/LocationObject.h index e89d82b22e..9f7282d942 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.h +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -29,6 +30,8 @@ public: // but we don't have the infrastructure in place to implement them yet. private: + DOM::Document const* relevant_document() const; + JS_DECLARE_NATIVE_FUNCTION(reload); JS_DECLARE_NATIVE_FUNCTION(replace);