From 1ad9b3ee6e4a2f16c98821c6adfbf34be2aba011 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Mon, 24 Mar 2025 21:23:58 +0100 Subject: [PATCH] LibWeb/IDB: Implement create_a_sorted_name_list --- Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp | 14 ++++++++++++++ Libraries/LibWeb/IndexedDB/Internal/Algorithms.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp index 8b2d08fb963..6708cae50c8 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -621,4 +623,16 @@ bool is_valid_key_path(KeyPath const& path) }); } +// https://w3c.github.io/IndexedDB/#create-a-sorted-name-list +GC::Ref create_a_sorted_name_list(JS::Realm& realm, Vector 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); +} + } diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h index 7bc329ffca6..74e5b3f022f 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -25,5 +26,6 @@ WebIDL::ExceptionOr delete_a_database(JS::Realm&, StorageAPI::StorageKey, S void abort_a_transaction(IDBTransaction&, GC::Ptr); JS::Value convert_a_key_to_a_value(JS::Realm&, GC::Ref); bool is_valid_key_path(KeyPath const&); +GC::Ref create_a_sorted_name_list(JS::Realm&, Vector); }