mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 01:29:17 +00:00
LibWeb/IDB: Implement possibly_update_the_key_generator
This commit is contained in:
parent
dbe0db0cab
commit
1bdf519b60
Notes:
github-actions[bot]
2025-04-23 18:37:27 +00:00
Author: https://github.com/stelar7
Commit: 1bdf519b60
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4317
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/kennethmyhra ✅
2 changed files with 25 additions and 0 deletions
|
@ -1235,4 +1235,28 @@ ErrorOr<u64> generate_a_key(GC::Ref<ObjectStore> store)
|
||||||
return key;
|
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, MAX_KEY_GENERATOR_VALUE);
|
||||||
|
|
||||||
|
// 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>);
|
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);
|
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>);
|
ErrorOr<u64> generate_a_key(GC::Ref<ObjectStore>);
|
||||||
|
void possibly_update_the_key_generator(GC::Ref<ObjectStore>, GC::Ref<Key>);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue