LibWeb: Implement IDBFactory::cmp

This commit is contained in:
stelar7 2024-11-11 10:49:44 +01:00 committed by Andreas Kling
commit 331f26a88b
Notes: github-actions[bot] 2024-11-25 10:54:47 +00:00
14 changed files with 655 additions and 1 deletions

View file

@ -13,6 +13,7 @@
#include <LibWeb/IndexedDB/IDBDatabase.h>
#include <LibWeb/IndexedDB/IDBFactory.h>
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
#include <LibWeb/IndexedDB/Internal/Key.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/StorageAPI/StorageKey.h>
@ -93,4 +94,25 @@ WebIDL::ExceptionOr<GC::Ref<IDBOpenDBRequest>> IDBFactory::open(String const& na
return request;
}
// https://w3c.github.io/IndexedDB/#dom-idbfactory-cmp
WebIDL::ExceptionOr<i8> IDBFactory::cmp(JS::Value first, JS::Value second)
{
// 1. Let a be the result of converting a value to a key with first. Rethrow any exceptions.
auto a = convert_a_value_to_a_key(realm(), first);
// 2. If a is invalid, throw a "DataError" DOMException.
if (a.is_error())
return WebIDL::DataError::create(realm(), "Failed to convert a value to a key"_string);
// 3. Let b be the result of converting a value to a key with second. Rethrow any exceptions.
auto b = convert_a_value_to_a_key(realm(), second);
// 4. If b is invalid, throw a "DataError" DOMException.
if (b.is_error())
return WebIDL::DataError::create(realm(), "Failed to convert a value to a key"_string);
// 5. Return the results of comparing two keys with a and b.
return Key::compare_two_keys(a.release_value(), b.release_value());
}
}