mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb: Implement indexed property support for HTML::Storage
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
We only supported named properties on Storage, and as a result `localStorage[0]` would be disconnected from the Storage's backing map. Fixes at least 20 subtests in WPT in /webstorage.
This commit is contained in:
parent
999c591e83
commit
4c189166f4
Notes:
github-actions[bot]
2024-10-18 21:11:13 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/4c189166f4f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1846
4 changed files with 42 additions and 0 deletions
6
Tests/LibWeb/Text/expected/localStorage.txt
Normal file
6
Tests/LibWeb/Text/expected/localStorage.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
value
|
||||
value
|
||||
other
|
||||
other
|
||||
foo
|
||||
foo
|
17
Tests/LibWeb/Text/input/localStorage.html
Normal file
17
Tests/LibWeb/Text/input/localStorage.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
localStorage["test"] = "value";
|
||||
println(localStorage["test"]);
|
||||
println(localStorage.getItem("test"));
|
||||
|
||||
localStorage.setItem("test", "other");
|
||||
println(localStorage["test"]);
|
||||
println(localStorage.getItem("test"));
|
||||
|
||||
// Ensure indexed properties work
|
||||
localStorage[0] = "foo";
|
||||
println(localStorage[0]);
|
||||
println(localStorage.getItem("0"));
|
||||
});
|
||||
</script>
|
|
@ -23,10 +23,13 @@ Storage::Storage(JS::Realm& realm)
|
|||
: Bindings::PlatformObject(realm)
|
||||
{
|
||||
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
|
||||
.supports_indexed_properties = true,
|
||||
.supports_named_properties = true,
|
||||
.has_indexed_property_setter = true,
|
||||
.has_named_property_setter = true,
|
||||
.has_named_property_deleter = true,
|
||||
.has_legacy_override_built_ins_interface_extended_attribute = true,
|
||||
.indexed_property_setter_has_identifier = true,
|
||||
.named_property_setter_has_identifier = true,
|
||||
.named_property_deleter_has_identifier = true,
|
||||
};
|
||||
|
@ -168,6 +171,13 @@ Vector<FlyString> Storage::supported_property_names() const
|
|||
return names;
|
||||
}
|
||||
|
||||
Optional<JS::Value> Storage::item_value(size_t index) const
|
||||
{
|
||||
// Handle index as a string since that's our key type
|
||||
auto key = String::number(index);
|
||||
return named_item_value(key);
|
||||
}
|
||||
|
||||
JS::Value Storage::named_item_value(FlyString const& name) const
|
||||
{
|
||||
auto value = get_item(name);
|
||||
|
@ -182,6 +192,13 @@ WebIDL::ExceptionOr<Bindings::PlatformObject::DidDeletionFail> Storage::delete_v
|
|||
return DidDeletionFail::NotRelevant;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> Storage::set_value_of_indexed_property(u32 index, JS::Value unconverted_value)
|
||||
{
|
||||
// Handle index as a string since that's our key type
|
||||
auto key = String::number(index);
|
||||
return set_value_of_named_property(key, unconverted_value);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> Storage::set_value_of_named_property(String const& key, JS::Value unconverted_value)
|
||||
{
|
||||
// NOTE: Since PlatformObject does not know the type of value, we must convert it ourselves.
|
||||
|
|
|
@ -38,9 +38,11 @@ private:
|
|||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
// ^PlatformObject
|
||||
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||
virtual JS::Value named_item_value(FlyString const&) const override;
|
||||
virtual WebIDL::ExceptionOr<DidDeletionFail> delete_value(String const&) override;
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual WebIDL::ExceptionOr<void> set_value_of_indexed_property(u32, JS::Value) override;
|
||||
virtual WebIDL::ExceptionOr<void> set_value_of_named_property(String const& key, JS::Value value) override;
|
||||
|
||||
void reorder();
|
||||
|
|
Loading…
Reference in a new issue