mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:07:34 +00:00
LibWeb: Add Storage interface and window.localStorage
This is a naive-but-somewhat-functional initial implementation of HTML Storage. Note that there is no persistence yet, everything is in-process only, and one local Storage object per origin.
This commit is contained in:
parent
a856cf8d4c
commit
47979996e8
10 changed files with 250 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -32,6 +32,7 @@
|
|||
#include <LibWeb/Bindings/Replaceable.h>
|
||||
#include <LibWeb/Bindings/ScreenWrapper.h>
|
||||
#include <LibWeb/Bindings/SelectionWrapper.h>
|
||||
#include <LibWeb/Bindings/StorageWrapper.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/Bindings/WindowObjectHelper.h>
|
||||
#include <LibWeb/Crypto/Crypto.h>
|
||||
|
@ -42,6 +43,7 @@
|
|||
#include <LibWeb/HTML/EventHandler.h>
|
||||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Storage.h>
|
||||
#include <LibWeb/Origin.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/WebAssembly/WebAssemblyObject.h>
|
||||
|
@ -110,6 +112,8 @@ void WindowObject::initialize_global_object()
|
|||
|
||||
define_direct_property("CSS", heap().allocate<CSSNamespace>(*this, *this), 0);
|
||||
|
||||
define_native_accessor("localStorage", local_storage_getter, {}, attr);
|
||||
|
||||
// Legacy
|
||||
define_native_accessor("event", event_getter, event_setter, JS::Attribute::Enumerable);
|
||||
|
||||
|
@ -646,6 +650,13 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_y_getter)
|
|||
return JS::Value(impl->screen_y());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::local_storage_getter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm, global_object));
|
||||
// FIXME: localStorage may throw. We have to deal with that here.
|
||||
return wrap(global_object, *impl->local_storage());
|
||||
}
|
||||
|
||||
#define __ENUMERATE(attribute, event_name) \
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_getter) \
|
||||
{ \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue