diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index fb9079eb21..a616a69d8d 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -114,6 +114,7 @@ void WindowObject::initialize_global_object() define_direct_property("CSS", heap().allocate(*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) \ { \ diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.h b/Userland/Libraries/LibWeb/Bindings/WindowObject.h index 2e35d12bef..3cf9939b58 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.h @@ -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); diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index d016feb793..187d6cbb4d 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -528,6 +528,17 @@ RefPtr Window::local_storage() }); } +// https://html.spec.whatwg.org/multipage/webstorage.html#dom-sessionstorage +RefPtr Window::session_storage() +{ + // FIXME: Implement according to spec. + + static HashMap> 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() { diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index cb6c7414f5..252e7da939 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -104,6 +104,7 @@ public: Selection::Selection* get_selection(); RefPtr local_storage(); + RefPtr session_storage(); Window* parent();