Files
ladybird/Libraries/LibWeb/HTML/NavigationDestination.cpp
Shannon Booth fd44da6829 LibWeb/Bindings: Emit one bindings header and cpp per IDL
Previously, the LibWeb bindings generator would output multiple per
interface files like Prototype/Constructor/Namespace/GlobalMixin
depending on the contents of that IDL file.

This complicates the build system as it means that it does not know
what files will be generated without knowledge of the contents of that
IDL file.

Instead, for each IDL file only generate a single Bindings/<IDLFile>.h
and Bindings/<IDLFile>.cpp.
2026-04-21 07:36:13 +02:00

95 lines
2.8 KiB
C++

/*
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGC/Heap.h>
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/NavigationDestination.h>
#include <LibWeb/HTML/NavigationDestination.h>
#include <LibWeb/HTML/NavigationHistoryEntry.h>
#include <LibWeb/HTML/StructuredSerialize.h>
namespace Web::HTML {
GC_DEFINE_ALLOCATOR(NavigationDestination);
GC::Ref<NavigationDestination> NavigationDestination::create(JS::Realm& realm)
{
return realm.create<NavigationDestination>(realm);
}
NavigationDestination::NavigationDestination(JS::Realm& realm)
: Bindings::PlatformObject(realm)
{
}
NavigationDestination::~NavigationDestination() = default;
void NavigationDestination::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(NavigationDestination);
Base::initialize(realm);
}
void NavigationDestination::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_entry);
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-url
String NavigationDestination::url() const
{
// The url getter steps are to return this's URL, serialized.
return m_url.serialize();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-key
String NavigationDestination::key() const
{
// The key getter steps are:
// 1. If this's entry is null, then return the empty string.
// 2. Return this's entry's key.
return (m_entry == nullptr) ? String {} : m_entry->key();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-id
String NavigationDestination::id() const
{
// The id getter steps are:
// 1. If this's entry is null, then return the empty string.
// 2. Return this's entry's ID.
return (m_entry == nullptr) ? String {} : m_entry->id();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-index
i64 NavigationDestination::index() const
{
// The index getter steps are:
// 1. If this's entry is null, then return -1.
// 2. Return this's entry's index.
return (m_entry == nullptr) ? -1 : m_entry->index();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-samedocument
bool NavigationDestination::same_document() const
{
// The sameDocument getter steps are to return this's is same document.
return m_is_same_document;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigationdestination-getstate
WebIDL::ExceptionOr<JS::Value> NavigationDestination::get_state()
{
// The getState() method steps are to return StructuredDeserialize(this's state).
return structured_deserialize(vm(), m_state, realm());
}
}