LibWeb/IDB: Implement is_valid_key_path

This commit is contained in:
stelar7 2025-03-24 19:34:05 +01:00 committed by Jelle Raaijmakers
parent c276c212a0
commit 0979a154fd
Notes: github-actions[bot] 2025-03-27 15:49:58 +00:00
2 changed files with 36 additions and 0 deletions

View file

@ -589,4 +589,36 @@ JS::Value convert_a_key_to_a_value(JS::Realm& realm, GC::Ref<Key> key)
VERIFY_NOT_REACHED();
}
// https://w3c.github.io/IndexedDB/#valid-key-path
bool is_valid_key_path(KeyPath const& path)
{
// A valid key path is one of:
return path.visit(
[](String const& value) -> bool {
// * An empty string.
if (value.is_empty())
return true;
// FIXME: * An identifier, which is a string matching the IdentifierName production from the ECMAScript Language Specification [ECMA-262].
return true;
// FIXME: * A string consisting of two or more identifiers separated by periods (U+002E FULL STOP).
return true;
return false;
},
[](Vector<String> const& values) -> bool {
// * A non-empty list containing only strings conforming to the above requirements.
if (values.is_empty())
return false;
for (auto const& value : values) {
if (!is_valid_key_path(value))
return false;
}
return true;
});
}
}

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/Variant.h>
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/IndexedDB/IDBRequest.h>
#include <LibWeb/IndexedDB/Internal/Key.h>
@ -13,6 +14,8 @@
namespace Web::IndexedDB {
using KeyPath = Variant<String, Vector<String>>;
WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&, StorageAPI::StorageKey, String, Optional<u64>, GC::Ref<IDBRequest>);
bool fire_a_version_change_event(JS::Realm&, FlyString const&, GC::Ref<DOM::EventTarget>, u64, Optional<u64>);
ErrorOr<GC::Ref<Key>> convert_a_value_to_a_key(JS::Realm&, JS::Value, Vector<JS::Value> = {});
@ -21,5 +24,6 @@ GC::Ref<IDBTransaction> upgrade_a_database(JS::Realm&, GC::Ref<IDBDatabase>, u64
WebIDL::ExceptionOr<u64> delete_a_database(JS::Realm&, StorageAPI::StorageKey, String, GC::Ref<IDBRequest>);
void abort_a_transaction(IDBTransaction&, GC::Ptr<WebIDL::DOMException>);
JS::Value convert_a_key_to_a_value(JS::Realm&, GC::Ref<Key>);
bool is_valid_key_path(KeyPath const&);
}