mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibWeb: Implement indexed property support for HTML::Storage
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: 4c189166f4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1846
4 changed files with 42 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue