1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:57:35 +00:00

LibWeb: Add window.sessionStorage

This commit is contained in:
Paul Wratt 2022-03-08 04:39:44 +13:00 committed by Linus Groh
parent 1535fe0324
commit 83eb5ac8fd
4 changed files with 21 additions and 0 deletions

View file

@ -114,6 +114,7 @@ void WindowObject::initialize_global_object()
define_direct_property("CSS", heap().allocate<CSSNamespace>(*this, *this), 0);
define_native_accessor("localStorage", local_storage_getter, {}, attr);
define_native_accessor("sessionStorage", session_storage_getter, {}, attr);
define_native_accessor("origin", origin_getter, {}, attr);
// Legacy
@ -649,6 +650,13 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::local_storage_getter)
return wrap(global_object, *impl->local_storage());
}
JS_DEFINE_NATIVE_FUNCTION(WindowObject::session_storage_getter)
{
auto* impl = TRY(impl_from(vm, global_object));
// FIXME: sessionStorage may throw. We have to deal with that here.
return wrap(global_object, *impl->session_storage());
}
#define __ENUMERATE(attribute, event_name) \
JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_getter) \
{ \

View file

@ -107,6 +107,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(post_message);
JS_DECLARE_NATIVE_FUNCTION(local_storage_getter);
JS_DECLARE_NATIVE_FUNCTION(session_storage_getter);
JS_DECLARE_NATIVE_FUNCTION(origin_getter);
JS_DECLARE_NATIVE_FUNCTION(alert);

View file

@ -528,6 +528,17 @@ RefPtr<HTML::Storage> Window::local_storage()
});
}
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-sessionstorage
RefPtr<HTML::Storage> Window::session_storage()
{
// FIXME: Implement according to spec.
static HashMap<Origin, NonnullRefPtr<HTML::Storage>> session_storage_per_origin;
return session_storage_per_origin.ensure(associated_document().origin(), [] {
return HTML::Storage::create();
});
}
// https://html.spec.whatwg.org/multipage/browsers.html#dom-parent
Window* Window::parent()
{

View file

@ -104,6 +104,7 @@ public:
Selection::Selection* get_selection();
RefPtr<HTML::Storage> local_storage();
RefPtr<HTML::Storage> session_storage();
Window* parent();