mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibWeb/IDB: Implement possibly_update_the_key_generator
This commit is contained in:
parent
126e5c8833
commit
c2b2994efe
2 changed files with 25 additions and 0 deletions
|
@ -1228,4 +1228,28 @@ ErrorOr<u64> generate_a_key(GC::Ref<ObjectStore> store)
|
|||
return key;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#possibly-update-the-key-generator
|
||||
void possibly_update_the_key_generator(GC::Ref<ObjectStore> store, GC::Ref<Key> key)
|
||||
{
|
||||
// 1. If the type of key is not number, abort these steps.
|
||||
if (key->type() != Key::KeyType::Number)
|
||||
return;
|
||||
|
||||
// 2. Let value be the value of key.
|
||||
auto temp_value = key->value_as_double();
|
||||
|
||||
// 3. Set value to the minimum of value and 2^53 (9007199254740992).
|
||||
temp_value = min(temp_value, 9007199254740992.0);
|
||||
|
||||
// 4. Set value to the largest integer not greater than value.
|
||||
u64 value = floor(temp_value);
|
||||
|
||||
// 5. Let generator be store’s key generator.
|
||||
auto generator = store->key_generator().value();
|
||||
|
||||
// 6. If value is greater than or equal to generator’s current number, then set generator’s current number to value + 1.
|
||||
if (value >= generator.current_number())
|
||||
generator.set(value + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,5 +37,6 @@ void fire_an_error_event(JS::Realm&, GC::Ref<IDBRequest>);
|
|||
void fire_a_success_event(JS::Realm&, GC::Ref<IDBRequest>);
|
||||
GC::Ref<IDBRequest> asynchronously_execute_a_request(JS::Realm&, IDBRequestSource, GC::Ref<GC::Function<WebIDL::ExceptionOr<JS::Value>()>>, GC::Ptr<IDBRequest> = nullptr);
|
||||
ErrorOr<u64> generate_a_key(GC::Ref<ObjectStore>);
|
||||
void possibly_update_the_key_generator(GC::Ref<ObjectStore>, GC::Ref<Key>);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue