Skip to content

Commit

Permalink
LibWeb: Add LocationObject::relevant_document()
Browse files Browse the repository at this point in the history
https://html.spec.whatwg.org/multipage/history.html#relevant-document

> 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.
  • Loading branch information
linusg authored and awesomekling committed Mar 5, 2022
1 parent 2f021e9 commit da85252
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <[email protected]>
* Copyright (c) 2022, Linus Groh <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Expand Down Expand Up @@ -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<WindowObject&>(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)
{
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/Bindings/LocationObject.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <[email protected]>
* Copyright (c) 2022, Linus Groh <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Expand Down Expand Up @@ -29,6 +30,8 @@ class LocationObject final : public JS::Object {
// 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);

Expand Down

0 comments on commit da85252

Please sign in to comment.