LibWeb: Fix infinite loop in Storage::internal_own_property_keys

Since `Storage::item_value` never returns an empty Optional,
and since `PlatformObject::is_supported_property_index` only
returns false when `item_value` returns an empty Optional,
the loop in `PlatformObject::internal_own_property_keys` will
never terminate when executed on a `Storage` instance.

This fix allows youtube.com to load successfully :^)
This commit is contained in:
Jonne Ransijn 2024-10-23 13:25:30 +02:00 committed by Jelle Raaijmakers
parent 3536ba9a88
commit cc0fce3983
Notes: github-actions[bot] 2024-10-25 10:43:24 +00:00
3 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1 @@
PASS (didn't loop forever)

View file

@ -0,0 +1,8 @@
<!DOCTYPE html>
<script src="include.js"></script>
<script>
test(() => {
for (_ in window.localStorage);
println("PASS (didn't loop forever)");
});
</script>

View file

@ -175,7 +175,10 @@ 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);
auto value = get_item(key);
if (!value.has_value())
return {};
return JS::PrimitiveString::create(vm(), value.release_value());
}
JS::Value Storage::named_item_value(FlyString const& name) const