LibWeb/Storage: Return undefined for non-existent key/index access

All tests at now pass: http://wpt.live/webstorage/defineProperty.window.html
This commit is contained in:
Jim Broadbent 2024-10-20 20:40:17 +01:00 committed by Andrew Kaster
parent c10cb8ac8d
commit 7a66316297
Notes: github-actions[bot] 2024-10-23 17:32:41 +00:00
3 changed files with 14 additions and 1 deletions

View file

@ -1,6 +1,10 @@
undefined
null
value
value
other
other
undefined
null
foo
foo

View file

@ -1,6 +1,10 @@
<script src="include.js"></script>
<script>
test(() => {
println(localStorage["test"])
println(localStorage.getItem("test"))
localStorage["test"] = "value";
println(localStorage["test"]);
println(localStorage.getItem("test"));
@ -10,6 +14,9 @@
println(localStorage.getItem("test"));
// Ensure indexed properties work
println(localStorage[0])
println(localStorage.getItem(0))
localStorage[0] = "foo";
println(localStorage[0]);
println(localStorage.getItem("0"));

View file

@ -182,7 +182,9 @@ JS::Value Storage::named_item_value(FlyString const& name) const
{
auto value = get_item(name);
if (!value.has_value())
return JS::js_null();
// AD-HOC: Spec leaves open to a description at: https://html.spec.whatwg.org/multipage/webstorage.html#the-storage-interface
// However correct behavior expected here: https://github.com/whatwg/html/issues/8684
return JS::js_undefined();
return JS::PrimitiveString::create(vm(), value.release_value());
}