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;
});
}
}