LibWeb/IDB: Implement create_a_sorted_name_list

This commit is contained in:
stelar7 2025-03-24 21:23:58 +01:00 committed by Jelle Raaijmakers
parent 3879391fa6
commit 1ad9b3ee6e
Notes: github-actions[bot] 2025-03-27 15:49:03 +00:00
2 changed files with 16 additions and 0 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/QuickSort.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/ArrayBuffer.h>
@ -20,6 +21,7 @@
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
#include <LibWeb/IndexedDB/Internal/ConnectionQueueHandler.h>
#include <LibWeb/IndexedDB/Internal/Database.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/StorageAPI/StorageKey.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/Buffers.h>
@ -621,4 +623,16 @@ bool is_valid_key_path(KeyPath const& path)
});
}
// https://w3c.github.io/IndexedDB/#create-a-sorted-name-list
GC::Ref<HTML::DOMStringList> create_a_sorted_name_list(JS::Realm& realm, Vector<String> names)
{
// 1. Let sorted be names sorted in ascending order with the code unit less than algorithm.
quick_sort(names, [](auto const& a, auto const& b) {
return Infra::code_unit_less_than(a, b);
});
// 2. Return a new DOMStringList associated with sorted.
return HTML::DOMStringList::create(realm, names);
}
}