1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 15:08:12 +00:00

LibWeb: Add state field to History

This is the "classic history API state" referenced in the current HTML
spec.
This commit is contained in:
Andrew Kaster 2023-09-27 22:39:44 -06:00 committed by Alexander Kalenik
parent 2c27b4e63c
commit 49e0466a3d
3 changed files with 17 additions and 1 deletions

View file

@ -38,6 +38,7 @@ void History::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_associated_document);
visitor.visit(m_state);
}
// https://html.spec.whatwg.org/multipage/history.html#dom-history-pushstate
@ -65,6 +66,17 @@ WebIDL::ExceptionOr<u64> History::length() const
return m_length;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-history-state
WebIDL::ExceptionOr<JS::Value> History::state() const
{
// 1. If this's relevant global object's associated Document is not fully active, then throw a "SecurityError" DOMException.
if (!m_associated_document->is_fully_active())
return WebIDL::SecurityError::create(realm(), "Cannot perform state on a document that isn't fully active."_fly_string);
// 2. Return this's state.
return m_state;
}
// https://html.spec.whatwg.org/multipage/history.html#dom-history-go
WebIDL::ExceptionOr<void> History::go(long delta = 0)
{